make area optional and add EasyHome switches
This commit is contained in:
parent
3dcfc3e5ba
commit
41e2e1359a
@ -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;
|
||||
|
||||
@ -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<string, Ha::Switch*> mapSwitches;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user