Merge PR #455: Philips Hue: Add support for on/off light
This commit is contained in:
commit
3fdf31e1b2
@ -16,7 +16,8 @@ This plugin allows to interact with the Hue bridge. Each light bulb, sensor and
|
||||
* Hue Ambient White Bulb
|
||||
* Hue Color Bulb
|
||||
* Hue Smart plug
|
||||
* Any other Bulb that can be connected and controlled by the Hue App.
|
||||
* Any other Bulb that can be connected and controlled by the Hue App
|
||||
* In-wall dimmers/switches that can be connected and controlled by the Hue App.
|
||||
|
||||
## Requirements
|
||||
|
||||
|
||||
@ -422,6 +422,25 @@ 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);
|
||||
|
||||
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 +619,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 +847,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 +901,11 @@ void IntegrationPluginPhilipsHue::executeAction(ThingActionInfo *info)
|
||||
QPair<QNetworkRequest, QByteArray> 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<QNetworkRequest, QByteArray> 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 +1114,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 +1434,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 +1898,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 +1921,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 +1975,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) {
|
||||
|
||||
@ -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",
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user