Skip to content

Commit

Permalink
Add initial support for LifeControl enviroment sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
bastshoes committed Oct 14, 2019
1 parent 7699c98 commit 538075d
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 22 deletions.
10 changes: 10 additions & 0 deletions bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,8 @@ bool DeRestPluginPrivate::checkSensorBindingsForAttributeReporting(Sensor *senso
sensor->modelId() == QLatin1String("WL4200S") ||
//LifeControl smart plug
sensor->modelId() == QLatin1String("RICI01") ||
//LifeControl enviroment sensor
sensor->modelId() == QLatin1String("VOC_Sensor") ||
// ORVIBO
sensor->modelId().startsWith(QLatin1String("SN10ZW")) ||
sensor->modelId().startsWith(QLatin1String("SF2")))
Expand Down Expand Up @@ -2215,6 +2217,14 @@ bool DeRestPluginPrivate::checkSensorBindingsForClientClusters(Sensor *sensor)
srcEndpoints.push_back(0x04);
sensor->setMgmtBindSupported(true);
}
// LifeControl Enviroment Sensor
else if (sensor->modelId().startsWith(QLatin1String("VOC_Sensor")))
{
clusters.push_back(TEMPERATURE_MEASUREMENT_CLUSTER_ID);
srcEndpoints.push_back(0x00);
srcEndpoints.push_back(0x01);
sensor->setMgmtBindSupported(true);
}
else
{
return false;
Expand Down
138 changes: 116 additions & 22 deletions de_web_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ static const SupportedDevice supportedDevices[] = {
{ VENDOR_EMBER, "3AFE140103020000", konkeMacPrefix }, // Konke Kit Pro-FT Temp Humidity Sensor
{ VENDOR_EMBER, "3AFE130104020015", konkeMacPrefix }, // Konke Kit Pro-Door Entry Sensor
{ VENDOR_NONE, "RICI01", tiMacPrefix}, // LifeControl smart plug
{ VENDOR_JENNIC, "VOC_Sensor", jennicMacPrefix}, //LifeControl Enviroment sensor
{ VENDOR_JENNIC, "SN10ZW", jennicMacPrefix }, // ORVIBO motion sensor
{ VENDOR_OSRAM_STACK, "SF2", heimanMacPrefix }, // ORVIBO (Heiman) smoke sensor
{ 0, nullptr, 0 }
Expand Down Expand Up @@ -3868,13 +3869,34 @@ void DeRestPluginPrivate::addSensorNode(const deCONZ::Node *node, const deCONZ::

case TEMPERATURE_MEASUREMENT_CLUSTER_ID:
{
fpTemperatureSensor.inClusters.push_back(ci->id());
if (modelId.startsWith(QLatin1String("VOC_Sensor"))
{
if (i->endpoint() == 0x00)
{
fpTemperatureSensor.inClusters.push_back(ci->id());
}
else if (i->endpoint() == 0x01)
{
fpHumiditySensor.inClusters.push_back(ci->id());
}
}
else
{
fpTemperatureSensor.inClusters.push_back(ci->id());
}
}
break;

case RELATIVE_HUMIDITY_CLUSTER_ID:
{
fpHumiditySensor.inClusters.push_back(ci->id());
if (modelId.startsWith(QLatin1String("VOC_Sensor"))
{
// Ignore RELATIVE HUMIDITY CLUSTER
}
else
{
fpHumiditySensor.inClusters.push_back(ci->id());
}
}
break;

Expand Down Expand Up @@ -3990,7 +4012,14 @@ void DeRestPluginPrivate::addSensorNode(const deCONZ::Node *node, const deCONZ::

case THERMOSTAT_CLUSTER_ID:
{
fpThermostatSensor.inClusters.push_back(ci->id());
if (modelId.startsWith(QLatin1String("VOC_Sensor"))
{
// Ignore THERMOSTAT CLUSTER
}
else
{
fpThermostatSensor.inClusters.push_back(ci->id());
}
}
break;

Expand Down Expand Up @@ -5718,34 +5747,99 @@ void DeRestPluginPrivate::updateSensorNode(const deCONZ::NodeEvent &event)
{
for (;ia != enda; ++ia)
{
if (ia->id() == 0x0000) // temperature (0.01 °C)
if (i->modelId().startsWith(QLatin1String("VOC_Sensor")))
{
if (updateType != NodeValue::UpdateInvalid)
if (ia->id() == 0x0000) // temperature (0.01 °C)
{
i->setZclValue(updateType, event.clusterId(), 0x0000, ia->numericValue());
pushZclValueDb(event.node()->address().ext(), event.endpoint(), event.clusterId(), ia->id(), ia->numericValue().s16);
}
if (updateType != NodeValue::UpdateInvalid)
{
i->setZclValue(updateType, event.clusterId(), 0x0000, ia->numericValue());
pushZclValueDb(event.node()->address().ext(), event.endpoint(), event.clusterId(), ia->id(), ia->numericValue().s16);
}

int temp = ia->numericValue().s16;
ResourceItem *item = i->item(RStateTemperature);
int temp = ia->numericValue().s16;
ResourceItem *item = i->item(RStateTemperature);

if (item)
{
ResourceItem *item2 = i->item(RConfigOffset);
if (item2 && item2->toNumber() != 0)
if (item)
{
temp += item2->toNumber();
ResourceItem *item2 = i->item(RConfigOffset);
if (item2 && item2->toNumber() != 0)
{
temp += item2->toNumber();
}
item->setValue(temp);
i->updateStateTimestamp();
i->setNeedSaveDatabase(true);
Event e(RSensors, RStateTemperature, i->id(), item);
enqueueEvent(e);
enqueueEvent(Event(RSensors, RStateLastUpdated, i->id()));
}
item->setValue(temp);
i->updateStateTimestamp();
i->setNeedSaveDatabase(true);
Event e(RSensors, RStateTemperature, i->id(), item);
enqueueEvent(e);
enqueueEvent(Event(RSensors, RStateLastUpdated, i->id()));

updateSensorEtag(&*i);
}

updateSensorEtag(&*i);
if(ia->id() == 0x0001) //// relative humidity
{
if (updateType != NodeValue::UpdateInvalid)
{
i->setZclValue(updateType, event.clusterId(), 0x0001, ia->numericValue());
pushZclValueDb(event.node()->address().ext(), event.endpoint(), event.clusterId(), ia->id(), ia->numericValue().u16);
}

int humidity = ia->numericValue().u16;
ResourceItem *item = i->item(RStateHumidity);

if (item)
{
ResourceItem *item2 = i->item(RConfigOffset);
if (item2 && item2->toNumber() != 0)
{
qint16 _humidity = humidity + item2->toNumber();
humidity = _humidity < 0 ? 0 : _humidity > 10000 ? 10000 : _humidity;
}
item->setValue(humidity);
i->updateStateTimestamp();
i->setNeedSaveDatabase(true);
Event e(RSensors, RStateHumidity, i->id(), item);
enqueueEvent(e);
enqueueEvent(Event(RSensors, RStateLastUpdated, i->id()));
}

updateSensorEtag(&*i);
}

}
else
{
if (ia->id() == 0x0000) // temperature (0.01 °C)
{
if (updateType != NodeValue::UpdateInvalid)
{
i->setZclValue(updateType, event.clusterId(), 0x0000, ia->numericValue());
pushZclValueDb(event.node()->address().ext(), event.endpoint(), event.clusterId(), ia->id(), ia->numericValue().s16);
}

int temp = ia->numericValue().s16;
ResourceItem *item = i->item(RStateTemperature);

if (item)
{
ResourceItem *item2 = i->item(RConfigOffset);
if (item2 && item2->toNumber() != 0)
{
temp += item2->toNumber();
}
item->setValue(temp);
i->updateStateTimestamp();
i->setNeedSaveDatabase(true);
Event e(RSensors, RStateTemperature, i->id(), item);
enqueueEvent(e);
enqueueEvent(Event(RSensors, RStateLastUpdated, i->id()));
}

updateSensorEtag(&*i);
}
}
}
}
else if (event.clusterId() == RELATIVE_HUMIDITY_CLUSTER_ID)
Expand Down

0 comments on commit 538075d

Please sign in to comment.