From 51c39fe08a20c5085008b05e4c263f757343040e Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sun, 27 Jan 2019 00:59:52 +0100 Subject: [PATCH] Simulation: Make use of thermostat interface --- simulation/devicepluginsimulation.cpp | 37 +++++++++++++++++++++++++- simulation/devicepluginsimulation.json | 34 ++++++++++++++++++++--- 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/simulation/devicepluginsimulation.cpp b/simulation/devicepluginsimulation.cpp index 179cdc97..c8c2822f 100644 --- a/simulation/devicepluginsimulation.cpp +++ b/simulation/devicepluginsimulation.cpp @@ -59,7 +59,8 @@ DeviceManager::DeviceSetupStatus DevicePluginSimulation::setupDevice(Device *dev device->deviceClassId() == extendedAwningDeviceClassId || device->deviceClassId() == extendedBlindDeviceClassId || device->deviceClassId() == rollerShutterDeviceClassId || - device->deviceClassId() == fingerPrintSensorDeviceClassId) { + device->deviceClassId() == fingerPrintSensorDeviceClassId || + device->deviceClassId() == thermostatDeviceClassId) { m_simulationTimers.insert(device, new QTimer(device)); connect(m_simulationTimers[device], &QTimer::timeout, this, &DevicePluginSimulation::simulationTimerTimeout); } @@ -143,6 +144,37 @@ DeviceManager::DeviceError DevicePluginSimulation::executeAction(Device *device, return DeviceManager::DeviceErrorActionTypeNotFound; } + if (device->deviceClassId() == thermostatDeviceClassId) { + if (action.actionTypeId() == thermostatPowerActionTypeId) { + bool power = action.param(thermostatPowerActionPowerParamTypeId).value().toBool(); + if (!power && device->stateValue(thermostatBoostStateTypeId).toBool()) { + device->setStateValue(thermostatBoostStateTypeId, false); + } + qCDebug(dcSimulation()) << "Set power" << power << "for thermostat device" << device->name(); + device->setStateValue(thermostatPowerStateTypeId, power); + return DeviceManager::DeviceErrorNoError; + } + if (action.actionTypeId() == thermostatBoostActionTypeId) { + bool boost = action.param(thermostatBoostActionBoostParamTypeId).value().toBool(); + if (boost && !device->stateValue(thermostatPowerStateTypeId).toBool()) { + device->setStateValue(thermostatPowerStateTypeId, true); + } + qCDebug(dcSimulation()) << "Set boost" << boost << "for thermostat device" << device->name(); + device->setStateValue(thermostatBoostStateTypeId, boost); + m_simulationTimers.value(device)->start(5 * 60 * 1000); + return DeviceManager::DeviceErrorNoError; + } + if (action.actionTypeId() == thermostatTargetTemperatureActionTypeId) { + if (!device->stateValue(thermostatPowerStateTypeId).toBool()) { + device->setStateValue(thermostatPowerStateTypeId, true); + } + double targetTemp = action.param(thermostatTargetTemperatureActionTargetTemperatureParamTypeId).value().toDouble(); + qCDebug(dcSimulation()) << "Set targetTemp" << targetTemp << "for thermostat device" << device->name(); + device->setStateValue(thermostatTargetTemperatureStateTypeId, targetTemp); + return DeviceManager::DeviceErrorNoError; + } + } + if (device->deviceClassId() == evChargerDeviceClassId){ if (action.actionTypeId() == evChargerPowerActionTypeId){ @@ -668,5 +700,8 @@ void DevicePluginSimulation::simulationTimerTimeout() } Event event(evt, device->id(), params); emitEvent(event); + } else if (device->deviceClassId() == thermostatDeviceClassId) { + device->setStateValue(thermostatBoostStateTypeId, false); + t->stop(); } } diff --git a/simulation/devicepluginsimulation.json b/simulation/devicepluginsimulation.json index 343d883e..9c1c823c 100644 --- a/simulation/devicepluginsimulation.json +++ b/simulation/devicepluginsimulation.json @@ -202,7 +202,8 @@ "minValue": 0, "maxValue": 100, "defaultValue": 100, - "writable": true + "writable": true, + "unit": "Percentage" } ] }, @@ -249,18 +250,43 @@ "name": "thermostat", "displayName": "Thermostat", "createMethods": ["user"], - "interfaces": ["temperaturesensor"], + "interfaces": ["heating", "thermostat"], "paramTypes": [ ], "stateTypes": [ { "id": "edc0ccb6-3a78-44b9-8c7d-638142c27e10", - "name": "temperature", + "name": "targetTemperature", "displayName": "Target temperature", "displayNameEvent": "Target temperature changed", + "displayNameAction": "Set target temperature", "type": "double", "unit": "DegreeCelsius", - "defaultValue": 0 + "defaultValue": 5, + "minValue": 5, + "maxValue": 30, + "writable": true + }, + { + "id": "94a7d50c-df3b-4590-a89e-9dae40ad84fa", + "name": "power", + "displayName": "Power", + "displayNameEvent": "Power changed", + "displayNameAction": "Set power", + "type": "bool", + "defaultValue": false, + "writable": true + }, + { + "id": "f892f660-87ff-458a-bfa0-5af08591233e", + "name": "boost", + "displayName": "Boost", + "displayNameEvent": "Boost enabled changed", + "displayNameAction": "Enable/disable boost", + "type": "bool", + "defaultValue": false, + "writable": true } + ] }, {