From b6322de46e27ed8aeacfcf4aeb754a76d51beb75 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Tue, 30 Apr 2024 08:45:50 +0200 Subject: [PATCH] make area optional and add EasyHome switches --- gateway/include/ha.h | 35 +++++++++++++++++++++++++++++++---- gateway/include/mqtt.h | 9 +++++---- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/gateway/include/ha.h b/gateway/include/ha.h index 4879828..381f520 100644 --- a/gateway/include/ha.h +++ b/gateway/include/ha.h @@ -77,8 +77,8 @@ namespace Ha { uint16_t (*publisher)(const char* topic, const char* message); virtual void onCommand(const char* msg){} - Switch(const char* name, const char* id, const char* area, uint16_t (*publisher)(const char* topic, const char* message) = nullptr) - : Command(name, id, type), area(area), publisher(publisher) { + Switch(const char* name, const char* id, uint16_t (*publisher)(const char* topic, const char* message) = nullptr) + : Command(name, id, type), publisher(publisher) { sprintf(commandTopic, "homeassistant/%s/rc-gateway/%s/set", type, id); } @@ -104,6 +104,11 @@ namespace Ha { return this; } + Switch* withArea(const char* area) { + this->area = area; + return this; + } + void publishState(bool state) { publisher(stateTopic, state ? "ON" : "OFF"); } @@ -114,8 +119,8 @@ namespace Ha { const char* group; unsigned char channel; - PollinSwitch(const char* name, const char* area, const char* group, const unsigned char channel, uint16_t (*publisher)(const char* topic, const char* message)) - : Switch(name, Protocol_1::buildId(group, channel), area, publisher), group(group), channel(channel) { + PollinSwitch(const char* name, const char* group, const unsigned char channel, uint16_t (*publisher)(const char* topic, const char* message)) + : Switch(name, Protocol_1::buildId(group, channel), publisher), group(group), channel(channel) { sprintf(commandTopic, "homeassistant/%s/rc-gateway/%s/set", type, id); } @@ -132,6 +137,28 @@ namespace Ha { }; + struct EasyHomeSwitch : Switch { + const char* on; + const char* off; + + EasyHomeSwitch(const char* name, const char* id, const char* on, const char* off) : Switch(name, id), on(on), off(off) { + sprintf(commandTopic, "homeassistant/%s/rc-gateway/easy_home_%s/set", type, id); + } + + void onCommand(const char* msg) override { + mySwitch.setProtocol(4); + String{ "ON" }.equals(msg) ? mySwitch.send(on) : mySwitch.send(off); + } + + void buildConfig(JsonDocument& jsonDoc) override { + Switch::buildConfig(jsonDoc); + JsonObject device = jsonDoc["device"]; + device["manufacturer"] = "Intertek"; + device["model"] = "Easy Home"; + } + + }; + struct Sensor : Component { const char* deviceClass; const char* unitMeasure; diff --git a/gateway/include/mqtt.h b/gateway/include/mqtt.h index 40a3813..45a4423 100644 --- a/gateway/include/mqtt.h +++ b/gateway/include/mqtt.h @@ -48,10 +48,11 @@ namespace Mqtt { }; Ha::Switch* switches[] = { - (new Ha::PollinSwitch{"Meeting sensor", "Dining room", "00001", 1, publish})->withStateTopic(), - (new Ha::PollinSwitch{"Fire Tv", "Living room", "00001", 2, publish})->withStateTopic(), - (new Ha::PollinSwitch{"Diningroom player", "Dining room", "00001", 3, publish})->withStateTopic(), - (new Ha::PollinSwitch{"Train", "Playroom", "11111", 4, publish})->withStateTopic() + (new Ha::PollinSwitch{"Meeting sensor", "00001", 1, publish})->withArea("Dining room")->withStateTopic(), + (new Ha::PollinSwitch{"Fire Tv", "00001", 2, publish})->withArea("Living room")->withStateTopic(), + (new Ha::PollinSwitch{"Diningroom player", "00001", 3, publish})->withArea("Dining room")->withStateTopic(), + (new Ha::PollinSwitch{"Train", "11111", 4, publish})->withArea("Playroom")->withStateTopic(), + (new Ha::EasyHomeSwitch{"FritzBox", "easy_home_a", "010001101001100101110000", "010010111110000010100000"})->withArea("Basement") }; unordered_map mapSwitches;