Skip to content

Commit

Permalink
DDF for dresden elektronik scene and lighting switches (#7464)
Browse files Browse the repository at this point in the history
The PR removes quite large C++ parts which were needed to support the switches in legacy code.

The DDF button detection should be simplified in future without needing Javascript. The lighting switch uses 2 switch resources for legacy reasons.

Note the validator might be a bit nervous here until the "cmd": "any" is added.
  • Loading branch information
manup authored Dec 18, 2023
1 parent 986ccd1 commit b835464
Show file tree
Hide file tree
Showing 9 changed files with 543 additions and 450 deletions.
76 changes: 0 additions & 76 deletions button_maps.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,82 +146,6 @@
}
},
"maps": {
"deLightingSwitchMap": {
"vendor": "dresden elektronik",
"modelids": ["Lighting Switch"],
"doc": "Lighting Switch",
"buttons": [
{"S_BUTTON_1": "Top Left"},
{"S_BUTTON_2": "Bottom Left"},
{"S_BUTTON_3": "Top Right"},
{"S_BUTTON_4": "Bottom Right"}
],
"map": [
[1, "0x01", "ONOFF", "ON", "0", "S_BUTTON_1", "S_BUTTON_ACTION_SHORT_RELEASED", "On"],
[2, "0x01", "ONOFF", "ON", "0", "S_BUTTON_1", "S_BUTTON_ACTION_SHORT_RELEASED", "On"],
[3, "0x01", "ONOFF", "ON", "0", "S_BUTTON_1", "S_BUTTON_ACTION_SHORT_RELEASED", "On"],
[1, "0x01", "LEVEL_CONTROL", "MOVE", "0", "S_BUTTON_1", "S_BUTTON_ACTION_HOLD", "Dimm up"],
[2, "0x01", "LEVEL_CONTROL", "MOVE", "0", "S_BUTTON_1", "S_BUTTON_ACTION_HOLD", "Dimm up"],
[3, "0x01", "LEVEL_CONTROL", "MOVE", "0", "S_BUTTON_1", "S_BUTTON_ACTION_HOLD", "Dimm up"],
[1, "0x01", "LEVEL_CONTROL", "STOP", "0", "S_BUTTON_1", "S_BUTTON_ACTION_LONG_RELEASED", "Dimm stop"],
[2, "0x01", "LEVEL_CONTROL", "STOP", "0", "S_BUTTON_1", "S_BUTTON_ACTION_LONG_RELEASED", "Dimm stop"],
[3, "0x01", "LEVEL_CONTROL", "STOP", "0", "S_BUTTON_1", "S_BUTTON_ACTION_LONG_RELEASED", "Dimm stop"],

[1, "0x01", "ONOFF", "OFF", "0", "S_BUTTON_2", "S_BUTTON_ACTION_SHORT_RELEASED", "Off"],
[2, "0x01", "ONOFF", "OFF", "0", "S_BUTTON_2", "S_BUTTON_ACTION_SHORT_RELEASED", "Off"],
[3, "0x01", "ONOFF", "OFF", "0", "S_BUTTON_2", "S_BUTTON_ACTION_SHORT_RELEASED", "Off"],
[1, "0x01", "LEVEL_CONTROL", "MOVE", "1", "S_BUTTON_2", "S_BUTTON_ACTION_HOLD", "Dimm down"],
[2, "0x01", "LEVEL_CONTROL", "MOVE", "1", "S_BUTTON_2", "S_BUTTON_ACTION_HOLD", "Dimm down"],
[3, "0x01", "LEVEL_CONTROL", "MOVE", "1", "S_BUTTON_2", "S_BUTTON_ACTION_HOLD", "Dimm down"],
[1, "0x01", "LEVEL_CONTROL", "STOP", "1", "S_BUTTON_2", "S_BUTTON_ACTION_LONG_RELEASED", "Dimm stop"],
[2, "0x01", "LEVEL_CONTROL", "STOP", "1", "S_BUTTON_2", "S_BUTTON_ACTION_LONG_RELEASED", "Dimm stop"],
[3, "0x01", "LEVEL_CONTROL", "STOP", "1", "S_BUTTON_2", "S_BUTTON_ACTION_LONG_RELEASED", "Dimm stop"],

[1, "0x01", "SCENES", "RECALL_SCENE", "1", "S_BUTTON_3", "S_BUTTON_ACTION_SHORT_RELEASED", "Recall scene 1"],
[2, "0x02", "ONOFF", "ON", "0", "S_BUTTON_3", "S_BUTTON_ACTION_SHORT_RELEASED", "On"],
[3, "0x01", "COLOR_CONTROL", "MOVE_COLOR_TEMPERATURE", "0x01FE", "S_BUTTON_3", "S_BUTTON_ACTION_SHORT_RELEASED", "Color temperature move up"],
[2, "0x02", "LEVEL_CONTROL", "MOVE_WITH_ON_OFF", "0", "S_BUTTON_3", "S_BUTTON_ACTION_HOLD", "Dimm up"],
[3, "0x01", "COLOR_CONTROL", "MOVE_COLOR_TEMPERATURE", "0x0128", "S_BUTTON_3", "S_BUTTON_ACTION_HOLD", "Color temperature move up hold"],
[2, "0x02", "LEVEL_CONTROL", "STOP", "0", "S_BUTTON_3", "S_BUTTON_ACTION_LONG_RELEASED", "Dimm stop"],
[3, "0x01", "COLOR_CONTROL", "MOVE_COLOR_TEMPERATURE", "0x1028", "S_BUTTON_3", "S_BUTTON_ACTION_LONG_RELEASED", "Color temperature move up stop"],


[1, "0x01", "SCENES", "RECALL_SCENE", "4", "S_BUTTON_4", "S_BUTTON_ACTION_SHORT_RELEASED", "Recall scene 4"],
[2, "0x02", "ONOFF", "OFF", "0", "S_BUTTON_4", "S_BUTTON_ACTION_SHORT_RELEASED", "Off"],
[3, "0x01", "COLOR_CONTROL", "MOVE_COLOR_TEMPERATURE", "0x03FE", "S_BUTTON_4", "S_BUTTON_ACTION_SHORT_RELEASED", "Color temperature move down"],
[2, "0x02", "LEVEL_CONTROL", "MOVE", "1", "S_BUTTON_4", "S_BUTTON_ACTION_HOLD", "Dimm down"],
[3, "0x01", "COLOR_CONTROL", "MOVE_COLOR_TEMPERATURE", "0x0328", "S_BUTTON_4", "S_BUTTON_ACTION_HOLD", "Color temperature move down hold"],
[2, "0x02", "LEVEL_CONTROL", "STOP", "1", "S_BUTTON_4", "S_BUTTON_ACTION_LONG_RELEASED", "Dimm stop"],
[3, "0x01", "COLOR_CONTROL", "MOVE_COLOR_TEMPERATURE", "0x3028", "S_BUTTON_4", "S_BUTTON_ACTION_LONG_RELEASED", "Color temperature move down stop"]
]
},
"deSceneSwitchMap": {
"vendor": "dresden elektronik",
"modelids": ["Scene Switch"],
"doc": "Scene Switch",
"buttons": [
{"S_BUTTON_1": "Top Left"},
{"S_BUTTON_2": "Bottom Left"},
{"S_BUTTON_3": "Scene 1"},
{"S_BUTTON_4": "Scene 2"},
{"S_BUTTON_5": "Scene 3"},
{"S_BUTTON_6": "Scene 4"}
],
"map": [
[1, "0x01", "ONOFF", "ON", "0", "S_BUTTON_1", "S_BUTTON_ACTION_SHORT_RELEASED", "On"],
[1, "0x01", "LEVEL_CONTROL", "MOVE", "0", "S_BUTTON_1", "S_BUTTON_ACTION_HOLD", "Dimm up"],
[1, "0x01", "LEVEL_CONTROL", "STOP", "0", "S_BUTTON_1", "S_BUTTON_ACTION_LONG_RELEASED", "Dimm up stop"],

[1, "0x01", "ONOFF", "OFF", "0", "S_BUTTON_2", "S_BUTTON_ACTION_SHORT_RELEASED", "Off"],
[1, "0x01", "LEVEL_CONTROL", "MOVE", "1", "S_BUTTON_2", "S_BUTTON_ACTION_HOLD", "Dimm down"],
[1, "0x01", "LEVEL_CONTROL", "STOP", "1", "S_BUTTON_2", "S_BUTTON_ACTION_LONG_RELEASED", "Dimm down stop"],

[1, "0x01", "SCENES", "RECALL_SCENE", "1", "S_BUTTON_3", "S_BUTTON_ACTION_SHORT_RELEASED", "Recall scene 1"],
[1, "0x01", "SCENES", "RECALL_SCENE", "2", "S_BUTTON_4", "S_BUTTON_ACTION_SHORT_RELEASED", "Recall scene 2"],
[1, "0x01", "SCENES", "RECALL_SCENE", "3", "S_BUTTON_5", "S_BUTTON_ACTION_SHORT_RELEASED", "Recall scene 3"],
[1, "0x01", "SCENES", "RECALL_SCENE", "4", "S_BUTTON_6", "S_BUTTON_ACTION_SHORT_RELEASED", "Recall scene 4"]
]
},
"deKoboldMap": {
"vendor": "dresden elektronik",
"modelids": ["Kobold"],
Expand Down
89 changes: 17 additions & 72 deletions de_web_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ static const SupportedDevice supportedDevices[] = {
{ VENDOR_NONE, "SPW35Z", tiMacPrefix }, // RT-RK OBLO SPW35ZD0 smart plug
{ VENDOR_NONE, "SWO-MOS1PA", tiMacPrefix }, // Swann One Motion Sensor
{ VENDOR_BITRON, "902010/32", emberMacPrefix }, // Bitron: thermostat
{ VENDOR_DDEL, "Lighting Switch", deMacPrefix },
{ VENDOR_DDEL, "Scene Switch", deMacPrefix },
{ VENDOR_IKEA, "TRADFRI remote control", silabs1MacPrefix },
{ VENDOR_IKEA, "TRADFRI remote control", silabsMacPrefix },
{ VENDOR_IKEA, "TRADFRI remote control", silabs2MacPrefix },
Expand Down Expand Up @@ -4500,47 +4498,6 @@ void DeRestPluginPrivate::checkSensorButtonEvent(Sensor *sensor, const deCONZ::A
{
// DDF managed devices handle this in another place
}
// DE Lighting Switch: probe for mode changes
else if (sensor->modelId() == QLatin1String("Lighting Switch") && ind.dstAddressMode() == deCONZ::ApsGroupAddress)
{
Sensor::SensorMode mode = sensor->mode();

if (ind.srcEndpoint() == 2 && mode != Sensor::ModeTwoGroups)
{
mode = Sensor::ModeTwoGroups;
}
else if (ind.clusterId() == SCENE_CLUSTER_ID && mode != Sensor::ModeScenes)
{
mode = Sensor::ModeScenes;
}
else if (ind.clusterId() == COLOR_CLUSTER_ID && mode != Sensor::ModeColorTemperature)
{
mode = Sensor::ModeColorTemperature;
}

Sensor *other = getSensorNodeForAddressAndEndpoint(sensor->address(), (sensor->fingerPrint().endpoint == 2) ? 1 : 2);

if (mode != sensor->mode())
{
sensor->setMode(mode);
updateSensorEtag(sensor);
sensor->setNeedSaveDatabase(true);
queSaveDb(DB_SENSORS, DB_SHORT_SAVE_DELAY);

// set changed mode for sensor endpoints 1 and 2
if (other)
{
other->setMode(mode);
other->setNeedSaveDatabase(true);
updateSensorEtag(other);
}
}

if (other && ind.srcEndpoint() == 2 && other->fingerPrint().endpoint == 1)
{ // forward button events 300x and 400x to first endpoint sensor
checkSensorButtonEvent(other, ind, zclFrame);
}
}
// Busch-Jaeger
else if (sensor->modelId() == QLatin1String("RM01") || sensor->modelId() == QLatin1String("RB01"))
{
Expand Down Expand Up @@ -4661,11 +4618,6 @@ void DeRestPluginPrivate::checkSensorButtonEvent(Sensor *sensor, const deCONZ::A
}
else if (ind.dstAddressMode() == deCONZ::ApsGroupAddress)
{
if (sensor->mode() == Sensor::ModeTwoGroups) // only supported for DE Lighting Switch
{
sensor->setMode(Sensor::ModeScenes);
updateSensorEtag(sensor);
}
}
else if (sensor->modelId().endsWith(QLatin1String("86opcn01"))) // Aqara Opple
{
Expand Down Expand Up @@ -4725,21 +4677,6 @@ void DeRestPluginPrivate::checkSensorButtonEvent(Sensor *sensor, const deCONZ::A

quint16 groupId = ind.dstAddress().group();

if (sensor->modelId() == QLatin1String("Lighting Switch"))
{
// adjust groupId for endpoints
// ep 1: <gid>
// ep 2: <gid> + 1
if (sensor->fingerPrint().endpoint == 2 && ind.srcEndpoint() == 1)
{
groupId++;
}
else if (sensor->fingerPrint().endpoint == 1 && ind.srcEndpoint() == 2)
{
groupId--;
}
}

QStringList gids;
const QString gid = QString::number(groupId);

Expand Down Expand Up @@ -7715,12 +7652,6 @@ void DeRestPluginPrivate::addSensorNode(const deCONZ::Node *node, const SensorFi
}
else if (node->nodeDescriptor().manufacturerCode() == VENDOR_DDEL)
{
sensorNode.setManufacturer("dresden elektronik");

if (modelId == QLatin1String("Lighting Switch"))
{
sensorNode.setMode(Sensor::ModeTwoGroups); // inital
}
}
else if ((node->nodeDescriptor().manufacturerCode() == VENDOR_OSRAM_STACK) || (node->nodeDescriptor().manufacturerCode() == VENDOR_OSRAM))
{
Expand Down Expand Up @@ -16728,10 +16659,24 @@ void DEV_AllocateGroup(const Device *device, Resource *rsub, ResourceItem *item)
if (groupList[i] != QLatin1String("auto") && groupList[i] != QLatin1String("null"))
{
// verify group exists
auto g = std::find_if(groups.begin(), groups.end(), [&](const Group &x)
{ return x.state() == Group::StateNormal && x.id() == groupList[i]; });
auto g = std::find_if(groups.begin(), groups.end(), [&](const Group &x) {
const ResourceItem *itemUniqueId = x.item(RAttrUniqueId);
if (x.state() == Group::StateNormal)
{
if (x.id() == groupList[i])
{
return true;
}

if (itemUniqueId && itemUniqueId->toString() == gUniqueId)
{
return true;
}
}
return false;
});

if (g == groups.cend())
if (g == groups.end())
{
bool ok;
uint gid = groupList[i].toUInt(&ok, 0);
Expand Down
Loading

0 comments on commit b835464

Please sign in to comment.