-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWiFiMQTT_HA_GroupLight.h
64 lines (48 loc) · 1.11 KB
/
WiFiMQTT_HA_GroupLight.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef _WIFIMQTT_HA_GROUPLIGHT_H_
#define _WIFIMQTT_HA_GROUPLIGHT_H_
#include "WiFiMQTT_HA_Light.h"
class WiFiMQTT_HA_GroupLight : public WiFiMQTT_HA_Light
{
public:
WiFiMQTT_HA_GroupLight(const FastLEDLight& ledLight)
: WiFiMQTT_HA_Light(ledLight)
{
}
void publishState() override
{
DynamicJsonDocument doc(128);
doc["state"] = ledLight.isON() ? "ON" : "OFF";
doc["brightness"] = ledLight.getBrightness();
doc["effect"] = ledLight.getEffectName();
publishJson(STATE_TOPIC, doc);
doc["deviceID"] = DEVICE_UNIQUE_ID;
publishJson(GROUP_TOPIC, doc);
}
protected:
void subscribe() override
{
WiFiMQTT_HA_Light::subscribe();
mqtt.subscribe(GROUP_TOPIC);
}
void processTopic(char* topic, DynamicJsonDocument& payload)
{
if (strcmp(topic, GROUP_TOPIC) == 0)
{
if (payload.containsKey("deviceID"))
{
String deviceID = payload["deviceID"];
// ignore command from itself
if (deviceID.equals(DEVICE_UNIQUE_ID))
return;
}
processPayload(payload);
WiFiMQTT_HA_Light::publishState();
}
else
{
processPayload(payload);
publishState();
}
}
};
#endif