Skip to content

Commit

Permalink
Merge pull request #57 from dresden-elektronik/master
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
Smanar authored Apr 26, 2021
2 parents f83abdb + ea37a53 commit e78b27c
Show file tree
Hide file tree
Showing 12 changed files with 1,429 additions and 1,323 deletions.
479 changes: 250 additions & 229 deletions bindings.cpp

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion button_maps.json
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,22 @@
[1, "0x01", "MULTISTATE_INPUT", "ATTRIBUTE_REPORT", "255", "S_BUTTON_1", "S_BUTTON_ACTION_LONG_RELEASED", "Long released"]
]
},
"xiaomiSwitchBx1acn02Map": {
"vendor": "Xiaomi",
"doc": "Xiaomi Aqara D1 1-gang QBKG21LM and 2-gang QBKG22LM",
"modelids": ["lumi.switch.b1lacn02", "lumi.switch.b2lacn02"],
"map": [
[1, "0x04", "ONOFF", "ATTRIBUTE_REPORT", "0", "S_BUTTON_1", "S_BUTTON_ACTION_SHORT_RELEASED", "Normal press"],
[1, "0x04", "ONOFF", "ATTRIBUTE_REPORT", "1", "S_BUTTON_1", "S_BUTTON_ACTION_LONG_RELEASED", "Long press"],
[1, "0x04", "ONOFF", "ATTRIBUTE_REPORT", "2", "S_BUTTON_1", "S_BUTTON_ACTION_DOUBLE_PRESS", "Double press"],
[1, "0x05", "ONOFF", "ATTRIBUTE_REPORT", "0", "S_BUTTON_2", "S_BUTTON_ACTION_SHORT_RELEASED", "Normal press"],
[1, "0x05", "ONOFF", "ATTRIBUTE_REPORT", "1", "S_BUTTON_2", "S_BUTTON_ACTION_LONG_RELEASED", "Long press"],
[1, "0x05", "ONOFF", "ATTRIBUTE_REPORT", "2", "S_BUTTON_2", "S_BUTTON_ACTION_DOUBLE_PRESS", "Double press"],
[1, "0x06", "ONOFF", "ATTRIBUTE_REPORT", "0", "S_BUTTON_3", "S_BUTTON_ACTION_SHORT_RELEASED", "Normal press"],
[1, "0x06", "ONOFF", "ATTRIBUTE_REPORT", "1", "S_BUTTON_3", "S_BUTTON_ACTION_LONG_RELEASED", "Long press"],
[1, "0x06", "ONOFF", "ATTRIBUTE_REPORT", "2", "S_BUTTON_3", "S_BUTTON_ACTION_DOUBLE_PRESS", "Double press"]
]
},
"xiaomiSwitchAq2Map": {
"vendor": "Xiaomi",
"doc": "WXKG11LM 2016 remote",
Expand Down Expand Up @@ -959,7 +975,7 @@
"Tuya3gangMap": {
"vendor": "Tuya",
"doc": "3-gang remote",
"modelids": ["_TZ3000_bi6lpsew", "_TZ3400_keyjhapk", "_TYZB02_key8kk7r", "_TZ3400_keyjqthh", "_TZ3400_key8kk7r", "_TZ3000_vp6clf9d", "_TYZB02_keyjqthh", "_TZ3000_peszejy7", "_TZ3000_qzjcsmar", "_TZ3000_owgcnkrh", "_TZ3000_adkvzooy", "_TZ3000_arfwfgoa", "_TZ3000_a7ouggvs"],
"modelids": ["_TZ3000_bi6lpsew", "_TZ3400_keyjhapk", "_TYZB02_key8kk7r", "_TZ3400_keyjqthh", "_TZ3400_key8kk7r", "_TZ3000_vp6clf9d", "_TYZB02_keyjqthh", "_TZ3000_peszejy7", "_TZ3000_qzjcsmar", "_TZ3000_owgcnkrh", "_TZ3000_adkvzooy", "_TZ3000_arfwfgoa", "_TZ3000_a7ouggvs", "_TZ3000_rrjr1q0u", "_TZ3000_abci1hiu"],
"map": [
[1, "0x01", "ONOFF", "0xfd", "0", "S_BUTTON_1", "S_BUTTON_ACTION_SHORT_RELEASED", "B1 short"],
[1, "0x01", "ONOFF", "0xfd", "1", "S_BUTTON_1", "S_BUTTON_ACTION_DOUBLE_PRESS", "B1 double"],
Expand Down
33 changes: 14 additions & 19 deletions database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3718,6 +3718,13 @@ static int sqliteLoadAllSensorsCallback(void *user, int ncols, char **colval , c
sensor.addItem(DataTypeString, RConfigFanMode);
sensor.addItem(DataTypeString, RConfigSwingMode);
}
else if (sensor.modelId() == QLatin1String("iTRV")) // Drayton Wiser Radiator Thermostat
{
sensor.addItem(DataTypeUInt8, RStateValve);
sensor.addItem(DataTypeInt16, RConfigCoolSetpoint);
sensor.addItem(DataTypeString, RConfigMode);
sensor.addItem(DataTypeBool, RConfigLocked)->setValue(false);
}
else if (sensor.modelId() == QLatin1String("TH1300ZB")) // sinope thermostat
{
sensor.addItem(DataTypeUInt8, RStateValve);
Expand Down Expand Up @@ -4884,11 +4891,11 @@ void DeRestPluginPrivate::saveDb()

i->setNeedSaveDatabase(false);

/*
if (i->state() == LightNode::StateDeleted)
{
// delete LightNode from db (if exist)
QString sql = QString("DELETE FROM nodes WHERE id='%1'").arg(i->id());
QString sql = QString("DELETE FROM nodes WHERE mac='%1'").arg(i->uniqueId());
sql.append(QString("; DELETE FROM devices WHERE mac = '%1'").arg(generateUniqueId(i->address().ext(), 0, 0)));

errmsg = NULL;
rc = sqlite3_exec(db, sql.toUtf8().constData(), NULL, NULL, &errmsg);
Expand All @@ -4904,9 +4911,6 @@ void DeRestPluginPrivate::saveDb()

continue;
}
*/

QString lightState((i->state() == LightNode::StateDeleted ? "deleted" : "normal"));

std::vector<GroupInfo>::const_iterator gi = i->groups().begin();
std::vector<GroupInfo>::const_iterator gend = i->groups().end();
Expand All @@ -4920,6 +4924,7 @@ void DeRestPluginPrivate::saveDb()
}
}

const QString lightState = "normal";
QString ritems = i->resourceItemsToJson();
QString sql = QString(QLatin1String("REPLACE INTO nodes (id, state, mac, name, groups, endpoint, modelid, manufacturername, swbuildid, ritems) VALUES ('%1', '%2', '%3', '%4', '%5', '%6', '%7', '%8', '%9', '%10')"))
.arg(i->id())
Expand All @@ -4933,11 +4938,6 @@ void DeRestPluginPrivate::saveDb()
.arg(i->swBuildId())
.arg(ritems);

if (i->state() == LightNode::StateDeleted)
{
sql.append(QString("; DELETE FROM devices WHERE mac = '%1'").arg(generateUniqueId(i->address().ext(), 0, 0)));
}

DBG_Printf(DBG_INFO_L2, "DB sql exec %s\n", qPrintable(sql));
errmsg = NULL;
rc = sqlite3_exec(db, sql.toUtf8().constData(), NULL, NULL, &errmsg);
Expand Down Expand Up @@ -5314,11 +5314,11 @@ void DeRestPluginPrivate::saveDb()

i->setNeedSaveDatabase(false);

/*
if (i->deletedState() == Sensor::StateDeleted)
{
// delete sensor from db (if exist)
QString sql = QString("DELETE FROM sensors WHERE sid='%1'").arg(sid);
QString sql = QString("DELETE FROM sensors WHERE uniqueid='%1'").arg(i->uniqueId());
sql.append(QString("; DELETE FROM devices WHERE mac = '%1'").arg(generateUniqueId(i->address().ext(), 0, 0)));

errmsg = NULL;
rc = sqlite3_exec(db, sql.toUtf8().constData(), NULL, NULL, &errmsg);
Expand All @@ -5334,11 +5334,11 @@ void DeRestPluginPrivate::saveDb()

continue;
}
*/

QString stateJSON = i->stateToString();
QString configJSON = i->configToString();
QString fingerPrintJSON = i->fingerPrint().toString();
QString deletedState((i->deletedState() == Sensor::StateDeleted ? "deleted" : "normal"));
const QString deletedState = "normal";

QString sql = QString(QLatin1String("REPLACE INTO sensors (sid, name, type, modelid, manufacturername, uniqueid, swversion, state, config, fingerprint, deletedState, mode) VALUES ('%1', '%2', '%3', '%4', '%5', '%6', '%7', '%8', '%9', '%10', '%11', '%12')"))
.arg(i->id())
Expand All @@ -5354,11 +5354,6 @@ void DeRestPluginPrivate::saveDb()
.arg(deletedState)
.arg(QString::number(i->mode()));

if (i->deletedState() == Sensor::StateDeleted)
{
sql.append(QString("; DELETE FROM devices WHERE mac = '%1'").arg(generateUniqueId(i->address().ext(), 0, 0)));
}

DBG_Printf(DBG_INFO_L2, "DB sql exec %s\n", qPrintable(sql));
errmsg = NULL;
rc = sqlite3_exec(db, sql.toUtf8().constData(), NULL, NULL, &errmsg);
Expand Down
2 changes: 2 additions & 0 deletions de_web.pro
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ SOURCES = air_quality.cpp \
de_web_plugin.cpp \
de_web_widget.cpp \
de_otau.cpp \
electrical_measurement.cpp \
event.cpp \
event_queue.cpp \
fan_control.cpp \
Expand Down Expand Up @@ -191,6 +192,7 @@ SOURCES = air_quality.cpp \
reset_device.cpp \
rest_userparameter.cpp \
utils/utils.cpp \
xiaomi.cpp \
zcl_tasks.cpp \
window_covering.cpp \
websocket_server.cpp \
Expand Down
Loading

0 comments on commit e78b27c

Please sign in to comment.