make publisher accesible to entire Ha namespace
This commit is contained in:
parent
e48c75796b
commit
35c0adcee5
@ -7,6 +7,7 @@
|
||||
#define DEVICE_ID "rc-gateway"
|
||||
|
||||
namespace Ha {
|
||||
uint16_t (*publisher)(const char* topic, const char* message);
|
||||
|
||||
struct Component {
|
||||
const char* name;
|
||||
@ -70,18 +71,16 @@ namespace Ha {
|
||||
|
||||
};
|
||||
|
||||
typedef uint16_t (*publisherFunc)(const char* topic, const char* message);
|
||||
struct Switch : Command {
|
||||
static constexpr const char* type = "switch";
|
||||
char stateTopic[TOPIC_SIZE];
|
||||
const char* area;
|
||||
publisherFunc publisher;
|
||||
|
||||
virtual void onCommand(const char* msg){}
|
||||
virtual void addToMap(){}
|
||||
|
||||
Switch(const char* name, const char* id, publisherFunc publisher = nullptr)
|
||||
: Command(name, id, type), publisher(publisher) {
|
||||
Switch(const char* name, const char* id)
|
||||
: Command(name, id, type) {
|
||||
sprintf(commandTopic, "homeassistant/%s/rc-gateway/%s/set", type, id);
|
||||
}
|
||||
|
||||
@ -121,8 +120,8 @@ namespace Ha {
|
||||
const char* group;
|
||||
unsigned char channel;
|
||||
|
||||
PollinSwitch(const char* name, const char* group, const unsigned char channel, publisherFunc publisher)
|
||||
: Switch(name, Protocol_1::buildId(group, channel), publisher), group(group), channel(channel) {
|
||||
PollinSwitch(const char* name, const char* group, const unsigned char channel)
|
||||
: Switch(name, Protocol_1::buildId(group, channel)), group(group), channel(channel) {
|
||||
sprintf(commandTopic, "homeassistant/%s/rc-gateway/%s/set", type, id);
|
||||
}
|
||||
|
||||
@ -147,8 +146,8 @@ namespace Ha {
|
||||
unsigned long on[8] = {4326554, 4537114, 4767530, 4972714};
|
||||
unsigned long off[8] = {4483146, 4626810, 4661562, 4819642};
|
||||
|
||||
EasyHomeSwitch(const char* name, const char* id, unsigned long on[4], unsigned long off[4], publisherFunc publisher)
|
||||
: Switch(name, id, publisher) {
|
||||
EasyHomeSwitch(const char* name, const char* id, unsigned long on[4], unsigned long off[4])
|
||||
: Switch(name, id) {
|
||||
memcpy(&this->on[4], on, 4*sizeof(unsigned long));
|
||||
memcpy(&this->off[4], off, 4*sizeof(unsigned long));
|
||||
sprintf(commandTopic, "homeassistant/%s/rc-gateway/%s/set", type, id);
|
||||
|
||||
@ -48,12 +48,12 @@ namespace Mqtt {
|
||||
};
|
||||
|
||||
Ha::Switch* switches[] = {
|
||||
(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", (unsigned long[4]) { 4483136, 4626800, 4661552, 4819632 }, (unsigned long[4]) { 4326544, 4537104, 4767520, 4972704 }, publish})->withArea("Basement")->withStateTopic(),
|
||||
(new Ha::EasyHomeSwitch{"Outside", "easy_home_b", (unsigned long[4]) { 4483140, 4626804, 4661556, 4819636 }, (unsigned long[4]) { 4326548, 4537108, 4767524, 4972708 }, publish})->withArea("Basement")->withStateTopic()
|
||||
(new Ha::PollinSwitch{"Meeting sensor", "00001", 1})->withArea("Dining room")->withStateTopic(),
|
||||
(new Ha::PollinSwitch{"Fire Tv", "00001", 2})->withArea("Living room")->withStateTopic(),
|
||||
(new Ha::PollinSwitch{"Diningroom player", "00001", 3})->withArea("Dining room")->withStateTopic(),
|
||||
(new Ha::PollinSwitch{"Train", "11111", 4})->withArea("Playroom")->withStateTopic(),
|
||||
(new Ha::EasyHomeSwitch{"FritzBox", "easy_home_a", (unsigned long[4]) { 4483136, 4626800, 4661552, 4819632 }, (unsigned long[4]) { 4326544, 4537104, 4767520, 4972704 }})->withArea("Basement")->withStateTopic(),
|
||||
(new Ha::EasyHomeSwitch{"Outside", "easy_home_b", (unsigned long[4]) { 4483140, 4626804, 4661556, 4819636 }, (unsigned long[4]) { 4326548, 4537108, 4767524, 4972708 }})->withArea("Basement")->withStateTopic()
|
||||
};
|
||||
|
||||
void publishComponentConfig(Ha::Component& component) {
|
||||
@ -70,6 +70,7 @@ namespace Mqtt {
|
||||
// for (Ha::Component* cmp : sensors) {
|
||||
// publishComponentConfig(*cmp);
|
||||
// }
|
||||
Ha::publisher = publish;
|
||||
for (Ha::Component* cmp : buttons) {
|
||||
publishComponentConfig(*cmp);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user