From 945c1f626088a292262d827ad98f3432506e988d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F=20=D0=A2=D0=B8=D1=82=D0=BE=D0=B2?= Date: Fri, 14 Jun 2024 09:02:34 +0300 Subject: [PATCH] clean up --- actions/tuya.cpp | 11 +++-------- actions/tuya.h | 2 +- controller.cpp | 5 +++++ controller.h | 2 +- deploy/data/usr/share/homed-zigbee/tuya.json | 14 ++++++++++++-- properties/tuya.cpp | 3 +-- 6 files changed, 23 insertions(+), 14 deletions(-) diff --git a/actions/tuya.cpp b/actions/tuya.cpp index e34671f9..a4546bd3 100644 --- a/actions/tuya.cpp +++ b/actions/tuya.cpp @@ -245,18 +245,13 @@ QByteArray ActionsTUYA::ChildLock::request(const QString &, const QVariant &data QByteArray ActionsTUYA::IRCode::request(const QString &, const QVariant &data) { - QJsonObject json = {{"delay", 300}, {"key1", QJsonObject {{"freq", 38000}, {"key_code", data.toString()}, {"num", 1}, {"type", 1}}}, {"key_num", 1}}; - QByteArray message = QJsonDocument(json).toJson(QJsonDocument::Compact); - quint32 length = message.length(); - + QByteArray message = QJsonDocument(QJsonObject {{"delay", 300}, {"key1", QJsonObject {{"freq", 38000}, {"key_code", data.toString()}, {"num", 1}, {"type", 1}}}, {"key_num", 1}}).toJson(QJsonDocument::Compact); + quint32 length = qToLittleEndian (message.length()); meta().insert("message", message); - length = qToLittleEndian(length); - return zclHeader(FC_CLUSTER_SPECIFIC, m_transactionId++, 0x00).append(2, 0x00).append(reinterpret_cast (&length), sizeof(length)).append(QByteArray::fromHex("0000000004e001020000")); } QByteArray ActionsTUYA::IRLearn::request(const QString &, const QVariant &data) { - QJsonObject json = {{"study", 0}}; - return !data.toBool() ? QByteArray() : zclHeader(FC_CLUSTER_SPECIFIC, m_transactionId++, 0x00).append(QJsonDocument(json).toJson(QJsonDocument::Compact)); + return zclHeader(FC_CLUSTER_SPECIFIC, m_transactionId++, 0x00).append(QJsonDocument(QJsonObject {{"study", data.toBool() ? 0 : 1}}).toJson(QJsonDocument::Compact)); } diff --git a/actions/tuya.h b/actions/tuya.h index 204fb2c5..a9aa82d8 100644 --- a/actions/tuya.h +++ b/actions/tuya.h @@ -115,7 +115,7 @@ namespace ActionsTUYA public: - IRLearn(void) : ActionObject("irLearn", CLUSTER_TUYA_IR_CONTROL, 0x0000) {} + IRLearn(void) : ActionObject("learn", CLUSTER_TUYA_IR_CONTROL, 0x0000) {} QByteArray request(const QString &name, const QVariant &data) override; }; diff --git a/controller.cpp b/controller.cpp index 5a7291b4..1a30cac0 100644 --- a/controller.cpp +++ b/controller.cpp @@ -38,7 +38,12 @@ void Controller::publishExposes(DeviceObject *device, bool remove) void Controller::serviceOnline(void) { for (auto it = m_zigbee->devices()->begin(); it != m_zigbee->devices()->end(); it++) + { + if (it.value()->removed()) + continue; + publishExposes(it.value().data()); + } if (m_haEnabled) mqttPublishDiscovery("ZigBee", SERVICE_VERSION, m_haPrefix, true); diff --git a/controller.h b/controller.h index 29894090..7be0e357 100644 --- a/controller.h +++ b/controller.h @@ -1,7 +1,7 @@ #ifndef CONTROLLER_H #define CONTROLLER_H -#define SERVICE_VERSION "3.7.4-8" +#define SERVICE_VERSION "3.7.5" #define UPDATE_AVAILABILITY_INTERVAL 5000 #define UPDATE_PROPERTIES_DELAY 1000 diff --git a/deploy/data/usr/share/homed-zigbee/tuya.json b/deploy/data/usr/share/homed-zigbee/tuya.json index d877693b..7faadd5e 100644 --- a/deploy/data/usr/share/homed-zigbee/tuya.json +++ b/deploy/data/usr/share/homed-zigbee/tuya.json @@ -1351,9 +1351,19 @@ }, { "description": "TUYA TS1201 IR Remote Control", - "modelNames": ["_TZ3290_7v1k4vufotpowp9z", "_TZ3290_rlkmy85q4pzoxobl"], + "modelNames": ["_TZ3290_7v1k4vufotpowp9z", "_TZ3290_acv1iuslxi3shaaj", "_TZ3290_gnl5a6a5xvql7c2a", "_TZ3290_rlkmy85q4pzoxobl"], "properties": ["tuyaIRCode"], - "actions": ["tuyaIRCode", "tuyaIRLearn"] + "actions": ["tuyaIRCode", "tuyaIRLearn"], + "exposes": ["irCode"] + }, + { + "description": "TUYA TS1201 Wireless IR Remote Control", + "modelNames": ["_TZ3290_j37rooaxrcdcqo5n", "_TZ3290_ot6ewjvmejq5ekhl", "_TZ3290_xjpbcxn92aaxvmlz"], + "properties": ["batteryPercentage", "tuyaIRCode"], + "actions": ["tuyaIRCode", "tuyaIRLearn"], + "bindings": ["battery"], + "reportings": ["batteryPercentage"], + "exposes": ["irCode", "battery"] }, { "description": "MIBOXER FUT089Z 8-Group Remote Control", diff --git a/properties/tuya.cpp b/properties/tuya.cpp index ebb4e51a..c18c09d0 100644 --- a/properties/tuya.cpp +++ b/properties/tuya.cpp @@ -377,8 +377,7 @@ void PropertiesTUYA::IRCode::parseCommand(quint16, quint8 commandId, const QByte case 0x05: { - QJsonObject json = {{"study", 1}}; - m_queue.enqueue({CLUSTER_TUYA_IR_CONTROL, zclHeader(FC_CLUSTER_SPECIFIC, m_transactionId, 0x00).append(QJsonDocument(json).toJson(QJsonDocument::Compact))}); + m_queue.enqueue({CLUSTER_TUYA_IR_CONTROL, zclHeader(FC_CLUSTER_SPECIFIC, m_transactionId, 0x00).append(QJsonDocument(QJsonObject {{"study", 1}}).toJson(QJsonDocument::Compact))}); m_value = m_buffer.toBase64(); break; }