Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose RConfigInterfaceMode for Develco EMI Norwegian HAN #4653

Merged
merged 3 commits into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3466,6 +3466,10 @@ static int sqliteLoadAllSensorsCallback(void *user, int ncols, char **colval , c
sensor.addItem(DataTypeUInt8, RConfigInterfaceMode)->setValue(1);
sensor.addItem(DataTypeUInt16, RConfigPulseConfiguration)->setValue(1000);
}
if (sensor.modelId().startsWith(QLatin1String("EMIZB-1")))
{
sensor.addItem(DataTypeUInt8, RConfigInterfaceMode)->setValue(1);
}
}
else if (sensor.fingerPrint().hasInCluster(ANALOG_INPUT_CLUSTER_ID))
{
Expand Down
4 changes: 4 additions & 0 deletions de_web_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6714,6 +6714,10 @@ void DeRestPluginPrivate::addSensorNode(const deCONZ::Node *node, const SensorFi
sensorNode.addItem(DataTypeUInt8, RConfigInterfaceMode)->setValue(1);
sensorNode.addItem(DataTypeUInt16, RConfigPulseConfiguration)->setValue(1000);
}
if (modelId.startsWith(QLatin1String("EMIZB-1")))
{
sensorNode.addItem(DataTypeUInt8, RConfigInterfaceMode)->setValue(1);
}
}
else if (sensorNode.fingerPrint().hasInCluster(ANALOG_INPUT_CLUSTER_ID))
{
Expand Down
5 changes: 5 additions & 0 deletions de_web_plugin_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,11 @@ using namespace deCONZ::literals;
#define DLMS_COSEM 0x0102
#define DSMR_23 0x0103
#define DSMR_40 0x0104
#define NORWEGIAN_HAN 0x0200
#define NORWEGIAN_HAN_EXTRA_LOAD 0x0201
#define AIDON_METER 0x0202
#define KAIFA_KAMSTRUP_METERS 0x0203
#define AUTO_DETECT 0x0204

#ifndef DBG_IAS
#define DBG_IAS DBG_INFO // DBG_IAS didn't exist before version v2.10.x
Expand Down
47 changes: 30 additions & 17 deletions rest_sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2311,28 +2311,34 @@ int DeRestPluginPrivate::changeSensorConfig(const ApiRequest &req, ApiResponse &
{
if (map[pi.key()].type() == QVariant::Double)
{
if (sensor->modelId() == QLatin1String("ZHEMI101"))
if (sensor->modelId() == QLatin1String("ZHEMI101") || sensor->modelId().startsWith(QLatin1String("EMIZB-1")))
{
const uint mode = map[pi.key()].toUInt(&ok);
quint16 interfaceMode = 0;

if (ok && mode == 1) { interfaceMode = PULSE_COUNTING_ELECTRICITY; }
else if (ok && mode == 2) { interfaceMode = PULSE_COUNTING_GAS; }
else if (ok && mode == 3) { interfaceMode = PULSE_COUNTING_WATER; }
else if (ok && mode == 4) { interfaceMode = KAMSTRUP_KMP; }
else if (ok && mode == 5) { interfaceMode = LINKY; }
else if (ok && mode == 6) { interfaceMode = DLMS_COSEM; }
else if (ok && mode == 7) { interfaceMode = DSMR_23; }
else if (ok && mode == 8) { interfaceMode = DSMR_40; }
else

if (!ok)
{ }
if (sensor->modelId() == QLatin1String("ZHEMI101"))
{
rsp.list.append(errorToMap(ERR_INVALID_VALUE, QString("/sensors/%1/config/%2").arg(id).arg(pi.key()),
QString("invalid value, %1, for parameter %2").arg(map[pi.key()].toString()).arg(pi.key())));
rsp.httpStatus = HttpStatusBadRequest;
return REQ_READY_SEND;
if (mode == 1) { interfaceMode = PULSE_COUNTING_ELECTRICITY; }
else if (mode == 2) { interfaceMode = PULSE_COUNTING_GAS; }
else if (mode == 3) { interfaceMode = PULSE_COUNTING_WATER; }
else if (mode == 4) { interfaceMode = KAMSTRUP_KMP; }
else if (mode == 5) { interfaceMode = LINKY; }
else if (mode == 6) { interfaceMode = DLMS_COSEM; }
else if (mode == 7) { interfaceMode = DSMR_23; }
else if (mode == 8) { interfaceMode = DSMR_40; }
}

if (mode > 0 && mode < 9)
else if (sensor->modelId().startsWith(QLatin1String("EMIZB-1")))
{
if (mode == 1) { interfaceMode = NORWEGIAN_HAN; }
else if (mode == 2) { interfaceMode = NORWEGIAN_HAN_EXTRA_LOAD; }
else if (mode == 3) { interfaceMode = AIDON_METER; }
else if (mode == 4) { interfaceMode = KAIFA_KAMSTRUP_METERS; }
else if (mode == 5) { interfaceMode = AUTO_DETECT; }
}

if (interfaceMode != 0)
{
if (addTaskSimpleMeteringReadWriteAttribute(task, deCONZ::ZclWriteAttributesId, 0x0302, deCONZ::Zcl16BitEnum, interfaceMode, VENDOR_DEVELCO))
{
Expand All @@ -2346,6 +2352,13 @@ int DeRestPluginPrivate::changeSensorConfig(const ApiRequest &req, ApiResponse &
return REQ_READY_SEND;
}
}
else
{
rsp.list.append(errorToMap(ERR_INVALID_VALUE, QString("/sensors/%1/config/%2").arg(id).arg(pi.key()),
QString("invalid value, %1, for parameter %2").arg(map[pi.key()].toString()).arg(pi.key())));
rsp.httpStatus = HttpStatusBadRequest;
return REQ_READY_SEND;
}
}
else
{
Expand Down
31 changes: 21 additions & 10 deletions simple_metering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,33 @@ void DeRestPluginPrivate::handleSimpleMeteringClusterIndication(const deCONZ::Ap

case 0x0302: // Interface Mode
{
if (zclFrame.manufacturerCode() == VENDOR_DEVELCO && sensor->modelId() == QLatin1String("ZHEMI101"))
if (zclFrame.manufacturerCode() == VENDOR_DEVELCO)
{
quint16 interfaceMode = attr.numericValue().u16;
quint8 mode = 0;

if (interfaceMode == PULSE_COUNTING_ELECTRICITY) { mode = 1; }
else if (interfaceMode == PULSE_COUNTING_GAS) { mode = 2; }
else if (interfaceMode == PULSE_COUNTING_WATER) { mode = 3; }
else if (interfaceMode == KAMSTRUP_KMP) { mode = 4; }
else if (interfaceMode == LINKY) { mode = 5; }
else if (interfaceMode == DLMS_COSEM) { mode = 6; }
else if (interfaceMode == DSMR_23) { mode = 7; }
else if (interfaceMode == DSMR_40) { mode = 8; }
if(sensor->modelId() == QLatin1String("ZHEMI101"))
{
if (interfaceMode == PULSE_COUNTING_ELECTRICITY) { mode = 1; }
else if (interfaceMode == PULSE_COUNTING_GAS) { mode = 2; }
else if (interfaceMode == PULSE_COUNTING_WATER) { mode = 3; }
else if (interfaceMode == KAMSTRUP_KMP) { mode = 4; }
else if (interfaceMode == LINKY) { mode = 5; }
else if (interfaceMode == DLMS_COSEM) { mode = 6; }
else if (interfaceMode == DSMR_23) { mode = 7; }
else if (interfaceMode == DSMR_40) { mode = 8; }
]
else if (sensor->modelId().startsWith(QLatin1String("EMIZB-1")))
{
if (interfaceMode == NORWEGIAN_HAN) { mode = 1; }
else if (interfaceMode == NORWEGIAN_HAN_EXTRA_LOAD) { mode = 2; }
else if (interfaceMode == AIDON_METER) { mode = 3; }
else if (interfaceMode == KAIFA_KAMSTRUP_METERS) { mode = 4; }
else if (interfaceMode == AUTO_DETECT) { mode = 5; }
}

item = sensor->item(RConfigInterfaceMode);
if (item && item->toNumber() != mode && mode > 0 && mode < 9)
if (item && mode != 0 && item->toNumber() != mode)
{
item->setValue(mode);
enqueueEvent(Event(RSensors, RConfigInterfaceMode, sensor->id(), item));
Expand Down