Add occupancy and illuminance measument clusters

pull/7/head
Simon Stürz 2020-05-29 17:46:56 +02:00
parent c565a25be2
commit 67c07f674c
9 changed files with 289 additions and 3 deletions

View File

@ -10,6 +10,8 @@ SOURCES += \
backends/deconz/zigbeenetworkdeconz.cpp \
zcl/general/zigbeeclusteridentify.cpp \
zcl/general/zigbeeclusteronoff.cpp \
zcl/measurement/zigbeeclusterilluminancemeasurment.cpp \
zcl/measurement/zigbeeclusteroccupancysensing.cpp \
zcl/measurement/zigbeeclusterrelativehumiditymeasurement.cpp \
zcl/measurement/zigbeeclustertemperaturemeasurement.cpp \
zcl/security/zigbeeclusteriaszone.cpp \
@ -56,6 +58,8 @@ HEADERS += \
backends/deconz/zigbeenetworkdeconz.h \
zcl/general/zigbeeclusteridentify.h \
zcl/general/zigbeeclusteronoff.h \
zcl/measurement/zigbeeclusterilluminancemeasurment.h \
zcl/measurement/zigbeeclusteroccupancysensing.h \
zcl/measurement/zigbeeclusterrelativehumiditymeasurement.h \
zcl/measurement/zigbeeclustertemperaturemeasurement.h \
zcl/security/zigbeeclusteriaszone.h \

View File

@ -0,0 +1,59 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea-zigbee.
* This project including source code and documentation is protected by copyright law, and
* remains the property of nymea GmbH. All rights, including reproduction, publication,
* editing and translation, are reserved. The use of this project is subject to the terms of a
* license agreement to be concluded with nymea GmbH in accordance with the terms
* of use of nymea GmbH, available under https://nymea.io/license
*
* GNU Lesser General Public License Usage
* Alternatively, this project may be redistributed and/or modified under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation; version 3.
* this project is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this project.
* If not, see <https://www.gnu.org/licenses/>.
*
* For any further details and any questions please contact us under contact@nymea.io
* or see our FAQ/Licensing Information on https://nymea.io/license/faq
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "zigbeeclusterilluminancemeasurment.h"
#include "zigbeenetworkreply.h"
#include "loggingcategory.h"
#include "zigbeenetwork.h"
ZigbeeClusterIlluminanceMeasurment::ZigbeeClusterIlluminanceMeasurment(ZigbeeNetwork *network, ZigbeeNode *node, ZigbeeNodeEndpoint *endpoint, Direction direction, QObject *parent) :
ZigbeeCluster(network, node, endpoint, Zigbee::ClusterIdIlluminanceMeasurement, direction, parent)
{
}
void ZigbeeClusterIlluminanceMeasurment::setAttribute(const ZigbeeClusterAttribute &attribute)
{
qCDebug(dcZigbeeCluster()) << "Update attribute" << m_node << m_endpoint << this << static_cast<Attribute>(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);
}
// Parse the information for convinience
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);
}
}
}

View File

@ -0,0 +1,75 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea-zigbee.
* This project including source code and documentation is protected by copyright law, and
* remains the property of nymea GmbH. All rights, including reproduction, publication,
* editing and translation, are reserved. The use of this project is subject to the terms of a
* license agreement to be concluded with nymea GmbH in accordance with the terms
* of use of nymea GmbH, available under https://nymea.io/license
*
* GNU Lesser General Public License Usage
* Alternatively, this project may be redistributed and/or modified under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation; version 3.
* this project is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this project.
* If not, see <https://www.gnu.org/licenses/>.
*
* For any further details and any questions please contact us under contact@nymea.io
* or see our FAQ/Licensing Information on https://nymea.io/license/faq
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef ZIGBEECLUSTERILLUMINANCEMEASURMENT_H
#define ZIGBEECLUSTERILLUMINANCEMEASURMENT_H
#include <QObject>
#include "zcl/zigbeecluster.h"
#include "zcl/zigbeeclusterreply.h"
class ZigbeeNode;
class ZigbeeNetwork;
class ZigbeeNodeEndpoint;
class ZigbeeNetworkReply;
class ZigbeeClusterIlluminanceMeasurment : public ZigbeeCluster
{
Q_OBJECT
friend class ZigbeeNode;
friend class ZigbeeNetwork;
public:
enum Attribute {
AttributeMeasuredValue = 0x0000,
AttributeMinMeasuredValue = 0x0001,
AttributeMaxMeasuredValue = 0x0002,
AttributeTolerance = 0x0003,
AttributeLightSensorType = 0x0004
};
Q_ENUM(Attribute)
enum LightSensorType {
LightSensorTypePhotodiode = 0x00,
LightSensorTypeCMOS = 0x01,
LightSensorTypeUnknown = 0xff
};
Q_ENUM(LightSensorType)
explicit ZigbeeClusterIlluminanceMeasurment(ZigbeeNetwork *network, ZigbeeNode *node, ZigbeeNodeEndpoint *endpoint, Direction direction, QObject *parent = nullptr);
private:
void setAttribute(const ZigbeeClusterAttribute &attribute) override;
signals:
void illuminanceChanged(quint16 illuminance);
};
#endif // ZIGBEECLUSTERILLUMINANCEMEASURMENT_H

View File

@ -0,0 +1,59 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea-zigbee.
* This project including source code and documentation is protected by copyright law, and
* remains the property of nymea GmbH. All rights, including reproduction, publication,
* editing and translation, are reserved. The use of this project is subject to the terms of a
* license agreement to be concluded with nymea GmbH in accordance with the terms
* of use of nymea GmbH, available under https://nymea.io/license
*
* GNU Lesser General Public License Usage
* Alternatively, this project may be redistributed and/or modified under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation; version 3.
* this project is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this project.
* If not, see <https://www.gnu.org/licenses/>.
*
* For any further details and any questions please contact us under contact@nymea.io
* or see our FAQ/Licensing Information on https://nymea.io/license/faq
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "zigbeeclusteroccupancysensing.h"
#include "zigbeenetworkreply.h"
#include "loggingcategory.h"
#include "zigbeenetwork.h"
ZigbeeClusterOccupancySensing::ZigbeeClusterOccupancySensing(ZigbeeNetwork *network, ZigbeeNode *node, ZigbeeNodeEndpoint *endpoint, Direction direction, QObject *parent) :
ZigbeeCluster(network, node, endpoint, Zigbee::ClusterIdOccupancySensing, direction, parent)
{
}
void ZigbeeClusterOccupancySensing::setAttribute(const ZigbeeClusterAttribute &attribute)
{
qCDebug(dcZigbeeCluster()) << "Update attribute" << m_node << m_endpoint << this << static_cast<Attribute>(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);
}
// Parse the information for convinience
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);
}
}
}

View File

@ -0,0 +1,81 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea-zigbee.
* This project including source code and documentation is protected by copyright law, and
* remains the property of nymea GmbH. All rights, including reproduction, publication,
* editing and translation, are reserved. The use of this project is subject to the terms of a
* license agreement to be concluded with nymea GmbH in accordance with the terms
* of use of nymea GmbH, available under https://nymea.io/license
*
* GNU Lesser General Public License Usage
* Alternatively, this project may be redistributed and/or modified under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation; version 3.
* this project is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this project.
* If not, see <https://www.gnu.org/licenses/>.
*
* For any further details and any questions please contact us under contact@nymea.io
* or see our FAQ/Licensing Information on https://nymea.io/license/faq
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef ZIGBEECLUSTEROCCUPANCYSENSING_H
#define ZIGBEECLUSTEROCCUPANCYSENSING_H
#include <QObject>
#include "zcl/zigbeecluster.h"
#include "zcl/zigbeeclusterreply.h"
class ZigbeeNode;
class ZigbeeNetwork;
class ZigbeeNodeEndpoint;
class ZigbeeNetworkReply;
class ZigbeeClusterOccupancySensing : public ZigbeeCluster
{
Q_OBJECT
friend class ZigbeeNode;
friend class ZigbeeNetwork;
public:
enum Attribute {
// Occupancy sensor information set
AttributeOccupancy = 0x0000,
AttributeOccupancySensorType = 0x0001,
// PRI configuration set
AttributePirOccupiedToUnoccupiedDelay = 0x0010,
AttributePirUnoccupiedToOccupiedDelay = 0x0011,
AttributePirUnoccupiedToOccupiedThreshold = 0x0012,
// Ultrasonic configuration set
AttributeUltrasonicOccupiedToUnoccupiedDelay = 0x0020,
AttributeUltrasonicUnoccupiedToOccupiedDelay = 0x0021,
AttributeUltrasonicUnoccupiedToOccupiedThreshold = 0x0022
};
Q_ENUM(Attribute)
enum OccupancySensorType {
OccupancySensorTypePir = 0x00,
OccupancySensorTypeUltrasonic = 0x01,
OccupancySensorTypePirAndUltrasonic = 0x02
};
Q_ENUM(OccupancySensorType)
explicit ZigbeeClusterOccupancySensing(ZigbeeNetwork *network, ZigbeeNode *node, ZigbeeNodeEndpoint *endpoint, Direction direction, QObject *parent = nullptr);
private:
void setAttribute(const ZigbeeClusterAttribute &attribute) override;
signals:
void occupancyChanged(bool occupied);
};
#endif // ZIGBEECLUSTEROCCUPANCYSENSING_H

View File

@ -125,7 +125,7 @@ public:
ClusterIdBallastConfiguration = 0x0301,
// Sensing
ClusterIdMeasurementIlluminance = 0x0400,
ClusterIdIlluminanceMeasurement = 0x0400,
ClusterIdIlluminanceLevelSensing = 0x0401,
ClusterIdTemperatureMeasurement = 0x0402,
ClusterIdPressureMeasurement = 0x0403,

View File

@ -304,7 +304,7 @@ ZigbeeDataType::ZigbeeDataType(const QString &value, Zigbee::DataType dataType)
quint8 ZigbeeDataType::toUInt8(bool *ok) const
{
if (ok) *ok = true;
if (m_data.count() != 1 || m_dataType != Zigbee::Uint8) {
if (m_data.count() != 1) {
if (ok) *ok = false;
return 0;
}
@ -435,7 +435,7 @@ quint64 ZigbeeDataType::toUInt64(bool *ok) const
qint8 ZigbeeDataType::toInt8(bool *ok) const
{
if (ok) *ok = true;
if (m_data.count() != 1 || m_dataType != Zigbee::Int8) {
if (m_data.count() != 1) {
if (ok) *ok = false;
return 0;
}

View File

@ -183,6 +183,12 @@ ZigbeeCluster *ZigbeeNodeEndpoint::createCluster(Zigbee::ClusterId clusterId, Zi
case Zigbee::ClusterIdRelativeHumidityMeasurement:
return new ZigbeeClusterRelativeHumidityMeasurement(m_network, m_node, this, direction, this);
break;
case Zigbee::ClusterIdOccupancySensing:
return new ZigbeeClusterOccupancySensing(m_network, m_node, this, direction, this);
break;
case Zigbee::ClusterIdIlluminanceMeasurement:
return new ZigbeeClusterIlluminanceMeasurment(m_network, m_node, this, direction, this);
break;
// Security
case Zigbee::ClusterIdIasZone:
return new ZigbeeClusterIasZone(m_network, m_node, this, direction, this);

View File

@ -41,6 +41,8 @@
#include "zcl/general/zigbeeclusteronoff.h"
#include "zcl/general/zigbeeclusteridentify.h"
#include "zcl/measurement/zigbeeclusteroccupancysensing.h"
#include "zcl/measurement/zigbeeclusterilluminancemeasurment.h"
#include "zcl/measurement/zigbeeclustertemperaturemeasurement.h"
#include "zcl/measurement/zigbeeclusterrelativehumiditymeasurement.h"