diff --git a/philipshue/integrationpluginphilipshue.cpp b/philipshue/integrationpluginphilipshue.cpp index 4328fe3e..ff663152 100644 --- a/philipshue/integrationpluginphilipshue.cpp +++ b/philipshue/integrationpluginphilipshue.cpp @@ -422,6 +422,49 @@ void IntegrationPluginPhilipsHue::setupThing(ThingSetupInfo *info) return info->finish(Thing::ThingErrorNoError); } + // Hue on/off light + if (thing->thingClassId() == onOffLightThingClassId) { + qCDebug(dcPhilipsHue) << "Setup Hue white light" << thing->params(); + + HueLight *hueLight = new HueLight(bridge, this); + + /* // Migrate thing parameters after changing param type UUIDs in 0.14. + QMap migrationMap; + migrationMap.insert("095a463b-f59e-46b1-989a-a71f9cbe3e30", onOffLightThingModelIdParamTypeId); + migrationMap.insert("3f3467ef-4483-4eb9-bcae-84e628322f84", onOffLightThingTypeParamTypeId); + migrationMap.insert("1a5129ca-006c-446c-9f2e-79b065de715f", onOffLightThingUuidParamTypeId); + migrationMap.insert("491dc012-ccf2-4d3a-9f18-add98f7374af", onOffLightThingLightIdParamTypeId); + + ParamList migratedParams; + foreach (const Param &oldParam, thing->params()) { + QString oldId = oldParam.paramTypeId().toString(); + oldId.remove(QRegExp("[{}]")); + if (migrationMap.contains(oldId)) { + ParamTypeId newId = migrationMap.value(oldId); + QVariant oldValue = oldParam.value(); + qCDebug(dcPhilipsHue()) << "Migrating hue onoff light param:" << oldId << "->" << newId << ":" << oldValue; + Param newParam(newId, oldValue); + migratedParams << newParam; + } else { + migratedParams << oldParam; + } + } + thing->setParams(migratedParams); + // Migration done */ + + hueLight->setModelId(thing->paramValue(onOffLightThingModelIdParamTypeId).toString()); + hueLight->setType(thing->paramValue(onOffLightThingTypeParamTypeId).toString()); + hueLight->setUuid(thing->paramValue(onOffLightThingUuidParamTypeId).toString()); + hueLight->setId(thing->paramValue(onOffLightThingLightIdParamTypeId).toInt()); + + connect(hueLight, &HueLight::stateChanged, this, &IntegrationPluginPhilipsHue::lightStateChanged); + + m_lights.insert(hueLight, thing); + refreshLight(thing); + + return info->finish(Thing::ThingErrorNoError); + } + // Hue remote if (thing->thingClassId() == remoteThingClassId) { qCDebug(dcPhilipsHue) << "Setup Hue remote" << thing->params() << thing->thingClassId(); @@ -600,6 +643,7 @@ void IntegrationPluginPhilipsHue::thingRemoved(Thing *thing) if (thing->thingClassId() == colorLightThingClassId || thing->thingClassId() == colorTemperatureLightThingClassId || thing->thingClassId() == dimmableLightThingClassId + || thing->thingClassId() == onOffLightThingClassId || thing->thingClassId() == smartPlugThingClassId) { HueLight *light = m_lights.key(thing); m_lights.remove(light); @@ -827,6 +871,7 @@ void IntegrationPluginPhilipsHue::executeAction(ThingActionInfo *info) if (thing->thingClassId() == colorLightThingClassId || thing->thingClassId() == colorTemperatureLightThingClassId || thing->thingClassId() == dimmableLightThingClassId || + thing->thingClassId() == onOffLightThingClassId || thing->thingClassId() == smartPlugThingClassId) { HueLight *light = m_lights.key(thing); @@ -880,6 +925,11 @@ void IntegrationPluginPhilipsHue::executeAction(ThingActionInfo *info) QPair request = light->createFlashRequest(action.param(dimmableLightAlertActionAlertParamTypeId).value().toString()); reply = hardwareManager()->networkManager()->put(request.first, request.second); } + // On/Off light + else if (action.actionTypeId() == onOffLightPowerActionTypeId) { + QPair request = light->createSetPowerRequest(action.param(onOffLightPowerActionPowerParamTypeId).value().toBool()); + reply = hardwareManager()->networkManager()->put(request.first, request.second); + } // Hue smart plug else if (action.actionTypeId() == smartPlugPowerActionTypeId) { @@ -1088,6 +1138,9 @@ void IntegrationPluginPhilipsHue::lightStateChanged() thing->setStateValue(dimmableLightConnectedStateTypeId, light->reachable()); thing->setStateValue(dimmableLightPowerStateTypeId, light->power()); thing->setStateValue(dimmableLightBrightnessStateTypeId, brightnessToPercentage(light->brightness())); + } else if (thing->thingClassId() == onOffLightThingClassId) { + thing->setStateValue(onOffLightConnectedStateTypeId, light->reachable()); + thing->setStateValue(onOffLightPowerStateTypeId, light->power()); } else if (thing->thingClassId() == smartPlugThingClassId) { thing->setStateValue(smartPlugConnectedStateTypeId, light->reachable()); thing->setStateValue(smartPlugPowerStateTypeId, light->power()); @@ -1405,6 +1458,17 @@ void IntegrationPluginPhilipsHue::processBridgeLightDiscoveryResponse(Thing *thi descriptors.append(descriptor); qCDebug(dcPhilipsHue) << "Found new dimmable light" << lightMap.value("name").toString() << model; + } else if (type == "On/Off light") { + ThingDescriptor descriptor(onOffLightThingClassId, lightMap.value("name").toString(), "Philips Hue On/Off Light", thing->id()); + ParamList params; + params.append(Param(onOffLightThingModelIdParamTypeId, model)); + params.append(Param(onOffLightThingTypeParamTypeId, lightMap.value("type").toString())); + params.append(Param(onOffLightThingUuidParamTypeId, uuid)); + params.append(Param(onOffLightThingLightIdParamTypeId, lightId)); + descriptor.setParams(params); + descriptors.append(descriptor); + + qCDebug(dcPhilipsHue) << "Found new on/off light" << lightMap.value("name").toString() << model; } else if (type == "Color temperature light") { ThingDescriptor descriptor(colorTemperatureLightThingClassId, lightMap.value("name").toString(), "Philips Hue Color Temperature Light", thing->id()); ParamList params; @@ -1858,7 +1922,7 @@ void IntegrationPluginPhilipsHue::processSetNameResponse(Thing *thing, const QBy return; } - if (thing->thingClassId() == colorLightThingClassId || thing->thingClassId() == dimmableLightThingClassId) + if (thing->thingClassId() == colorLightThingClassId || thing->thingClassId() == dimmableLightThingClassId || thing->thingClassId() == onOffLightThingClassId) refreshLight(thing); } @@ -1881,6 +1945,8 @@ void IntegrationPluginPhilipsHue::bridgeReachableChanged(Thing *thing, bool reac m_lights.value(light)->setStateValue(colorTemperatureLightConnectedStateTypeId, false); } else if (m_lights.value(light)->thingClassId() == dimmableLightThingClassId) { m_lights.value(light)->setStateValue(dimmableLightConnectedStateTypeId, false); + } else if (m_lights.value(light)->thingClassId() == onOffLightThingClassId) { + m_lights.value(light)->setStateValue(onOffLightConnectedStateTypeId, false); } else if (m_lights.value(light)->thingClassId() == smartPlugThingClassId) { m_lights.value(light)->setStateValue(smartPlugConnectedStateTypeId, false); } @@ -1933,6 +1999,10 @@ bool IntegrationPluginPhilipsHue::lightAlreadyAdded(const QString &uuid) if (thing->paramValue(dimmableLightThingUuidParamTypeId).toString() == uuid) { return true; } + } else if (thing->thingClassId() == onOffLightThingClassId) { + if (thing->paramValue(onOffLightThingUuidParamTypeId).toString() == uuid) { + return true; + } } if (thing->thingClassId() == colorTemperatureLightThingClassId) { if (thing->paramValue(colorTemperatureLightThingUuidParamTypeId).toString() == uuid) { diff --git a/philipshue/integrationpluginphilipshue.json b/philipshue/integrationpluginphilipshue.json index 6e97a370..53323d2c 100644 --- a/philipshue/integrationpluginphilipshue.json +++ b/philipshue/integrationpluginphilipshue.json @@ -420,6 +420,64 @@ } ] }, + { + "id": "f720f31d-9523-4a74-9f10-19cbc9edeb58", + "name": "onOffLight", + "displayName": "Hue On/Off light", + "interfaces": ["light", "wirelessconnectable"], + "createMethods": ["auto"], + "paramTypes": [ + { + "id": "2e4274e8-c810-4b1b-8b27-86239e0e8a12", + "name": "modelId", + "displayName": "model id", + "type" : "QString", + "readOnly": true + }, + { + "id": "3b4b377a-de33-4b1f-a65f-c4915a797cde", + "name": "type", + "displayName": "type", + "type" : "QString", + "readOnly": true + }, + { + "id": "c5b62efe-b18d-4e10-b8f3-8cbe5938cce5", + "name": "uuid", + "displayName": "uuid", + "type" : "QString", + "readOnly": true + }, + { + "id": "dfd0ed05-26b1-4906-b1a1-384d2340c236", + "name": "lightId", + "displayName": "light id", + "type" : "int", + "readOnly": true + } + ], + "stateTypes": [ + { + "id": "111a5a4a-63d4-4d1d-ac72-b5b5a29fd0aa", + "name": "connected", + "displayName": "reachable", + "displayNameEvent": "reachable changed", + "defaultValue": false, + "type": "bool", + "cached": false + }, + { + "id": "5dc5e71b-789e-4c68-abb6-1534c8af019e", + "name": "power", + "displayName": "power", + "displayNameEvent": "power changed", + "displayNameAction": "Set power", + "type": "bool", + "defaultValue": false, + "writable": true + } + ] + }, { "id": "bb482d39-67ef-46dc-88e9-7b181d642b28", "name": "remote",