Skip to content

Commit

Permalink
some fixes and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Илья Титов committed Nov 2, 2022
1 parent 3babbf9 commit dd763a6
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 21 deletions.
17 changes: 13 additions & 4 deletions action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,17 @@ QByteArray ActionsTUYA::Request::makeRequest(quint8 transactionId, quint8 dataPo

switch (tuyaHeader.dataType)
{
case 0x02: tuyaHeader.length = 4; break;
case 0x04: tuyaHeader.length = 1; break;
default: return QByteArray();
case 0x01:
case 0x04:
tuyaHeader.length = 1;
break;

case 0x02:
tuyaHeader.length = 4;
break;

default:
return QByteArray();
}

return QByteArray(reinterpret_cast <char*> (&zclHeader), sizeof(zclHeader)).append(reinterpret_cast <char*> (&tuyaHeader), sizeof(tuyaHeader)).append(reinterpret_cast <char*> (data), tuyaHeader.length);
Expand All @@ -322,6 +330,7 @@ QByteArray ActionsTUYA::Duration::request(const QVariant &data)
if (value > 1800)
return QByteArray();

value = qToBigEndian(value);
return makeRequest(m_transactionId++, 0x07, 0x02, &value);
}

Expand All @@ -333,7 +342,7 @@ QByteArray ActionsTUYA::Alarm::request(const QVariant &data)

QByteArray ActionsTUYA::Melody::request(const QVariant &data)
{
quint32 value = static_cast <quint32> (data.toInt());
quint8 value = static_cast <quint8> (data.toInt());

if (value < 1 || value > 18)
return QByteArray();
Expand Down
2 changes: 1 addition & 1 deletion controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void Controller::mqttReceived(const QByteArray &message, const QMqttTopicName &t

case Command::bindDevice:
case Command::unbindDevice:
m_zigbee->bindingControl(json.value("device").toString(), static_cast <quint8> (json.value("endpointId").toInt()), static_cast <quint16> (json.value("clusterId").toInt()), json.value(json.contains("groupId") ? "groupId" : "dstAddress").toVariant(), static_cast <quint8> (json.value("dstEndpointId").toInt()), command == Command::unbindDevice);
m_zigbee->bindingControl(json.value("device").toString(), static_cast <quint8> (json.value("endpointId").toInt()), static_cast <quint16> (json.value("clusterId").toInt()), json.value(json.contains("groupId") ? "groupId" : "dstDevice").toVariant(), static_cast <quint8> (json.value("dstEndpointId").toInt()), command == Command::unbindDevice);
break;

case Command::addGroup:
Expand Down
2 changes: 1 addition & 1 deletion controller.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef CONTROLLER_H
#define CONTROLLER_H

#define SERVICE_VERSION "3.0.38"
#define SERVICE_VERSION "3.0.39"

#include <QMetaEnum>
#include "homed.h"
Expand Down
2 changes: 1 addition & 1 deletion package/data/usr/share/homed/zigbee.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
{
"description": "Perenio Door and Window Sensor PECWS01",
"modelNames": ["ZHA-DoorLockSensor"],
"properties": ["batteryPercentage", "iasOccupancy"],
"properties": ["batteryPercentage", "iasContact"],
"reportings": ["batteryPercentage"]
},
{
Expand Down
5 changes: 3 additions & 2 deletions property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void PropertyObject::registerMetaTypes(void)
qRegisterMetaType <PropertiesPTVO::Pattern> ("ptvoPatternProperty");
qRegisterMetaType <PropertiesPTVO::SwitchAction> ("ptvoSwitchActionProperty");

qRegisterMetaType <PropertiesTUYA::NeoSiren> ("tuyaNeoSirenProperty");
qRegisterMetaType <PropertiesTUYA::PresenceSensor> ("tuyaPresenceSensorProperty");
qRegisterMetaType <PropertiesTUYA::PowerOnBehavior> ("tuyaPowerOnBehaviorProperty");
qRegisterMetaType <PropertiesTUYA::SwitchType> ("tuyaSwitchTypeProperty");
Expand Down Expand Up @@ -781,7 +782,7 @@ void PropertiesTUYA::Data::parseCommand(quint8 commandId, const QByteArray &payl
const tuyaHeaderStruct *header = reinterpret_cast <const tuyaHeaderStruct*> (payload.constData());
QVariant data;

if (commandId != 0x02)
if (commandId != 0x01 && commandId != 0x02)
return;

data = parseData(header, payload.mid(sizeof(tuyaHeaderStruct)));
Expand Down Expand Up @@ -839,7 +840,7 @@ void PropertiesTUYA::NeoSiren::update(quint8 dataPoint, const QVariant &data)
case 0x07: m_map.insert("duration", data.toInt()); break;
case 0x0D: m_map.insert("alarm", data.toBool()); break;
case 0x0F: m_map.insert("battery", data.toInt()); break;
case 0x15: m_map.insert("melody", data.toBool()); break;
case 0x15: m_map.insert("melody", data.toInt()); break;
}

m_value = m_map;
Expand Down
37 changes: 25 additions & 12 deletions zigbee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "zigbee.h"
#include "zstack.h"

ZigBee::ZigBee(QSettings *config, QObject *parent) : QObject(parent), m_config(config), m_neighborsTimer(new QTimer(this)), m_queuesTimer(new QTimer(this)), m_statusLedTimer(new QTimer(this)), m_devices(new DeviceList(m_config)), m_transactionId(0)
ZigBee::ZigBee(QSettings *config, QObject *parent) : QObject(parent), m_config(config), m_neighborsTimer(new QTimer(this)), m_queuesTimer(new QTimer(this)), m_statusLedTimer(new QTimer(this)), m_devices(new DeviceList(m_config)), m_adapter(nullptr), m_transactionId(0)
{
ActionObject::registerMetaTypes();
PollObject::registerMetaTypes();
Expand Down Expand Up @@ -58,9 +58,10 @@ void ZigBee::init(void)

void ZigBee::setPermitJoin(bool enabled)
{
m_devices->setPermitJoin(enabled);
if (!m_adapter)
return;

m_adapter->setPermitJoin(enabled);
m_devices->storeStatus();
}

void ZigBee::setDeviceName(const QString &deviceName, const QString &newName)
Expand Down Expand Up @@ -141,25 +142,32 @@ void ZigBee::updateReporting(const QString &deviceName, quint8 endpointId, const
}
}

void ZigBee::bindingControl(const QString &deviceName, quint8 endpointId, quint16 clusterId, const QVariant &dstAddress, quint8 dstEndpointId, bool unbind)
void ZigBee::bindingControl(const QString &deviceName, quint8 endpointId, quint16 clusterId, const QVariant &dstName, quint8 dstEndpointId, bool unbind)
{
Device device = m_devices->byName(deviceName);

if (device.isNull())
return;

switch (dstAddress.type())
switch (dstName.type())
{
case QVariant::LongLong:
{
quint16 value = qToLittleEndian <quint16> (dstAddress.toInt());
enqueueBindRequest(device, endpointId, clusterId, QByteArray(reinterpret_cast <char*> (&value), sizeof(value)), 0xFF, unbind);
quint16 value = qToLittleEndian <quint16> (dstName.toInt());

if (value)
enqueueBindRequest(device, endpointId, clusterId, QByteArray(reinterpret_cast <char*> (&value), sizeof(value)), 0xFF, unbind);

break;
}

case QVariant::String:
{
enqueueBindRequest(device, endpointId, clusterId, QByteArray::fromHex(dstAddress.toString().toUtf8()), dstEndpointId, unbind);
Device destination = m_devices->byName(deviceName);

if (!destination.isNull())
enqueueBindRequest(device, endpointId, clusterId, destination->ieeeAddress(), dstEndpointId, unbind);

break;
}

Expand Down Expand Up @@ -1157,14 +1165,19 @@ void ZigBee::coordinatorReady(void)

void ZigBee::permitJoinUpdated(bool enabled)
{
if (enabled)
if (!enabled)
{
m_statusLedTimer->stop();
GPIO::setStatus(m_statusLedPin, m_statusLedPin != m_blinkLedPin);
}
else
{
m_statusLedTimer->start(STATUS_LED_TIMEOUT);
return;
GPIO::setStatus(m_statusLedPin, true);
}

m_statusLedTimer->stop();
GPIO::setStatus(m_statusLedPin, m_statusLedPin != m_blinkLedPin);
m_devices->setPermitJoin(enabled);
m_devices->storeStatus();
}

void ZigBee::deviceJoined(const QByteArray &ieeeAddress, quint16 networkAddress)
Expand Down

0 comments on commit dd763a6

Please sign in to comment.