Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added actionOpenClosed for contactSensors (simulated) #154

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
9 changes: 6 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,12 @@ function handleSubscribeEvent (req, res) {
subscriptions = [];
Object.keys(req.body.devices).forEach(function (property) {
req.body.devices[property].forEach(function (device) {
subscriptions.push(getTopicFor(device, property, TOPIC_COMMAND));
subscriptions.push(getTopicFor(device, property, TOPIC_WRITE_STATE));
var cmdTopic = getTopicFor(device, property, TOPIC_COMMAND);
var writeTopic = getTopicFor(device, property, TOPIC_WRITE_STATE);
subscriptions.push(cmdTopic);
if (writeTopic !== cmdTopic) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch!

subscriptions.push(writeTopic);
}
});
});

Expand Down Expand Up @@ -258,7 +262,6 @@ function parseMQTTMessage (topic, message) {
device = pieces[0],
property = pieces[1],
topicReadState = getTopicFor(device, property, TOPIC_READ_STATE),
topicWriteState = getTopicFor(device, property, TOPIC_WRITE_STATE),
topicSwitchState = getTopicFor(device, 'switch', TOPIC_READ_STATE),
topicLevelCommand = getTopicFor(device, 'level', TOPIC_COMMAND);

Expand Down
15 changes: 11 additions & 4 deletions smartapps/stj/mqtt-bridge.src/mqtt-bridge.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ import groovy.transform.Field
capability: "capability.contactSensor",
attributes: [
"contact"
]
],
action: "actionOpenClosed"
],
"doorControl": [
name: "Door Control",
Expand Down Expand Up @@ -611,11 +612,17 @@ def actionColor(device, attribute, value) {
}
}

//Action for contactSensors,doorControl,garageDoors,valve and windowShades.
//contactSensors don't have action but a simulated contact sensor can hence the hasCommand() check.
def actionOpenClosed(device, attribute, value) {
if (value == "open") {
device.open()
if (device.hasCommand("open")) {
iprak marked this conversation as resolved.
Show resolved Hide resolved
device.open()
}
} else if (value == "closed") {
device.close()
if (device.hasCommand("close")) {
device.close()
}
}
}

Expand Down Expand Up @@ -721,4 +728,4 @@ def actionTimedSession(device, attribute, value) {
if (attribute == "timeRemaining") {
device.setTimeRemaining(value)
}
}
}
iprak marked this conversation as resolved.
Show resolved Hide resolved