This commit is contained in:
2015-05-19 03:42:02 +02:00
parent 7156280bae
commit 3ff42cb533
30 changed files with 965 additions and 123 deletions
@@ -262,7 +262,7 @@ void DeviceStatusMsgCondition::notificationReceived(interface::Observer<devicere
if (msgPointer.empty()) {
value = e2->statusMsg;
} else if (e2->statusMsg.HasPath(msgPointer)) {
value = e2->statusMsg.Get(msgPointer);
value = e2->statusMsg.GetPath(msgPointer);
} else {
notify = false;
}
@@ -321,7 +321,7 @@ void DeviceCommandMsgCondition::notificationReceived(interface::Observer<devicer
if (msgPointer.empty()) {
value = e2->cmdMsg;
} else if (e2->cmdMsg.HasPath(msgPointer)) {
value = e2->cmdMsg.Get(msgPointer);
value = e2->cmdMsg.GetPath(msgPointer);
} else {
notify = false;
}
@@ -362,7 +362,15 @@ std::shared_ptr<rule::RuleCondition> DeviceStateChangeConditionFactory::createCo
throw std::runtime_error("Malformed JSON: property msgpointer is not an string.");
}
}
retval = std::make_shared<DeviceStateChangeCondition>(parent, deviceID, statePointer);
Variant fromValue;
if (raw.HasPath("fromvalue")) {
fromValue = raw["fromvalue"];
}
Variant toValue;
if (raw.HasPath("tovalue")) {
toValue = raw["tovalue"];
}
retval = std::make_shared<DeviceStateChangeCondition>(parent, deviceID, statePointer, fromValue, toValue);
return retval;
}
@@ -378,13 +386,19 @@ void DeviceStateChangeCondition::notificationReceived(interface::Observer<device
current = device->getCurrentState();
last = device->getLastState();
} else if (device->getCurrentState().HasPath(msgPointer) && device->getLastState().HasPath(msgPointer)) {
current = device->getCurrentState().Get(msgPointer);
last = device->getLastState().Get(msgPointer);
current = device->getCurrentState().GetPath(msgPointer);
last = device->getLastState().GetPath(msgPointer);
} else {
notify = false;
}
if (notify && current == last) {
notify = false;
if (notify) {
if (current == last) {
notify = false;
} else if (!fromValue.IsNull() && fromValue != last) {
notify = false;
} else if (!msgValue.IsNull() && msgValue != current) {
notify = false;
}
}
if (notify) {
Variant lcontext;
@@ -115,9 +115,11 @@ public:
class DeviceStateChangeCondition : public DeviceMsgCondition {
protected:
const Variant fromValue;
public:
DeviceStateChangeCondition(Rule* parent, const std::string deviceID, const std::string statePointer) :
DeviceMsgCondition(parent, Category::Event, "devicestatechange", deviceID, statePointer, Variant()) {}
DeviceStateChangeCondition(Rule* parent, const std::string deviceID, const std::string statePointer, const Variant fromValue, const Variant toValue) :
DeviceMsgCondition(parent, Category::Event, "devicestatechange", deviceID, statePointer, toValue), fromValue(fromValue) {}
virtual void notificationReceived(interface::Observer<devicerepository::DeviceEvent>::observable_type* o, const devicerepository::DeviceEvent* e) override;
};
+37 -23
View File
@@ -9,31 +9,19 @@
"conditions" : [
{
"type": "devicestatusmsg",
"deviceid": "huelight3"
},
{
"type": "devicestatechange",
"deviceid": "huelight4"
"deviceid": "dummySwitch0",
"msgpointer": "/switch/value",
"msgvalue": true
}
]
},
"script": { "code": "global var2\nprint \"Hello World1: \" + str(var2)\nvar2 = var2 + 1\nimport __main__\nprint \"__main__.__dict__: \" + str(__main__.__dict__)\nprint \"test: \" + event_type\ndev1 = Devices.getDevice(\"huelight1\")\nprint \"device: \" + dev1.deviceID()" },
"script": { "code": "global var2\nprint \"Hello World1: \" + str(var2)\nvar2 = var2 + 1\nimport __main__\nprint \"__main__.__dict__: \" + str(__main__.__dict__)\nprint \"event_type: \" + event_type\nprint \"devices: \" + str(Devices.keys())\nprint \"DeviceCount: \" + str(len(Devices))\nprint \"test: \" + str(Devices[\"dummySwitch1\"])" },
"exitscript": { "code": "print \"Hello from exitscript1\"" }
},
"rule02": {
"condition": {
"type": "logical_or",
"$schema": "hos:schema://core/configs/rulepackage#/definitions/LogicalOrCondition",
"conditions" : [
{
"type": "devicecommandmsg",
"deviceid": "huelight4"
},
{
"type": "devicestatechange",
"deviceid": "huelight3"
}
]
"type": "devicestatechange",
"deviceid": "dummySwitch0"
},
"script": { "code": "print \"Hello World2: \" + str(var2)\nvar2 = var2 + 1\nimport __main__\nprint \"__main__.__dict__: \" + str(__main__.__dict__)\nprint \"test: \" + event_type" },
"exitscript": { "code": "print \"Hello from exitscript2\"" }
@@ -45,16 +33,42 @@
"conditions" : [
{
"type": "devicecommandmsg",
"deviceid": "huelight1"
},
{
"type": "devicestatechange",
"deviceid": "huelight2"
"deviceid": "dummySwitch0"
}
]
},
"script": { "code": "print \"Hello World3: \" + str(var2)\nvar2 = var2 + 1\nimport __main__\nprint \"__main__.__dict__: \" + str(__main__.__dict__)\nprint \"test: \" + event_type" },
"exitscript": { "code": "print \"Hello from exitscript2\"" }
},
"rule04": {
"condition": {
"type": "logical_or",
"$schema": "hos:schema://core/configs/rulepackage#/definitions/LogicalOrCondition",
"conditions" : [
{
"type": "devicestatechange",
"deviceid": "dummyDimmer0",
"msgpointer": "/dimmer/value",
"tovalue": 1.0
}
]
},
"script": { "code": "print \"Dimmer 0 reached 100\"" }
},
"rule05": {
"condition": {
"type": "logical_or",
"$schema": "hos:schema://core/configs/rulepackage#/definitions/LogicalOrCondition",
"conditions" : [
{
"type": "devicestatechange",
"deviceid": "dummyDimmer0",
"msgpointer": "/dimmer",
"fromvalue": { "value": 1.0 }
}
]
},
"script": { "code": "print \"Dimmer 0 left 100\"" }
}
}
}