Button event introspection return only availale buttons
Filter button events for existing endpoints with references in the button map.
Needed for switches where the button map contains entries for multiple models
with different amount of buttons (e.g. sunricher 2/4/8 button switches).
@@ -820,6 +820,13 @@ QVariantMap RIS_IntrospectButtonEventItem(const ResourceItemDescriptor &rid, con
return result;
}
+ const deCONZ::Node *node = getCoreNode(sensor->address().ext(), deCONZ::ApsController::instance());
+
+ if (!node)
+ {
+ return result;
+ }
+
// TODO dependency on plugin needs to be removed to make this testable
const auto &buttonMapButtons = plugin->buttonMeta;
const auto &buttonMapData = plugin->buttonMaps;
@@ -839,6 +846,15 @@ QVariantMap RIS_IntrospectButtonEventItem(const ResourceItemDescriptor &rid, con
for (const auto &btn : buttonData->buttons)
{
+
+ const auto sd = std::find_if(node->simpleDescriptors().cbegin(), node->simpleDescriptors().cend(),
+ [&btn](const deCONZ::SimpleDescriptor &x){ return x.endpoint() == btn.endpoint; });
+
+ if (sd == node->simpleDescriptors().cend())
+ {
+ continue;
+ }
+
buttonBits |= 1 << int(btn.button / 1000);
QVariantMap m;
@@ -857,12 +873,15 @@ QVariantMap RIS_IntrospectButtonEventItem(const ResourceItemDescriptor &rid, con
if (buttonsMeta != buttonMapButtons.cend())
{
for (const auto &button : buttonsMeta->buttons)
+ {
+ if (buttonBits & (1 << button.button))
{
QVariantMap m;
m[QLatin1String("name")] = button.name;
buttons[QString::number(button.button)] = m;
}
}
+ }
else // fallback if no "buttons" is defined in the button map, generate a generic one
{
for (int i = 1 ; i < 32; i++)
