From e7d533b9e8849bc7e5dcd9deb60d918ebcc8e955 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 15 Oct 2021 16:09:24 +0200 Subject: [PATCH] Add support for IAS Zone enrollment --- .../zcl/security/zigbeeclusteriaszone.cpp | 35 +++++++++++++++++++ .../zcl/security/zigbeeclusteriaszone.h | 6 ++++ libnymea-zigbee/zcl/zigbeecluster.cpp | 2 +- libnymea-zigbee/zigbee.h | 8 ++--- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/libnymea-zigbee/zcl/security/zigbeeclusteriaszone.cpp b/libnymea-zigbee/zcl/security/zigbeeclusteriaszone.cpp index ebc9619..db3e2c5 100644 --- a/libnymea-zigbee/zcl/security/zigbeeclusteriaszone.cpp +++ b/libnymea-zigbee/zcl/security/zigbeeclusteriaszone.cpp @@ -54,6 +54,41 @@ ZigbeeClusterIasZone::ZoneStatusFlags ZigbeeClusterIasZone::zoneStatus() const return m_zoneStatus; } +ZigbeeClusterReply *ZigbeeClusterIasZone::sendZoneEnrollRequest(ZigbeeClusterIasZone::ZoneType zoneType, quint16 manufacturerCode) +{ + QByteArray payload; + QDataStream stream(&payload, QIODevice::WriteOnly); + stream.setByteOrder(QDataStream::LittleEndian); + stream << static_cast(zoneType); + stream << manufacturerCode; + ZigbeeClusterReply *reply = executeClusterCommand(ServerCommandZoneEnrollRequest, payload); + return reply; +} + +ZigbeeClusterReply* ZigbeeClusterIasZone::sendZoneEnrollResponse(quint8 zoneId, EnrollResponseCode code) +{ + QByteArray payload; + QDataStream stream(&payload, QIODevice::WriteOnly); + stream.setByteOrder(QDataStream::LittleEndian); + stream << static_cast(code); + stream << zoneId; + ZigbeeClusterReply *reply = executeClusterCommand(ClientCommandEnrollResponse, payload); + return reply; +} + +ZigbeeClusterReply *ZigbeeClusterIasZone::sendZoneStatusChangeNotification(ZigbeeClusterIasZone::ZoneStatus status, quint8 zoneId, quint16 delay) +{ + QByteArray payload; + QDataStream stream(&payload, QIODevice::WriteOnly); + stream.setByteOrder(QDataStream::LittleEndian); + stream << static_cast(status); + stream << static_cast(0); // extended status, reserved for future use + stream << zoneId; + stream << delay; + ZigbeeClusterReply *reply = executeClusterCommand(ClientCommandEnrollResponse, payload); + return reply; +} + void ZigbeeClusterIasZone::setAttribute(const ZigbeeClusterAttribute &attribute) { qCDebug(dcZigbeeCluster()) << "Update attribute" << m_node << m_endpoint << this << static_cast(attribute.id()) << attribute.dataType(); diff --git a/libnymea-zigbee/zcl/security/zigbeeclusteriaszone.h b/libnymea-zigbee/zcl/security/zigbeeclusteriaszone.h index c9a1a5d..3f0762e 100644 --- a/libnymea-zigbee/zcl/security/zigbeeclusteriaszone.h +++ b/libnymea-zigbee/zcl/security/zigbeeclusteriaszone.h @@ -127,6 +127,12 @@ public: ZoneType zoneType() const; ZoneStatusFlags zoneStatus() const; + // Request a Zone enrollment from the client (Server to client) + ZigbeeClusterReply *sendZoneEnrollRequest(ZigbeeClusterIasZone::ZoneType zoneType, quint16 manufacturerCode); + // Enroll a Zone on the server (Client to server) + ZigbeeClusterReply *sendZoneEnrollResponse(quint8 zoneId, ZigbeeClusterIasZone::EnrollResponseCode code = EnrollResponseCodeSuccess); + // Inform the client of Zone status changes (Server to client) + ZigbeeClusterReply *sendZoneStatusChangeNotification(ZoneStatus status, quint8 zoneId, quint16 delay = 0); private: ZoneState m_zoneState = ZoneStateNotEnrolled; ZoneType m_zoneType = ZoneTypeInvalidZone; diff --git a/libnymea-zigbee/zcl/zigbeecluster.cpp b/libnymea-zigbee/zcl/zigbeecluster.cpp index 54c4431..6debac5 100644 --- a/libnymea-zigbee/zcl/zigbeecluster.cpp +++ b/libnymea-zigbee/zcl/zigbeecluster.cpp @@ -489,7 +489,7 @@ QDebug operator<<(QDebug debug, ZigbeeCluster *cluster) << cluster->clusterName() << ", "; switch (cluster->direction()) { case ZigbeeCluster::Server: - debug.nospace().noquote() << "Servers)"; + debug.nospace().noquote() << "Server)"; break; case ZigbeeCluster::Client: debug.nospace().noquote() << "Client)"; diff --git a/libnymea-zigbee/zigbee.h b/libnymea-zigbee/zigbee.h index c904184..f800ece 100644 --- a/libnymea-zigbee/zigbee.h +++ b/libnymea-zigbee/zigbee.h @@ -162,10 +162,10 @@ public: HomeAutomationDeviceFlowSensor = 0x0306, // Intruder Alarm System (IAS) devices - HomeAutomationDeviceIsaControlEquipment = 0x0400, // CIE - HomeAutomationDeviceIsaAncillaryControlEquipment = 0x0401, // ACE - HomeAutomationDeviceIsaZone = 0x0402, - HomeAutomationDeviceIsaWarningDevice = 0x0403 // WD + HomeAutomationDeviceIasControlEquipment = 0x0400, // CIE + HomeAutomationDeviceIasAncillaryControlEquipment = 0x0401, // ACE + HomeAutomationDeviceIasZone = 0x0402, + HomeAutomationDeviceIasWarningDevice = 0x0403 // WD }; Q_ENUM(HomeAutomationDevice)