Skip to content

Commit

Permalink
Zigbee2mqtt driver is implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
awawa-dev committed Dec 27, 2024
1 parent 32e85af commit 27643cb
Show file tree
Hide file tree
Showing 11 changed files with 555 additions and 10 deletions.
3 changes: 1 addition & 2 deletions cmake/installers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,7 @@ macro(DeployUnix TARGET)
"libdl"
"libexpat"
"libfontconfig"
"libgcc_s"
"libgpg-error"
"libgcc_s"
"libm"
"libpthread"
"librt"
Expand Down
62 changes: 62 additions & 0 deletions include/led-drivers/net/DriverNetZigbee2mqtt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#pragma once

#ifndef PCH_ENABLED
#include <QJsonObject>
#include <QJsonArray>
#include <memory>
#include <list>
#include <atomic>
#endif

#include <led-drivers/LedDevice.h>
#include <linalg.h>

class DriverNetZigbee2mqtt : public LedDevice
{
Q_OBJECT

struct Zigbee2mqttLamp;

struct Zigbee2mqttInstance
{
int transition;
int constantBrightness;

std::list<Zigbee2mqttLamp> lamps;
};

struct Zigbee2mqttLamp
{
enum Mode { RGB = 0, HSV };

QString name;
Mode colorModel;
};

public:
explicit DriverNetZigbee2mqtt(const QJsonObject& deviceConfig);
static LedDevice* construct(const QJsonObject& deviceConfig);

QJsonObject discover(const QJsonObject& params) override;

void identify(const QJsonObject& params) override;

public slots:
void handlerSignalMqttReceived(QString topic, QString payload);

protected:
bool powerOn() override;
bool powerOff() override;

private:
bool init(const QJsonObject& deviceConfig) override;
int write(const std::vector<ColorRgb>& ledValues) override;
bool powerOnOff(bool isOn);

Zigbee2mqttInstance _zigInstance;
std::atomic<bool> _discoveryFinished, _colorsFinished;
int _timeLogger;
QString _discoveryMessage;

static bool isRegistered;
};
1 change: 1 addition & 0 deletions include/mqtt/mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public slots:
void handleSettingsUpdate(settings::type type, const QJsonDocument& config);

void handleSignalMqttSubscribe(bool subscribe, QString topic);
void handleSignalMqttPublish(QString topic, QString payload);

private slots:
void connected();
Expand Down
2 changes: 2 additions & 0 deletions include/utils/GlobalSignals.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,6 @@ class GlobalSignals : public QObject
void SignalMqttSubscribe(bool subscribe, QString topic);

void SignalMqttReceived(QString topic, QString payload);

void SignalMqttPublish(QString topic, QString payload);
};
1 change: 1 addition & 0 deletions sources/led-drivers/LedDeviceSchemas.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@
<file alias="schema-cololight">schemas/schema-cololight.json</file>
<file alias="schema-hyperspi">schemas/schema-hyperspi.json</file>
<file alias="schema-home_assistant">schemas/schema-home_assistant.json</file>
<file alias="schema-zigbee2mqtt">schemas/schema-zigbee2mqtt.json</file>
</qresource>
</RCC>
Loading

0 comments on commit 27643cb

Please sign in to comment.