fixed power state change on settings change
parent
c6b0e86bda
commit
af83f1514f
|
|
@ -243,6 +243,14 @@ void IntegrationPluginGenericThings::setupThing(ThingSetupInfo *info)
|
|||
timer->stop();
|
||||
}
|
||||
});
|
||||
} else if (thing->thingClassId() == thermostatThingClassId) {
|
||||
thermostatCheckPowerOutputState(thing); // check the initial values
|
||||
connect(thing, &Thing::settingChanged, thing, [this, thing] (const ParamTypeId ¶mTypeId, const QVariant &value) {
|
||||
Q_UNUSED(value)
|
||||
if (paramTypeId == thermostatSettingsTemperatureDifferenceParamTypeId) {
|
||||
thermostatCheckPowerOutputState(thing);
|
||||
}
|
||||
});
|
||||
}
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
}
|
||||
|
|
@ -627,32 +635,18 @@ void IntegrationPluginGenericThings::executeAction(ThingActionInfo *info)
|
|||
|
||||
Q_ASSERT_X(false, "executeAction", QString("Unhandled actionTypeId: %1").arg(action.actionTypeId().toString()).toUtf8());
|
||||
} else if (thing->thingClassId() == thermostatThingClassId) {
|
||||
if (action.actionTypeId() == temperatureSensorInputActionTypeId) {
|
||||
|
||||
double targetTemperature = thing->stateValue(thermostatTargetTemperatureStateTypeId).toDouble();
|
||||
double actualTemperature = action.param(thermostatTemperatureSensorInputActionTemperatureSensorInputParamTypeId).value().toDouble();
|
||||
thing->setStateValue(temperatureSensorInputStateTypeId, actualTemperature);
|
||||
double temperatureDifference = thing->setting(thermostatSettingsTemperatureDifferenceParamTypeId).toDouble();
|
||||
if (actualTemperature <= (targetTemperature-temperatureDifference)) {
|
||||
thing->setStateValue(thermostatPowerStateTypeId, true);
|
||||
} else if (actualTemperature >= targetTemperature) {
|
||||
thing->setStateValue(thermostatPowerStateTypeId, false);
|
||||
}
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
}
|
||||
if (action.actionTypeId() == thermostatTargetTemperatureActionTypeId) {
|
||||
|
||||
if (action.actionTypeId() == thermostatTemperatureSensorInputActionTypeId) {
|
||||
thing->setStateValue(thermostatTemperatureSensorInputStateTypeId, action.param(thermostatTemperatureSensorInputActionTemperatureSensorInputParamTypeId).value());
|
||||
} else if (action.actionTypeId() == thermostatTargetTemperatureActionTypeId) {
|
||||
thing->setStateValue(thermostatTargetTemperatureStateTypeId, action.param(thermostatTargetTemperatureActionTargetTemperatureParamTypeId).value());
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
}
|
||||
if (action.actionTypeId() == thermostatPowerActionTypeId) {
|
||||
} else if (action.actionTypeId() == thermostatPowerActionTypeId) {
|
||||
thing->setStateValue(thermostatPowerStateTypeId, action.param(thermostatPowerActionPowerParamTypeId).value());
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
} else {
|
||||
Q_ASSERT_X(false, "executeAction", QString("Unhandled actionTypeId: %1").arg(action.actionTypeId().toString()).toUtf8());
|
||||
}
|
||||
Q_ASSERT_X(false, "executeAction", QString("Unhandled actionTypeId: %1").arg(action.actionTypeId().toString()).toUtf8());
|
||||
thermostatCheckPowerOutputState(thing);
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
} else {
|
||||
Q_ASSERT_X(false, "executeAction", QString("Unhandled thingClassId: %1").arg(thing->thingClassId().toString()).toUtf8());
|
||||
}
|
||||
|
|
@ -806,3 +800,18 @@ void IntegrationPluginGenericThings::moveBlindToAngle(Action action, Thing *thin
|
|||
qCDebug(dcGenericThings()) << "Move to angle doesn't support this thingClass";
|
||||
}
|
||||
}
|
||||
|
||||
void IntegrationPluginGenericThings::thermostatCheckPowerOutputState(Thing *thing)
|
||||
{
|
||||
double targetTemperature = thing->stateValue(thermostatTargetTemperatureStateTypeId).toDouble();
|
||||
double actualTemperature = thing->stateValue(thermostatTemperatureSensorInputStateTypeId).toDouble();
|
||||
double temperatureDifference = thing->setting(thermostatSettingsTemperatureDifferenceParamTypeId).toDouble();
|
||||
if (actualTemperature <= (targetTemperature-temperatureDifference)) {
|
||||
thing->setStateValue(thermostatPowerStateTypeId, true);
|
||||
} else if (actualTemperature >= targetTemperature) {
|
||||
thing->setStateValue(thermostatPowerStateTypeId, false);
|
||||
} else {
|
||||
//Keep actual state
|
||||
//Possible improvement add boost action where powerState = true is forced inside the hysteresis
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,6 +70,8 @@ private:
|
|||
void setBlindState(BlindState state, Thing *thing);
|
||||
void moveBlindToPercentage(Action action, Thing *thing);
|
||||
void moveBlindToAngle(Action action, Thing *thing);
|
||||
|
||||
void thermostatCheckPowerOutputState(Thing *thing);
|
||||
};
|
||||
|
||||
#endif // INTEGRATIONPLUGINGENERICTHINGS_H
|
||||
|
|
|
|||
Loading…
Reference in New Issue