diff --git a/libnymea-zigbee/backends/nxp/zigbeenetworknxp.cpp b/libnymea-zigbee/backends/nxp/zigbeenetworknxp.cpp index 88625ac..270363f 100644 --- a/libnymea-zigbee/backends/nxp/zigbeenetworknxp.cpp +++ b/libnymea-zigbee/backends/nxp/zigbeenetworknxp.cpp @@ -571,7 +571,7 @@ void ZigbeeNetworkNxp::onNodeLeftIndication(const ZigbeeAddress &ieeeAddress, bo { qCDebug(dcZigbeeNetwork()) << "Received node left indication" << ieeeAddress.toString() << "rejoining:" << rejoining; if (!hasNode(ieeeAddress)) { - qCWarning(dcZigbeeNetwork()) << "Unknown node left the network" << ieeeAddress.toString(); + qCDebug(dcZigbeeNetwork()) << "Node left the network" << ieeeAddress.toString(); return; } diff --git a/libnymea-zigbee/zcl/closures/zigbeeclusterdoorlock.cpp b/libnymea-zigbee/zcl/closures/zigbeeclusterdoorlock.cpp index 07941de..b372a6e 100644 --- a/libnymea-zigbee/zcl/closures/zigbeeclusterdoorlock.cpp +++ b/libnymea-zigbee/zcl/closures/zigbeeclusterdoorlock.cpp @@ -113,13 +113,7 @@ ZigbeeClusterDoorLock::DoorState ZigbeeClusterDoorLock::doorState() const void ZigbeeClusterDoorLock::setAttribute(const ZigbeeClusterAttribute &attribute) { qCDebug(dcZigbeeCluster()) << "Update attribute" << m_node << m_endpoint << this << static_cast(attribute.id()) << attribute.dataType(); - if (hasAttribute(attribute.id())) { - m_attributes[attribute.id()] = attribute; - emit attributeChanged(attribute); - } else { - m_attributes.insert(attribute.id(), attribute); - emit attributeChanged(attribute); - } + updateOrAddAttribute(attribute); switch (attribute.id()) { case AttributeLockState: @@ -135,10 +129,22 @@ void ZigbeeClusterDoorLock::setAttribute(const ZigbeeClusterAttribute &attribute void ZigbeeClusterDoorLock::processDataIndication(ZigbeeClusterLibrary::Frame frame) { - //qCDebug(dcZigbeeCluster()) << "Processing cluster frame" << m_node << m_endpoint << this << frame; + qCDebug(dcZigbeeCluster()) << "Processing cluster frame" << m_node << m_endpoint << this << frame; // Increase the tsn for continuous id increasing on both sides m_transactionSequenceNumber = frame.header.transactionSequenceNumber; - qCWarning(dcZigbeeCluster()) << "Unhandled ZCL indication in" << m_node << m_endpoint << this << frame; + switch (m_direction) { + case Client: + // If the client cluster sends data to a server cluster (independent which), the command was executed on the device like button pressed + if (frame.header.frameControl.direction == ZigbeeClusterLibrary::DirectionClientToServer) { + // Read the payload which is + Command command = static_cast(frame.header.command); + qCDebug(dcZigbeeCluster()) << "Received" << command << "from" << m_node << m_endpoint << this; + } + break; + case Server: + qCWarning(dcZigbeeCluster()) << "Unhandled ZCL indication in" << m_node << m_endpoint << this << frame; + break; + } } diff --git a/libnymea-zigbee/zcl/general/zigbeeclusterbasic.cpp b/libnymea-zigbee/zcl/general/zigbeeclusterbasic.cpp index e69f233..76a47d5 100644 --- a/libnymea-zigbee/zcl/general/zigbeeclusterbasic.cpp +++ b/libnymea-zigbee/zcl/general/zigbeeclusterbasic.cpp @@ -39,11 +39,5 @@ ZigbeeClusterBasic::ZigbeeClusterBasic(ZigbeeNetwork *network, ZigbeeNode *node, void ZigbeeClusterBasic::setAttribute(const ZigbeeClusterAttribute &attribute) { qCDebug(dcZigbeeCluster()) << "Update attribute" << m_node << m_endpoint << this << static_cast(attribute.id()) << attribute.dataType(); - if (hasAttribute(attribute.id())) { - m_attributes[attribute.id()] = attribute; - emit attributeChanged(attribute); - } else { - m_attributes.insert(attribute.id(), attribute); - emit attributeChanged(attribute); - } + updateOrAddAttribute(attribute); } diff --git a/libnymea-zigbee/zcl/general/zigbeeclusteridentify.cpp b/libnymea-zigbee/zcl/general/zigbeeclusteridentify.cpp index 8eda969..34031c4 100644 --- a/libnymea-zigbee/zcl/general/zigbeeclusteridentify.cpp +++ b/libnymea-zigbee/zcl/general/zigbeeclusteridentify.cpp @@ -64,13 +64,7 @@ ZigbeeClusterReply *ZigbeeClusterIdentify::triggerEffect(ZigbeeClusterIdentify:: void ZigbeeClusterIdentify::setAttribute(const ZigbeeClusterAttribute &attribute) { qCDebug(dcZigbeeCluster()) << "Update attribute" << m_node << m_endpoint << this << static_cast(attribute.id()) << attribute.dataType(); - if (hasAttribute(attribute.id())) { - m_attributes[attribute.id()] = attribute; - emit attributeChanged(attribute); - } else { - m_attributes.insert(attribute.id(), attribute); - emit attributeChanged(attribute); - } + updateOrAddAttribute(attribute); } void ZigbeeClusterIdentify::processDataIndication(ZigbeeClusterLibrary::Frame frame) diff --git a/libnymea-zigbee/zcl/general/zigbeeclusterlevelcontrol.cpp b/libnymea-zigbee/zcl/general/zigbeeclusterlevelcontrol.cpp index 2b19434..526d745 100644 --- a/libnymea-zigbee/zcl/general/zigbeeclusterlevelcontrol.cpp +++ b/libnymea-zigbee/zcl/general/zigbeeclusterlevelcontrol.cpp @@ -102,24 +102,24 @@ ZigbeeClusterReply *ZigbeeClusterLevelControl::commandStopWithOnOff() return executeClusterCommand(ZigbeeClusterLevelControl::CommandStopWithOnOff); } +quint8 ZigbeeClusterLevelControl::currentLevel() const +{ + return m_currentLevel; +} + void ZigbeeClusterLevelControl::setAttribute(const ZigbeeClusterAttribute &attribute) { qCDebug(dcZigbeeCluster()) << "Update attribute" << m_node << m_endpoint << this << static_cast(attribute.id()) << attribute.dataType(); - if (hasAttribute(attribute.id())) { - m_attributes[attribute.id()] = attribute; - emit attributeChanged(attribute); - } else { - m_attributes.insert(attribute.id(), attribute); - emit attributeChanged(attribute); - } + updateOrAddAttribute(attribute); // Parse the information for convenience if (attribute.id() == AttributeCurrentLevel) { bool valueOk = false; quint8 value = attribute.dataType().toUInt8(&valueOk); if (valueOk) { - qCDebug(dcZigbeeCluster()) << "CurrentLevel state changed on" << m_node << m_endpoint << this << value; - emit currentLevelChanged(value); + m_currentLevel = value; + qCDebug(dcZigbeeCluster()) << "CurrentLevel state changed on" << m_node << m_endpoint << this << m_currentLevel; + emit currentLevelChanged(m_currentLevel); } else { qCWarning(dcZigbeeCluster()) << "Failed to parse attribute data" << m_node << m_endpoint << this << attribute; } diff --git a/libnymea-zigbee/zcl/general/zigbeeclusterlevelcontrol.h b/libnymea-zigbee/zcl/general/zigbeeclusterlevelcontrol.h index 83e2957..32459a7 100644 --- a/libnymea-zigbee/zcl/general/zigbeeclusterlevelcontrol.h +++ b/libnymea-zigbee/zcl/general/zigbeeclusterlevelcontrol.h @@ -94,7 +94,11 @@ public: ZigbeeClusterReply *commandStepWithOnOff(FadeMode fadeMode, quint8 stepSize = 0x01, quint16 transitionTime = 0xffff); ZigbeeClusterReply *commandStopWithOnOff(); + quint8 currentLevel() const; + private: + quint8 m_currentLevel = 0; + void setAttribute(const ZigbeeClusterAttribute &attribute) override; protected: diff --git a/libnymea-zigbee/zcl/general/zigbeeclusteronoff.cpp b/libnymea-zigbee/zcl/general/zigbeeclusteronoff.cpp index 3b8911f..d0e915f 100644 --- a/libnymea-zigbee/zcl/general/zigbeeclusteronoff.cpp +++ b/libnymea-zigbee/zcl/general/zigbeeclusteronoff.cpp @@ -76,24 +76,24 @@ ZigbeeClusterReply *ZigbeeClusterOnOff::commandOnWithTimedOff(bool acceptOnlyWhe return executeClusterCommand(ZigbeeClusterOnOff::CommandOnWithTimedOff, payload); } +bool ZigbeeClusterOnOff::power() const +{ + return m_power; +} + void ZigbeeClusterOnOff::setAttribute(const ZigbeeClusterAttribute &attribute) { qCDebug(dcZigbeeCluster()) << "Update attribute" << m_node << m_endpoint << this << static_cast(attribute.id()) << attribute.dataType(); - if (hasAttribute(attribute.id())) { - m_attributes[attribute.id()] = attribute; - emit attributeChanged(attribute); - } else { - m_attributes.insert(attribute.id(), attribute); - emit attributeChanged(attribute); - } + updateOrAddAttribute(attribute); // Parse the information for convenience if (attribute.id() == AttributeOnOff) { bool valueOk = false; bool value = attribute.dataType().toBool(&valueOk); if (valueOk) { - qCDebug(dcZigbeeCluster()) << "OnOff state changed on" << m_node << m_endpoint << this << value; - emit powerChanged(value); + m_power = value; + qCDebug(dcZigbeeCluster()) << "OnOff state changed on" << m_node << m_endpoint << this << m_power; + emit powerChanged(m_power); } else { qCWarning(dcZigbeeCluster()) << "Failed to parse attribute data" << m_node << m_endpoint << this << attribute; } diff --git a/libnymea-zigbee/zcl/general/zigbeeclusteronoff.h b/libnymea-zigbee/zcl/general/zigbeeclusteronoff.h index a3c6b09..dd35e1e 100644 --- a/libnymea-zigbee/zcl/general/zigbeeclusteronoff.h +++ b/libnymea-zigbee/zcl/general/zigbeeclusteronoff.h @@ -79,7 +79,11 @@ public: ZigbeeClusterReply *commandOnWithRecallGlobalScene(); ZigbeeClusterReply *commandOnWithTimedOff(bool acceptOnlyWhenOn, quint16 onTime, quint16 offWaitTime); + bool power() const; + private: + bool m_power = false; + void setAttribute(const ZigbeeClusterAttribute &attribute) override; protected: diff --git a/libnymea-zigbee/zcl/general/zigbeeclusterpowerconfiguration.cpp b/libnymea-zigbee/zcl/general/zigbeeclusterpowerconfiguration.cpp index 28e1f16..1544570 100644 --- a/libnymea-zigbee/zcl/general/zigbeeclusterpowerconfiguration.cpp +++ b/libnymea-zigbee/zcl/general/zigbeeclusterpowerconfiguration.cpp @@ -36,23 +36,23 @@ ZigbeeClusterPowerConfiguration::ZigbeeClusterPowerConfiguration(ZigbeeNetwork * } +double ZigbeeClusterPowerConfiguration::batteryPercentage() const +{ + return m_batteryPercentage; +} + void ZigbeeClusterPowerConfiguration::setAttribute(const ZigbeeClusterAttribute &attribute) { qCDebug(dcZigbeeCluster()) << "Update attribute" << m_node << m_endpoint << this << static_cast(attribute.id()) << attribute.dataType(); - if (hasAttribute(attribute.id())) { - m_attributes[attribute.id()] = attribute; - emit attributeChanged(attribute); - } else { - m_attributes.insert(attribute.id(), attribute); - emit attributeChanged(attribute); - } + updateOrAddAttribute(attribute); if (attribute.id() == AttributeBatteryPercentageRemaining) { bool valueOk = false; quint8 value = attribute.dataType().toUInt8(&valueOk); if (valueOk) { - qCDebug(dcZigbeeCluster()) << "PowerConfiguration attribute changed on" << m_node << m_endpoint << this << value; - emit batteryPercentageChanged(value / 2.0); + m_batteryPercentage = value / 2.0; + qCDebug(dcZigbeeCluster()) << "PowerConfiguration remaining battery percentage changed on" << m_node << m_endpoint << this << m_batteryPercentage << "%"; + emit batteryPercentageChanged(m_batteryPercentage); } else { qCWarning(dcZigbeeCluster()) << "Failed to parse attribute data" << m_node << m_endpoint << this << attribute; } diff --git a/libnymea-zigbee/zcl/general/zigbeeclusterpowerconfiguration.h b/libnymea-zigbee/zcl/general/zigbeeclusterpowerconfiguration.h index b08bc48..2d3e121 100644 --- a/libnymea-zigbee/zcl/general/zigbeeclusterpowerconfiguration.h +++ b/libnymea-zigbee/zcl/general/zigbeeclusterpowerconfiguration.h @@ -89,7 +89,11 @@ public: explicit ZigbeeClusterPowerConfiguration(ZigbeeNetwork *network, ZigbeeNode *node, ZigbeeNodeEndpoint *endpoint, Direction direction, QObject *parent = nullptr); + double batteryPercentage() const; + private: + double m_batteryPercentage = 0; + void setAttribute(const ZigbeeClusterAttribute &attribute) override; signals: diff --git a/libnymea-zigbee/zcl/lighting/zigbeeclustercolorcontrol.cpp b/libnymea-zigbee/zcl/lighting/zigbeeclustercolorcontrol.cpp index b5cd507..bfa49b7 100644 --- a/libnymea-zigbee/zcl/lighting/zigbeeclustercolorcontrol.cpp +++ b/libnymea-zigbee/zcl/lighting/zigbeeclustercolorcontrol.cpp @@ -216,14 +216,7 @@ ZigbeeClusterReply *ZigbeeClusterColorControl::commandStepColorTemperature(Zigbe void ZigbeeClusterColorControl::setAttribute(const ZigbeeClusterAttribute &attribute) { qCDebug(dcZigbeeCluster()) << "Attribute changed" << m_node << m_endpoint << this << static_cast(attribute.id()) << attribute.dataType(); - if (hasAttribute(attribute.id())) { - m_attributes[attribute.id()] = attribute; - emit attributeChanged(attribute); - } else { - m_attributes.insert(attribute.id(), attribute); - emit attributeChanged(attribute); - } - + updateOrAddAttribute(attribute); } void ZigbeeClusterColorControl::processDataIndication(ZigbeeClusterLibrary::Frame frame) diff --git a/libnymea-zigbee/zcl/measurement/zigbeeclusterilluminancemeasurment.cpp b/libnymea-zigbee/zcl/measurement/zigbeeclusterilluminancemeasurment.cpp index a7d61cd..c4bd5df 100644 --- a/libnymea-zigbee/zcl/measurement/zigbeeclusterilluminancemeasurment.cpp +++ b/libnymea-zigbee/zcl/measurement/zigbeeclusterilluminancemeasurment.cpp @@ -36,24 +36,24 @@ ZigbeeClusterIlluminanceMeasurment::ZigbeeClusterIlluminanceMeasurment(ZigbeeNet } +quint16 ZigbeeClusterIlluminanceMeasurment::illuminance() const +{ + return m_illuminance; +} + void ZigbeeClusterIlluminanceMeasurment::setAttribute(const ZigbeeClusterAttribute &attribute) { qCDebug(dcZigbeeCluster()) << "Update attribute" << m_node << m_endpoint << this << static_cast(attribute.id()) << attribute.dataType(); - if (hasAttribute(attribute.id())) { - m_attributes[attribute.id()] = attribute; - emit attributeChanged(attribute); - } else { - m_attributes.insert(attribute.id(), attribute); - emit attributeChanged(attribute); - } + updateOrAddAttribute(attribute); // Parse the information for convenience if (attribute.id() == AttributeMeasuredValue) { bool valueOk = false; quint16 value = attribute.dataType().toUInt16(&valueOk); if (valueOk) { - qCDebug(dcZigbeeCluster()) << "Illuminance changed on" << m_node << m_endpoint << this << value << "lux"; - emit illuminanceChanged(value); + m_illuminance = value; + qCDebug(dcZigbeeCluster()) << "Illuminance changed on" << m_node << m_endpoint << this << m_illuminance << "lux"; + emit illuminanceChanged(m_illuminance); } } } diff --git a/libnymea-zigbee/zcl/measurement/zigbeeclusterilluminancemeasurment.h b/libnymea-zigbee/zcl/measurement/zigbeeclusterilluminancemeasurment.h index 8d61e66..dbd27c2 100644 --- a/libnymea-zigbee/zcl/measurement/zigbeeclusterilluminancemeasurment.h +++ b/libnymea-zigbee/zcl/measurement/zigbeeclusterilluminancemeasurment.h @@ -63,7 +63,11 @@ public: explicit ZigbeeClusterIlluminanceMeasurment(ZigbeeNetwork *network, ZigbeeNode *node, ZigbeeNodeEndpoint *endpoint, Direction direction, QObject *parent = nullptr); + quint16 illuminance() const; + private: + quint16 m_illuminance = 0; + void setAttribute(const ZigbeeClusterAttribute &attribute) override; signals: diff --git a/libnymea-zigbee/zcl/measurement/zigbeeclusteroccupancysensing.cpp b/libnymea-zigbee/zcl/measurement/zigbeeclusteroccupancysensing.cpp index f99588c..3cf257d 100644 --- a/libnymea-zigbee/zcl/measurement/zigbeeclusteroccupancysensing.cpp +++ b/libnymea-zigbee/zcl/measurement/zigbeeclusteroccupancysensing.cpp @@ -36,24 +36,24 @@ ZigbeeClusterOccupancySensing::ZigbeeClusterOccupancySensing(ZigbeeNetwork *netw } +bool ZigbeeClusterOccupancySensing::occupied() const +{ + return m_occupied; +} + void ZigbeeClusterOccupancySensing::setAttribute(const ZigbeeClusterAttribute &attribute) { qCDebug(dcZigbeeCluster()) << "Update attribute" << m_node << m_endpoint << this << static_cast(attribute.id()) << attribute.dataType(); - if (hasAttribute(attribute.id())) { - m_attributes[attribute.id()] = attribute; - emit attributeChanged(attribute); - } else { - m_attributes.insert(attribute.id(), attribute); - emit attributeChanged(attribute); - } + updateOrAddAttribute(attribute); // Parse the information for convenience if (attribute.id() == AttributeOccupancy) { bool valueOk = false; bool value = attribute.dataType().toBool(&valueOk); if (valueOk) { - qCDebug(dcZigbeeCluster()) << "Occupancy changed on" << m_node << m_endpoint << this << value; - emit occupancyChanged(value); + m_occupied = value; + qCDebug(dcZigbeeCluster()) << "Occupancy changed on" << m_node << m_endpoint << this << m_occupied; + emit occupancyChanged(m_occupied); } } } diff --git a/libnymea-zigbee/zcl/measurement/zigbeeclusteroccupancysensing.h b/libnymea-zigbee/zcl/measurement/zigbeeclusteroccupancysensing.h index 1a89ae7..6c06fae 100644 --- a/libnymea-zigbee/zcl/measurement/zigbeeclusteroccupancysensing.h +++ b/libnymea-zigbee/zcl/measurement/zigbeeclusteroccupancysensing.h @@ -72,7 +72,11 @@ public: explicit ZigbeeClusterOccupancySensing(ZigbeeNetwork *network, ZigbeeNode *node, ZigbeeNodeEndpoint *endpoint, Direction direction, QObject *parent = nullptr); + bool occupied() const; + private: + bool m_occupied = false; + void setAttribute(const ZigbeeClusterAttribute &attribute) override; signals: diff --git a/libnymea-zigbee/zcl/measurement/zigbeeclusterpressuremeasurement.cpp b/libnymea-zigbee/zcl/measurement/zigbeeclusterpressuremeasurement.cpp index b0a5871..c052d54 100644 --- a/libnymea-zigbee/zcl/measurement/zigbeeclusterpressuremeasurement.cpp +++ b/libnymea-zigbee/zcl/measurement/zigbeeclusterpressuremeasurement.cpp @@ -36,33 +36,37 @@ ZigbeeClusterPressureMeasurement::ZigbeeClusterPressureMeasurement(ZigbeeNetwork } +double ZigbeeClusterPressureMeasurement::pressure() const +{ + return m_pressure; +} + +double ZigbeeClusterPressureMeasurement::pressureScaled() const +{ + return m_pressureScaled; +} + void ZigbeeClusterPressureMeasurement::setAttribute(const ZigbeeClusterAttribute &attribute) { qCDebug(dcZigbeeCluster()) << "Update attribute" << m_node << m_endpoint << this << static_cast(attribute.id()) << attribute.dataType(); - if (hasAttribute(attribute.id())) { - m_attributes[attribute.id()] = attribute; - emit attributeChanged(attribute); - } else { - m_attributes.insert(attribute.id(), attribute); - emit attributeChanged(attribute); - } + updateOrAddAttribute(attribute); // Parse the information for convinience if (attribute.id() == AttributeMeasuredValue) { bool valueOk = false; qint16 value = attribute.dataType().toInt16(&valueOk); if (valueOk) { - double pressure = value / 10.0; - qCDebug(dcZigbeeCluster()) << "Pressure changed on" << m_node << m_endpoint << this << pressure << "kPa"; - emit pressureChanged(pressure); + m_pressure = value / 10.0; + qCDebug(dcZigbeeCluster()) << "Pressure changed on" << m_node << m_endpoint << this << m_pressure << "kPa"; + emit pressureChanged(m_pressure); } } else if (attribute.id() == AttributeScaledValue) { bool valueOk = false; qint16 value = attribute.dataType().toInt16(&valueOk); if (valueOk) { - double pressureScaled = value / 10.0; - qCDebug(dcZigbeeCluster()) << "Pressure scaled changed on" << m_node << m_endpoint << this << pressureScaled << "Pa"; - emit pressureScaledChanged(pressureScaled); + m_pressureScaled = value / 10.0; + qCDebug(dcZigbeeCluster()) << "Pressure scaled changed on" << m_node << m_endpoint << this << m_pressureScaled << "Pa"; + emit pressureScaledChanged(m_pressureScaled); } } } diff --git a/libnymea-zigbee/zcl/measurement/zigbeeclusterpressuremeasurement.h b/libnymea-zigbee/zcl/measurement/zigbeeclusterpressuremeasurement.h index 9002a9e..910c21e 100644 --- a/libnymea-zigbee/zcl/measurement/zigbeeclusterpressuremeasurement.h +++ b/libnymea-zigbee/zcl/measurement/zigbeeclusterpressuremeasurement.h @@ -62,7 +62,12 @@ public: explicit ZigbeeClusterPressureMeasurement(ZigbeeNetwork *network, ZigbeeNode *node, ZigbeeNodeEndpoint *endpoint, Direction direction, QObject *parent = nullptr); + double pressure() const; + double pressureScaled() const; + private: + double m_pressure = 0; + double m_pressureScaled = 0; void setAttribute(const ZigbeeClusterAttribute &attribute) override; signals: diff --git a/libnymea-zigbee/zcl/measurement/zigbeeclusterrelativehumiditymeasurement.cpp b/libnymea-zigbee/zcl/measurement/zigbeeclusterrelativehumiditymeasurement.cpp index e6ff5a9..5b3701c 100644 --- a/libnymea-zigbee/zcl/measurement/zigbeeclusterrelativehumiditymeasurement.cpp +++ b/libnymea-zigbee/zcl/measurement/zigbeeclusterrelativehumiditymeasurement.cpp @@ -36,25 +36,24 @@ ZigbeeClusterRelativeHumidityMeasurement::ZigbeeClusterRelativeHumidityMeasureme } +double ZigbeeClusterRelativeHumidityMeasurement::humidity() const +{ + return m_humidity; +} + void ZigbeeClusterRelativeHumidityMeasurement::setAttribute(const ZigbeeClusterAttribute &attribute) { qCDebug(dcZigbeeCluster()) << "Update attribute" << m_node << m_endpoint << this << static_cast(attribute.id()) << attribute.dataType(); - if (hasAttribute(attribute.id())) { - m_attributes[attribute.id()] = attribute; - emit attributeChanged(attribute); - } else { - m_attributes.insert(attribute.id(), attribute); - emit attributeChanged(attribute); - } + updateOrAddAttribute(attribute); // Parse the information for convenience if (attribute.id() == AttributeMeasuredValue) { bool valueOk = false; quint16 value = attribute.dataType().toUInt16(&valueOk); if (valueOk) { - double humidity = value / 100.0; - qCDebug(dcZigbeeCluster()) << "Humidity changed on" << m_node << m_endpoint << this << humidity << "%"; - emit humidityChanged(humidity); + m_humidity = value / 100.0; + qCDebug(dcZigbeeCluster()) << "Humidity changed on" << m_node << m_endpoint << this << m_humidity << "%"; + emit humidityChanged(m_humidity); } } } diff --git a/libnymea-zigbee/zcl/measurement/zigbeeclusterrelativehumiditymeasurement.h b/libnymea-zigbee/zcl/measurement/zigbeeclusterrelativehumiditymeasurement.h index 86c1c3e..70e914f 100644 --- a/libnymea-zigbee/zcl/measurement/zigbeeclusterrelativehumiditymeasurement.h +++ b/libnymea-zigbee/zcl/measurement/zigbeeclusterrelativehumiditymeasurement.h @@ -56,7 +56,11 @@ public: explicit ZigbeeClusterRelativeHumidityMeasurement(ZigbeeNetwork *network, ZigbeeNode *node, ZigbeeNodeEndpoint *endpoint, Direction direction, QObject *parent = nullptr); + double humidity() const; + private: + double m_humidity = 0; + void setAttribute(const ZigbeeClusterAttribute &attribute) override; signals: diff --git a/libnymea-zigbee/zcl/measurement/zigbeeclustertemperaturemeasurement.cpp b/libnymea-zigbee/zcl/measurement/zigbeeclustertemperaturemeasurement.cpp index 0757bce..75e8d78 100644 --- a/libnymea-zigbee/zcl/measurement/zigbeeclustertemperaturemeasurement.cpp +++ b/libnymea-zigbee/zcl/measurement/zigbeeclustertemperaturemeasurement.cpp @@ -36,25 +36,24 @@ ZigbeeClusterTemperatureMeasurement::ZigbeeClusterTemperatureMeasurement(ZigbeeN } +double ZigbeeClusterTemperatureMeasurement::temperature() const +{ + return m_temperature; +} + void ZigbeeClusterTemperatureMeasurement::setAttribute(const ZigbeeClusterAttribute &attribute) { qCDebug(dcZigbeeCluster()) << "Update attribute" << m_node << m_endpoint << this << static_cast(attribute.id()) << attribute.dataType(); - if (hasAttribute(attribute.id())) { - m_attributes[attribute.id()] = attribute; - emit attributeChanged(attribute); - } else { - m_attributes.insert(attribute.id(), attribute); - emit attributeChanged(attribute); - } + updateOrAddAttribute(attribute); // Parse the information for convenience if (attribute.id() == AttributeMeasuredValue) { bool valueOk = false; qint16 value = attribute.dataType().toInt16(&valueOk); if (valueOk) { - double temperature = value / 100.0; - qCDebug(dcZigbeeCluster()) << "Temperature changed on" << m_node << m_endpoint << this << temperature << "°C"; - emit temperatureChanged(temperature); + m_temperature = value / 100.0; + qCDebug(dcZigbeeCluster()) << "Temperature changed on" << m_node << m_endpoint << this << m_temperature << "°C"; + emit temperatureChanged(m_temperature); } } } diff --git a/libnymea-zigbee/zcl/measurement/zigbeeclustertemperaturemeasurement.h b/libnymea-zigbee/zcl/measurement/zigbeeclustertemperaturemeasurement.h index 5f124f3..803b59f 100644 --- a/libnymea-zigbee/zcl/measurement/zigbeeclustertemperaturemeasurement.h +++ b/libnymea-zigbee/zcl/measurement/zigbeeclustertemperaturemeasurement.h @@ -56,7 +56,11 @@ public: explicit ZigbeeClusterTemperatureMeasurement(ZigbeeNetwork *network, ZigbeeNode *node, ZigbeeNodeEndpoint *endpoint, Direction direction, QObject *parent = nullptr); + double temperature() const; + private: + double m_temperature = 0; + void setAttribute(const ZigbeeClusterAttribute &attribute) override; signals: diff --git a/libnymea-zigbee/zcl/ota/zigbeeclusterota.cpp b/libnymea-zigbee/zcl/ota/zigbeeclusterota.cpp index 9ac6592..58bb430 100644 --- a/libnymea-zigbee/zcl/ota/zigbeeclusterota.cpp +++ b/libnymea-zigbee/zcl/ota/zigbeeclusterota.cpp @@ -42,13 +42,7 @@ ZigbeeClusterOta::ZigbeeClusterOta(ZigbeeNetwork *network, ZigbeeNode *node, Zig void ZigbeeClusterOta::setAttribute(const ZigbeeClusterAttribute &attribute) { qCDebug(dcZigbeeCluster()) << "Update attribute" << m_node << m_endpoint << this << static_cast(attribute.id()) << attribute.dataType(); - if (hasAttribute(attribute.id())) { - m_attributes[attribute.id()] = attribute; - emit attributeChanged(attribute); - } else { - m_attributes.insert(attribute.id(), attribute); - emit attributeChanged(attribute); - } + updateOrAddAttribute(attribute); } ZigbeeClusterOta::FileVersion ZigbeeClusterOta::parseFileVersion(quint32 fileVersionValue) diff --git a/libnymea-zigbee/zcl/security/zigbeeclusteriaszone.cpp b/libnymea-zigbee/zcl/security/zigbeeclusteriaszone.cpp index 8914424..45c4789 100644 --- a/libnymea-zigbee/zcl/security/zigbeeclusteriaszone.cpp +++ b/libnymea-zigbee/zcl/security/zigbeeclusteriaszone.cpp @@ -42,13 +42,7 @@ ZigbeeClusterIasZone::ZigbeeClusterIasZone(ZigbeeNetwork *network, ZigbeeNode *n void ZigbeeClusterIasZone::setAttribute(const ZigbeeClusterAttribute &attribute) { qCDebug(dcZigbeeCluster()) << "Update attribute" << m_node << m_endpoint << this << static_cast(attribute.id()) << attribute.dataType(); - if (hasAttribute(attribute.id())) { - m_attributes[attribute.id()] = attribute; - emit attributeChanged(attribute); - } else { - m_attributes.insert(attribute.id(), attribute); - emit attributeChanged(attribute); - } + updateOrAddAttribute(attribute); } void ZigbeeClusterIasZone::processDataIndication(ZigbeeClusterLibrary::Frame frame) diff --git a/libnymea-zigbee/zcl/security/zigbeeclusteriaszone.h b/libnymea-zigbee/zcl/security/zigbeeclusteriaszone.h index 9a38663..c43c717 100644 --- a/libnymea-zigbee/zcl/security/zigbeeclusteriaszone.h +++ b/libnymea-zigbee/zcl/security/zigbeeclusteriaszone.h @@ -97,7 +97,7 @@ public: ZoneStatusTest = 0x0100, ZoneStatusBatteryDefect = 0x0200 }; - Q_ENUM(ZoneStatus) + Q_FLAG(ZoneStatus) Q_DECLARE_FLAGS(ZoneStatusFlags, ZoneStatus) enum EnrollResponseCode { @@ -137,6 +137,4 @@ signals: }; -Q_DECLARE_OPERATORS_FOR_FLAGS(ZigbeeClusterIasZone::ZoneStatusFlags) - #endif // ZIGBEECLUSTERIASZONE_H diff --git a/libnymea-zigbee/zcl/zigbeecluster.cpp b/libnymea-zigbee/zcl/zigbeecluster.cpp index 411a519..4f69126 100644 --- a/libnymea-zigbee/zcl/zigbeecluster.cpp +++ b/libnymea-zigbee/zcl/zigbeecluster.cpp @@ -93,13 +93,7 @@ ZigbeeClusterAttribute ZigbeeCluster::attribute(quint16 attributeId) void ZigbeeCluster::setAttribute(const ZigbeeClusterAttribute &attribute) { qCDebug(dcZigbeeCluster()) << "Update attribute" << m_node << m_endpoint << this << attribute; - if (hasAttribute(attribute.id())) { - m_attributes[attribute.id()] = attribute; - emit attributeChanged(attribute); - } else { - m_attributes.insert(attribute.id(), attribute); - emit attributeChanged(attribute); - } + updateOrAddAttribute(attribute); } ZigbeeClusterReply *ZigbeeCluster::readAttributes(QList attributes) @@ -363,6 +357,17 @@ void ZigbeeCluster::processDataIndication(ZigbeeClusterLibrary::Frame frame) qCWarning(dcZigbeeCluster()) << "Unhandled ZCL indication in" << m_node << m_endpoint << this << frame; } +void ZigbeeCluster::updateOrAddAttribute(const ZigbeeClusterAttribute &attribute) +{ + if (hasAttribute(attribute.id())) { + m_attributes[attribute.id()] = attribute; + emit attributeChanged(attribute); + } else { + m_attributes.insert(attribute.id(), attribute); + emit attributeChanged(attribute); + } +} + void ZigbeeCluster::processApsDataIndication(const QByteArray &asdu, const ZigbeeClusterLibrary::Frame &frame) { // Check if this indication is for a pending reply diff --git a/libnymea-zigbee/zcl/zigbeecluster.h b/libnymea-zigbee/zcl/zigbeecluster.h index b96cbc8..4c7e692 100644 --- a/libnymea-zigbee/zcl/zigbeecluster.h +++ b/libnymea-zigbee/zcl/zigbeecluster.h @@ -114,7 +114,6 @@ protected: // Global commands ZigbeeClusterReply *executeGlobalCommand(quint8 command, const QByteArray &payload = QByteArray()); - // Cluster specific ZigbeeClusterReply *createClusterReply(const ZigbeeNetworkRequest &request, ZigbeeClusterLibrary::Frame frame); ZigbeeClusterReply *executeClusterCommand(quint8 command, const QByteArray &payload = QByteArray()); @@ -126,6 +125,8 @@ protected: virtual void processDataIndication(ZigbeeClusterLibrary::Frame frame); + void updateOrAddAttribute(const ZigbeeClusterAttribute &attribute); + private: virtual void setAttribute(const ZigbeeClusterAttribute &attribute); diff --git a/libnymea-zigbee/zigbeenode.cpp b/libnymea-zigbee/zigbeenode.cpp index 6be8641..2677833 100644 --- a/libnymea-zigbee/zigbeenode.cpp +++ b/libnymea-zigbee/zigbeenode.cpp @@ -628,6 +628,6 @@ QDebug operator<<(QDebug debug, ZigbeeNode *node) { debug.nospace().noquote() << "ZigbeeNode(" << ZigbeeUtils::convertUint16ToHexString(node->shortAddress()); debug.nospace().noquote() << ", " << node->extendedAddress().toString(); - debug.nospace().noquote() << ")"; - return debug.space(); + debug.nospace().noquote() << ") "; + return debug; } diff --git a/libnymea-zigbee/zigbeenodeendpoint.cpp b/libnymea-zigbee/zigbeenodeendpoint.cpp index 4b2b39d..f09491f 100644 --- a/libnymea-zigbee/zigbeenodeendpoint.cpp +++ b/libnymea-zigbee/zigbeenodeendpoint.cpp @@ -285,6 +285,6 @@ QDebug operator<<(QDebug debug, ZigbeeNodeEndpoint *endpoint) debug.nospace().noquote() << ", " << static_cast(endpoint->deviceId()); } - debug.nospace().noquote() << ")"; - return debug.space(); + debug.nospace().noquote() << ") "; + return debug; }