Skip to content

Commit

Permalink
Support Xiaomi Mijia switch (untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
manup committed Aug 7, 2017
1 parent 9f7e743 commit b9cf4bc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 4 additions & 0 deletions database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,10 @@ static int sqliteLoadAllSensorsCallback(void *user, int ncols, char **colval , c
clusterId = clusterId ? clusterId : ONOFF_CLUSTER_ID;
sensor.addItem(DataTypeString, RConfigGroup);
}
else if (sensor.fingerPrint().hasInCluster(ONOFF_CLUSTER_ID))
{
clusterId = clusterId ? clusterId : ONOFF_CLUSTER_ID;
}
item = sensor.addItem(DataTypeInt32, RStateButtonEvent);
item->setValue(0);
}
Expand Down
30 changes: 28 additions & 2 deletions de_web_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ static const SupportedDevice supportedDevices[] = {
{ VENDOR_JENNIC, "lumi.sens", jennicMacPrefix },
{ VENDOR_JENNIC, "lumi.weather", jennicMacPrefix },
{ VENDOR_JENNIC, "lumi.sensor_magnet", jennicMacPrefix },
{ VENDOR_JENNIC, "lumi.sensor_switch", jennicMacPrefix },
{ 0, 0, 0 }
};

Expand Down Expand Up @@ -2199,6 +2200,10 @@ void DeRestPluginPrivate::addSensorNode(const deCONZ::Node *node)
{
fpOpenCloseSensor.inClusters.push_back(ci->id());
}
else if (modelId.startsWith(QLatin1String("lumi.sensor_switch")))
{
fpSwitch.inClusters.push_back(ci->id());
}
}
break;

Expand Down Expand Up @@ -2279,7 +2284,9 @@ void DeRestPluginPrivate::addSensorNode(const deCONZ::Node *node)
Sensor *sensor = 0;

// ZHASwitch
if (fpSwitch.hasInCluster(ONOFF_SWITCH_CONFIGURATION_CLUSTER_ID) || !fpSwitch.outClusters.empty()) // (!fpSwitch.inClusters.empty() || !fpSwitch.outClusters.empty())
if (fpSwitch.hasInCluster(ONOFF_SWITCH_CONFIGURATION_CLUSTER_ID) ||
fpSwitch.hasInCluster(ONOFF_CLUSTER_ID) ||
!fpSwitch.outClusters.empty())
{
fpSwitch.endpoint = i->endpoint();
fpSwitch.deviceId = i->deviceId();
Expand Down Expand Up @@ -2476,7 +2483,8 @@ void DeRestPluginPrivate::addSensorNode(const deCONZ::Node *node, const SensorFi
{
clusterId = COMMISSIONING_CLUSTER_ID;
}
else if (sensorNode.fingerPrint().hasOutCluster(ONOFF_CLUSTER_ID))
else if (sensorNode.fingerPrint().hasInCluster(ONOFF_CLUSTER_ID) ||
sensorNode.fingerPrint().hasOutCluster(ONOFF_CLUSTER_ID))
{
clusterId = ONOFF_CLUSTER_ID;
}
Expand Down Expand Up @@ -3240,6 +3248,24 @@ void DeRestPluginPrivate::updateSensorNode(const deCONZ::NodeEvent &event)
i->updateStateTimestamp();
}

item = i->item(RStateButtonEvent);

if (item &&
event.event() == deCONZ::NodeEvent::UpdatedClusterDataZclReport)
{
// TODO better button handler
quint32 button;
if (ia->numericValue().u8 == 1) { button = S_BUTTON_1 + S_BUTTON_ACTION_INITIAL_PRESS; }
else { button = S_BUTTON_1 + S_BUTTON_ACTION_SHORT_RELEASED; }

item->setValue(button);

Event e(RSensors, item->descriptor().suffix, i->id());
enqueueEvent(e);
i->setNeedSaveDatabase(true);
i->updateStateTimestamp();
}

updateSensorEtag(&*i);
}
}
Expand Down

0 comments on commit b9cf4bc

Please sign in to comment.