Update generic lights and add post setup reading for inital values and improve debugging

This commit is contained in:
Simon Stürz 2020-12-02 12:03:06 +01:00
parent 762a32b57a
commit 34b5352c20
6 changed files with 139 additions and 92 deletions

View File

@ -445,9 +445,42 @@ void IntegrationPluginZigbeeGenericLights::setupThing(ThingSetupInfo *info)
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
} }
void IntegrationPluginZigbeeGenericLights::postSetupThing(Thing *thing)
{
if (thing->thingClassId() == onOffLightThingClassId) {
ZigbeeNode *node = m_thingNodes.value(thing);
if (node && node->reachable()) {
readLightPowerState(thing);
}
} else if (thing->thingClassId() == dimmableLightThingClassId) {
ZigbeeNode *node = m_thingNodes.value(thing);
if (node && node->reachable()) {
readLightPowerState(thing);
readLightLevelState(thing);
}
} else if (thing->thingClassId() == colorTemperatureLightThingClassId) {
ZigbeeNode *node = m_thingNodes.value(thing);
if (node && node->reachable()) {
readColorTemperatureRange(thing);
readLightPowerState(thing);
readLightLevelState(thing);
readLightColorTemperatureState(thing);
}
} else if (thing->thingClassId() == colorLightThingClassId) {
ZigbeeNode *node = m_thingNodes.value(thing);
if (node && node->reachable()) {
readColorCapabilities(thing);
readLightPowerState(thing);
readLightLevelState(thing);
readLightColorXYState(thing);
}
}
}
void IntegrationPluginZigbeeGenericLights::executeAction(ThingActionInfo *info) void IntegrationPluginZigbeeGenericLights::executeAction(ThingActionInfo *info)
{ {
if (!hardwareManager()->zigbeeResource()->available()) { if (!hardwareManager()->zigbeeResource()->available()) {
qCDebug(dcZigbeeGenericLights()) << "Failed to execute action" << info->thing() << info->action().actionTypeId().toString() << "because the hardware is not available.";
info->finish(Thing::ThingErrorHardwareNotAvailable); info->finish(Thing::ThingErrorHardwareNotAvailable);
return; return;
} }
@ -456,6 +489,7 @@ void IntegrationPluginZigbeeGenericLights::executeAction(ThingActionInfo *info)
Thing *thing = info->thing(); Thing *thing = info->thing();
ZigbeeNode *node = m_thingNodes.value(thing); ZigbeeNode *node = m_thingNodes.value(thing);
if (!node->reachable()) { if (!node->reachable()) {
qCDebug(dcZigbeeGenericLights()) << "Failed to execute action" << info->thing() << info->action().actionTypeId().toString() << "because node seems not to be reachable.";
info->finish(Thing::ThingErrorHardwareNotAvailable); info->finish(Thing::ThingErrorHardwareNotAvailable);
return; return;
} }
@ -463,6 +497,7 @@ void IntegrationPluginZigbeeGenericLights::executeAction(ThingActionInfo *info)
// Get the endpoint // Get the endpoint
ZigbeeNodeEndpoint *endpoint = findEndpoint(thing); ZigbeeNodeEndpoint *endpoint = findEndpoint(thing);
if (!endpoint) { if (!endpoint) {
qCDebug(dcZigbeeGenericLights()) << "Failed to execute action" << info->thing() << info->action().actionTypeId().toString() << "because node endpoint could not be found.";
info->finish(Thing::ThingErrorHardwareNotAvailable); info->finish(Thing::ThingErrorHardwareNotAvailable);
return; return;
} }

View File

@ -50,6 +50,7 @@ public:
void init() override; void init() override;
void setupThing(ThingSetupInfo *info) override; void setupThing(ThingSetupInfo *info) override;
void postSetupThing(Thing *thing) override;
void executeAction(ThingActionInfo *info) override; void executeAction(ThingActionInfo *info) override;
void thingRemoved(Thing *thing) override; void thingRemoved(Thing *thing) override;

View File

@ -188,7 +188,7 @@ void IntegrationPluginZigbeeLumi::setupThing(ThingSetupInfo *info)
// Get the endpoint of interest (0x01) for this device // Get the endpoint of interest (0x01) for this device
ZigbeeNodeEndpoint *endpoint = node->getEndpoint(0x01); ZigbeeNodeEndpoint *endpoint = node->getEndpoint(0x01);
if (!endpoint) { if (!endpoint) {
qCWarning(dcZigbeeLumi()) << "Zigbee endpoint 1 not found on" << thing->name(); qCWarning(dcZigbeeLumi()) << "Zigbee endpoint 1 not found on" << thing;
info->finish(Thing::ThingErrorSetupFailed); info->finish(Thing::ThingErrorSetupFailed);
return; return;
} }

View File

@ -388,7 +388,7 @@ void IntegrationPluginZigbeePhilipsHue::initDimmerSwitch(ZigbeeNode *node)
} }
qCDebug(dcZigbeePhilipsHue()) << "Bind on/off cluster to coordinator"; qCDebug(dcZigbeePhilipsHue()) << "Bind on/off cluster to coordinator";
ZigbeeDeviceObjectReply * zdoReply = node->deviceObject()->requestBindShortAddress(endpointZll->endpointId(), ZigbeeClusterLibrary::ClusterIdOnOff, 0x0000); ZigbeeDeviceObjectReply * zdoReply = node->deviceObject()->requestBindGroupAddress(endpointZll->endpointId(), ZigbeeClusterLibrary::ClusterIdOnOff, 0x0000);
connect(zdoReply, &ZigbeeDeviceObjectReply::finished, node, [=](){ connect(zdoReply, &ZigbeeDeviceObjectReply::finished, node, [=](){
if (zdoReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) { if (zdoReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) {
qCWarning(dcZigbeePhilipsHue()) << "Failed to bind on/off cluster to coordinator" << zdoReply->error(); qCWarning(dcZigbeePhilipsHue()) << "Failed to bind on/off cluster to coordinator" << zdoReply->error();
@ -397,7 +397,7 @@ void IntegrationPluginZigbeePhilipsHue::initDimmerSwitch(ZigbeeNode *node)
} }
qCDebug(dcZigbeePhilipsHue()) << "Bind power level cluster to coordinator"; qCDebug(dcZigbeePhilipsHue()) << "Bind power level cluster to coordinator";
ZigbeeDeviceObjectReply * zdoReply = node->deviceObject()->requestBindShortAddress(endpointZll->endpointId(), ZigbeeClusterLibrary::ClusterIdLevelControl, 0x0000); ZigbeeDeviceObjectReply * zdoReply = node->deviceObject()->requestBindGroupAddress(endpointZll->endpointId(), ZigbeeClusterLibrary::ClusterIdLevelControl, 0x0000);
connect(zdoReply, &ZigbeeDeviceObjectReply::finished, node, [=](){ connect(zdoReply, &ZigbeeDeviceObjectReply::finished, node, [=](){
if (zdoReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) { if (zdoReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) {
qCWarning(dcZigbeePhilipsHue()) << "Failed to bind level cluster to coordinator" << zdoReply->error(); qCWarning(dcZigbeePhilipsHue()) << "Failed to bind level cluster to coordinator" << zdoReply->error();

View File

@ -238,7 +238,7 @@
}, },
{ {
"name": "soundRemote", "name": "soundRemote",
"displayName": "TRÅDFRI Symfonsik", "displayName": "TRÅDFRI Symfonisk",
"id": "a18e398d-c14b-4bcd-8e6d-b64737436814", "id": "a18e398d-c14b-4bcd-8e6d-b64737436814",
"setupMethod": "JustAdd", "setupMethod": "JustAdd",
"createMethods": [ "Auto" ], "createMethods": [ "Auto" ],

View File

@ -110,7 +110,7 @@ bool IntegrationPluginZigbeeTradfri::handleNode(ZigbeeNode *node, const QUuid &n
if (endpoint->profile() == Zigbee::ZigbeeProfileHomeAutomation && endpoint->deviceId() == Zigbee::HomeAutomationDeviceRemoteControl) { if (endpoint->profile() == Zigbee::ZigbeeProfileHomeAutomation && endpoint->deviceId() == Zigbee::HomeAutomationDeviceRemoteControl) {
qCDebug(dcZigbeeTradfri()) << "Handeling TRADFRI Symfonsik sound remote" << node << endpoint; qCDebug(dcZigbeeTradfri()) << "Handeling TRADFRI Symfonsik sound remote" << node << endpoint;
createThing(soundRemoteThingClassId, networkUuid, node, endpoint); createThing(soundRemoteThingClassId, networkUuid, node, endpoint);
initRemote(node, endpoint); initOnOffSwitch(node, endpoint);
handled = true; handled = true;
} }
@ -359,18 +359,18 @@ void IntegrationPluginZigbeeTradfri::setupThing(ThingSetupInfo *info)
} else { } else {
connect(levelCluster, &ZigbeeClusterLevelControl::commandSent, thing, [=](ZigbeeClusterLevelControl::Command command, const QByteArray &payload){ connect(levelCluster, &ZigbeeClusterLevelControl::commandSent, thing, [=](ZigbeeClusterLevelControl::Command command, const QByteArray &payload){
qCDebug(dcZigbeeTradfri()) << thing << "level cluster command sent" << command << payload.toHex(); qCDebug(dcZigbeeTradfri()) << thing << "level cluster command sent" << command << payload.toHex();
// switch (command) { // switch (command) {
// case ZigbeeClusterLevelControl::CommandMoveWithOnOff: // case ZigbeeClusterLevelControl::CommandMoveWithOnOff:
// qCDebug(dcZigbeeTradfri()) << thing << "long pressed ON"; // qCDebug(dcZigbeeTradfri()) << thing << "long pressed ON";
// emit emitEvent(Event(onOffSwitchLongPressedEventTypeId, thing->id(), ParamList() << Param(onOffSwitchLongPressedEventButtonNameParamTypeId, "ON"))); // emit emitEvent(Event(onOffSwitchLongPressedEventTypeId, thing->id(), ParamList() << Param(onOffSwitchLongPressedEventButtonNameParamTypeId, "ON")));
// break; // break;
// case ZigbeeClusterLevelControl::CommandMove: // case ZigbeeClusterLevelControl::CommandMove:
// qCDebug(dcZigbeeTradfri()) << thing << "long pressed OFF"; // qCDebug(dcZigbeeTradfri()) << thing << "long pressed OFF";
// emit emitEvent(Event(onOffSwitchLongPressedEventTypeId, thing->id(), ParamList() << Param(onOffSwitchLongPressedEventButtonNameParamTypeId, "OFF"))); // emit emitEvent(Event(onOffSwitchLongPressedEventTypeId, thing->id(), ParamList() << Param(onOffSwitchLongPressedEventButtonNameParamTypeId, "OFF")));
// break; // break;
// default: // default:
// break; // break;
// } // }
}); });
} }
} }
@ -475,8 +475,8 @@ void IntegrationPluginZigbeeTradfri::initOnOffSwitch(ZigbeeNode *node, ZigbeeNod
} }
qCDebug(dcZigbeeTradfri()) << "Bind power configuration cluster to coordinator"; qCDebug(dcZigbeeTradfri()) << "Bind on/off configuration cluster to coordinator";
ZigbeeDeviceObjectReply * zdoReply = node->deviceObject()->requestBindShortAddress(endpoint->endpointId(), ZigbeeClusterLibrary::ClusterIdOnOff, 0x0000); ZigbeeDeviceObjectReply * zdoReply = node->deviceObject()->requestBindGroupAddress(endpoint->endpointId(), ZigbeeClusterLibrary::ClusterIdOnOff, 0x0000);
connect(zdoReply, &ZigbeeDeviceObjectReply::finished, node, [=](){ connect(zdoReply, &ZigbeeDeviceObjectReply::finished, node, [=](){
if (zdoReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) { if (zdoReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) {
qCWarning(dcZigbeeTradfri()) << "Failed to bind on/off cluster to coordinator" << zdoReply->error(); qCWarning(dcZigbeeTradfri()) << "Failed to bind on/off cluster to coordinator" << zdoReply->error();
@ -485,7 +485,7 @@ void IntegrationPluginZigbeeTradfri::initOnOffSwitch(ZigbeeNode *node, ZigbeeNod
} }
qCDebug(dcZigbeeTradfri()) << "Bind power level cluster to coordinator"; qCDebug(dcZigbeeTradfri()) << "Bind power level cluster to coordinator";
ZigbeeDeviceObjectReply * zdoReply = node->deviceObject()->requestBindShortAddress(endpoint->endpointId(), ZigbeeClusterLibrary::ClusterIdLevelControl, 0x0000); ZigbeeDeviceObjectReply * zdoReply = node->deviceObject()->requestBindGroupAddress(endpoint->endpointId(), ZigbeeClusterLibrary::ClusterIdLevelControl, 0x0000);
connect(zdoReply, &ZigbeeDeviceObjectReply::finished, node, [=](){ connect(zdoReply, &ZigbeeDeviceObjectReply::finished, node, [=](){
if (zdoReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) { if (zdoReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) {
qCWarning(dcZigbeeTradfri()) << "Failed to bind level cluster to coordinator" << zdoReply->error(); qCWarning(dcZigbeeTradfri()) << "Failed to bind level cluster to coordinator" << zdoReply->error();
@ -515,12 +515,22 @@ void IntegrationPluginZigbeeTradfri::initOnOffSwitch(ZigbeeNode *node, ZigbeeNod
void IntegrationPluginZigbeeTradfri::initRemote(ZigbeeNode *node, ZigbeeNodeEndpoint *endpoint) void IntegrationPluginZigbeeTradfri::initRemote(ZigbeeNode *node, ZigbeeNodeEndpoint *endpoint)
{ {
// Get the current configured bindings for this node // Get the current configured bindings for this node
ZigbeeReply *reply = node->removeAllBindings(); // ZigbeeReply *reply = node->removeAllBindings();
connect(reply, &ZigbeeReply::finished, node, [=](){ // connect(reply, &ZigbeeReply::finished, node, [=](){
if (reply->error() != ZigbeeReply::ErrorNoError) { // if (reply->error() != ZigbeeReply::ErrorNoError) {
qCWarning(dcZigbeeTradfri()) << "Failed to remove all bindings for initialization of" << node; // qCWarning(dcZigbeeTradfri()) << "Failed to remove all bindings for initialization of" << node;
// } else {
// qCDebug(dcZigbeeTradfri()) << "Removed all bindings successfully from" << node;
// }
// Bind basic cluster
ZigbeeDeviceObjectReply *bindRegisterReply = node->deviceObject()->requestBindGroupAddress(endpoint->endpointId(), ZigbeeClusterLibrary::ClusterIdBasic, 0x0000);
connect(bindRegisterReply, &ZigbeeDeviceObjectReply::finished, node, [=](){
if (bindRegisterReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) {
qCWarning(dcZigbeeTradfri()) << "Failed to bind basic cluster" << bindRegisterReply->error();
} else { } else {
qCDebug(dcZigbeeTradfri()) << "Removed all bindings successfully from" << node; qCDebug(dcZigbeeTradfri()) << "Bind basic cluster request finished successfully";
} }
// Read battery, bind and configure attribute reporting for battery // Read battery, bind and configure attribute reporting for battery
@ -569,7 +579,7 @@ void IntegrationPluginZigbeeTradfri::initRemote(ZigbeeNode *node, ZigbeeNodeEndp
// Init OnOff cluster // Init OnOff cluster
qCDebug(dcZigbeeTradfri()) << "Bind on/off cluster to coordinator"; qCDebug(dcZigbeeTradfri()) << "Bind on/off cluster to coordinator";
ZigbeeDeviceObjectReply * zdoReply = node->deviceObject()->requestBindShortAddress(endpoint->endpointId(), ZigbeeClusterLibrary::ClusterIdOnOff, 0x0000); ZigbeeDeviceObjectReply * zdoReply = node->deviceObject()->requestBindGroupAddress(endpoint->endpointId(), ZigbeeClusterLibrary::ClusterIdOnOff, 0x0000);
connect(zdoReply, &ZigbeeDeviceObjectReply::finished, node, [=](){ connect(zdoReply, &ZigbeeDeviceObjectReply::finished, node, [=](){
if (zdoReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) { if (zdoReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) {
qCWarning(dcZigbeeTradfri()) << "Failed to bind on/off cluster to coordinator" << zdoReply->error(); qCWarning(dcZigbeeTradfri()) << "Failed to bind on/off cluster to coordinator" << zdoReply->error();
@ -580,7 +590,7 @@ void IntegrationPluginZigbeeTradfri::initRemote(ZigbeeNode *node, ZigbeeNodeEndp
// Init Level cluster // Init Level cluster
qCDebug(dcZigbeeTradfri()) << "Bind power level cluster to coordinator"; qCDebug(dcZigbeeTradfri()) << "Bind power level cluster to coordinator";
ZigbeeDeviceObjectReply * zdoReply = node->deviceObject()->requestBindShortAddress(endpoint->endpointId(), ZigbeeClusterLibrary::ClusterIdLevelControl, 0x0000); ZigbeeDeviceObjectReply * zdoReply = node->deviceObject()->requestBindGroupAddress(endpoint->endpointId(), ZigbeeClusterLibrary::ClusterIdLevelControl, 0x0000);
connect(zdoReply, &ZigbeeDeviceObjectReply::finished, node, [=](){ connect(zdoReply, &ZigbeeDeviceObjectReply::finished, node, [=](){
if (zdoReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) { if (zdoReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) {
qCWarning(dcZigbeeTradfri()) << "Failed to bind level cluster to coordinator" << zdoReply->error(); qCWarning(dcZigbeeTradfri()) << "Failed to bind level cluster to coordinator" << zdoReply->error();
@ -606,6 +616,7 @@ void IntegrationPluginZigbeeTradfri::initRemote(ZigbeeNode *node, ZigbeeNodeEndp
}); });
}); });
}); });
//433 });
} }
void IntegrationPluginZigbeeTradfri::initMotionSensor(ZigbeeNode *node, ZigbeeNodeEndpoint *endpoint) void IntegrationPluginZigbeeTradfri::initMotionSensor(ZigbeeNode *node, ZigbeeNodeEndpoint *endpoint)
@ -664,7 +675,7 @@ void IntegrationPluginZigbeeTradfri::initMotionSensor(ZigbeeNode *node, ZigbeeNo
} }
qCDebug(dcZigbeeTradfri()) << "Bind on/off cluster to coordinator"; qCDebug(dcZigbeeTradfri()) << "Bind on/off cluster to coordinator";
ZigbeeDeviceObjectReply * zdoReply = node->deviceObject()->requestBindShortAddress(endpoint->endpointId(), ZigbeeClusterLibrary::ClusterIdOnOff, 0x0000); ZigbeeDeviceObjectReply * zdoReply = node->deviceObject()->requestBindGroupAddress(endpoint->endpointId(), ZigbeeClusterLibrary::ClusterIdOnOff, 0x0000);
connect(zdoReply, &ZigbeeDeviceObjectReply::finished, node, [=](){ connect(zdoReply, &ZigbeeDeviceObjectReply::finished, node, [=](){
if (zdoReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) { if (zdoReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) {
qCWarning(dcZigbeeTradfri()) << "Failed to bind on/off cluster to coordinator" << zdoReply->error(); qCWarning(dcZigbeeTradfri()) << "Failed to bind on/off cluster to coordinator" << zdoReply->error();