Merge PR #371: Simulation: Add a simulated water sensor

master
Jenkins nymea 2021-02-26 10:27:48 +01:00
commit 32c5edaa0d
3 changed files with 41 additions and 6 deletions

View File

@ -71,7 +71,8 @@ void IntegrationPluginSimulation::setupThing(ThingSetupInfo *info)
thing->thingClassId() == rollerShutterThingClassId ||
thing->thingClassId() == fingerPrintSensorThingClassId ||
thing->thingClassId() == barcodeScannerThingClassId ||
thing->thingClassId() == contactSensorThingClassId) {
thing->thingClassId() == contactSensorThingClassId ||
thing->thingClassId() == waterSensorThingClassId) {
m_simulationTimers.insert(thing, new QTimer(thing));
connect(m_simulationTimers[thing], &QTimer::timeout, this, &IntegrationPluginSimulation::simulationTimerTimeout);
}
@ -127,6 +128,9 @@ void IntegrationPluginSimulation::setupThing(ThingSetupInfo *info)
if (thing->thingClassId() == contactSensorThingClassId) {
m_simulationTimers.value(thing)->start(10000);
}
if (thing->thingClassId() == waterSensorThingClassId) {
m_simulationTimers.value(thing)->start(10000);
}
info->finish(Thing::ThingErrorNoError);
}
@ -628,10 +632,12 @@ void IntegrationPluginSimulation::onPluginTimer20Seconds()
thing->setStateValue(temperatureSensorConnectedStateTypeId, true);
} else if (thing->thingClassId() == motionDetectorThingClassId) {
// Motion detector
thing->setStateValue(motionDetectorActiveStateTypeId, generateRandomBoolValue());
thing->setStateValue(motionDetectorIsPresentStateTypeId, generateRandomBoolValue());
thing->setStateValue(motionDetectorBatteryLevelStateTypeId, generateBatteryValue(13, 1));
thing->setStateValue(motionDetectorBatteryCriticalStateTypeId, thing->stateValue(motionDetectorBatteryLevelStateTypeId).toInt() <= 30);
thing->setStateValue(motionDetectorConnectedStateTypeId, true);
} else if (thing->thingClassId() == waterSensorThingClassId) {
thing->setStateValue(waterSensorWaterDetectedStateTypeId, generateRandomBoolValue());
} else if (thing->thingClassId() == gardenSensorThingClassId) {
// Garden sensor
thing->setStateValue(gardenSensorTemperatureStateTypeId, generateSinValue(-4, 17, 5));
@ -787,5 +793,8 @@ void IntegrationPluginSimulation::simulationTimerTimeout()
} else {
thing->setStateValue(contactSensorBatteryCriticalStateTypeId, false);
}
} else if (thing->thingClassId() == waterSensorThingClassId) {
bool wet = qrand() > (RAND_MAX / 2);
thing->setStateValue(waterSensorWaterDetectedStateTypeId, wet);
}
}

View File

@ -115,12 +115,12 @@
"name": "motionDetector",
"displayName": "Motion Detector",
"createMethods": ["user"],
"interfaces": ["battery", "connectable"],
"interfaces": ["presencesensor", "battery", "connectable"],
"paramTypes": [ ],
"stateTypes": [
{
"id": "5ab00bfc-7345-44a2-90d4-852c810e59ec",
"name": "active",
"name": "isPresent",
"displayName": "Active",
"displayNameEvent": "Motion detected",
"type": "bool",
@ -153,6 +153,15 @@
"displayNameEvent": "Connected changed",
"type": "bool",
"defaultValue": true
},
{
"id": "17874952-a1ab-467f-9786-29ffe3196a8c",
"name": "lastSeenTime",
"displayName": "Last seen",
"displayNameEvent": "Last seen changed",
"type": "int",
"unit": "UnixTime",
"defaultValue": 0
}
]
},
@ -1026,7 +1035,7 @@
"name": "waterValve",
"displayName": "Water valve",
"createMethods": ["user"],
"paramTypes": [ ],
"interfaces": ["irrigation"],
"stateTypes": [
{
"id": "194f05a9-2c54-466c-a2a9-3d278fb41a2a",
@ -1108,6 +1117,23 @@
"defaultValue": false
}
]
},
{
"id": "088aa0cb-61e8-46b6-b99d-699a29fd79c7",
"name": "waterSensor",
"displayName": "Water sensor",
"createMethods": ["user"],
"interfaces": ["watersensor"],
"stateTypes": [
{
"id": "764cbbbf-6a5c-4265-9424-fc9e6dd86fda",
"name": "waterDetected",
"displayName": "Wet",
"displayNameEvent": "Water detected",
"type": "bool",
"defaultValue": false
}
]
}
]
}

View File

@ -513,7 +513,7 @@
"id": "e8e18bbe-27bb-4fd7-98fc-f5cef3b5f213",
"setupMethod": "JustAdd",
"createMethods": [ "Auto" ],
"interfaces": [ "sensor", "battery", "wirelessconnectable" ],
"interfaces": [ "watersensor", "battery", "wirelessconnectable" ],
"paramTypes": [
{
"id": "e12453e7-5fc3-4549-b4fc-8b85f78607c6",