mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-27 05:06:44 +00:00
Add HASP_USE_HA
This commit is contained in:
parent
7dd98b263f
commit
d4f5bea65c
@ -148,12 +148,14 @@ static void mqtt_message_cb(char* topic, char* payload, unsigned int length)
|
|||||||
dispatch_mtx.unlock();
|
dispatch_mtx.unlock();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#ifdef HASP_USE_HA
|
||||||
} else if(topic == strstr_P(topic, PSTR("homeassistant/status"))) { // HA discovery topic
|
} else if(topic == strstr_P(topic, PSTR("homeassistant/status"))) { // HA discovery topic
|
||||||
if(mqttHAautodiscover && !strcasecmp_P((char*)payload, PSTR("online"))) {
|
if(mqttHAautodiscover && !strcasecmp_P((char*)payload, PSTR("online"))) {
|
||||||
dispatch_current_state();
|
dispatch_current_state();
|
||||||
mqtt_ha_register_auto_discovery();
|
mqtt_ha_register_auto_discovery();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Other topic
|
// Other topic
|
||||||
|
@ -143,12 +143,14 @@ static void mqtt_message_cb(char* topic, char* payload, unsigned int length)
|
|||||||
dispatch_topic_payload(topic, (const char*)payload);
|
dispatch_topic_payload(topic, (const char*)payload);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#ifdef HASP_USE_HA
|
||||||
} else if(topic == strstr_P(topic, PSTR("homeassistant/status"))) { // HA discovery topic
|
} else if(topic == strstr_P(topic, PSTR("homeassistant/status"))) { // HA discovery topic
|
||||||
if(mqttHAautodiscover && !strcasecmp_P((char*)payload, PSTR("online"))) {
|
if(mqttHAautodiscover && !strcasecmp_P((char*)payload, PSTR("online"))) {
|
||||||
dispatch_current_state();
|
dispatch_current_state();
|
||||||
mqtt_ha_register_auto_discovery();
|
mqtt_ha_register_auto_discovery();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Other topic
|
// Other topic
|
||||||
@ -272,7 +274,9 @@ static void onConnect(void* context)
|
|||||||
mqtt_subscribe(mqtt_client, "hass/status");
|
mqtt_subscribe(mqtt_client, "hass/status");
|
||||||
|
|
||||||
/* Home Assistant auto-configuration */
|
/* Home Assistant auto-configuration */
|
||||||
|
#ifdef HASP_USE_HA
|
||||||
if(mqttHAautodiscover) mqtt_subscribe(mqtt_client, "homeassistant/status");
|
if(mqttHAautodiscover) mqtt_subscribe(mqtt_client, "homeassistant/status");
|
||||||
|
#endif
|
||||||
|
|
||||||
mqttPublish(TOPIC LWT_TOPIC, "online", 6, false);
|
mqttPublish(TOPIC LWT_TOPIC, "online", 6, false);
|
||||||
|
|
||||||
|
@ -167,12 +167,14 @@ static void mqtt_message_cb(char* topic, byte* payload, unsigned int length)
|
|||||||
dispatch_topic_payload(topic, (const char*)payload);
|
dispatch_topic_payload(topic, (const char*)payload);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#ifdef HASP_USE_HA
|
||||||
} else if(topic == strstr_P(topic, PSTR("homeassistant/status"))) { // HA discovery topic
|
} else if(topic == strstr_P(topic, PSTR("homeassistant/status"))) { // HA discovery topic
|
||||||
if(mqttHAautodiscover && !strcasecmp_P((char*)payload, PSTR("online"))) {
|
if(mqttHAautodiscover && !strcasecmp_P((char*)payload, PSTR("online"))) {
|
||||||
mqtt_ha_register_auto_discovery(); // auto-discovery first
|
mqtt_ha_register_auto_discovery(); // auto-discovery first
|
||||||
dispatch_current_state(); // send the data
|
dispatch_current_state(); // send the data
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Other topic
|
// Other topic
|
||||||
@ -299,7 +301,9 @@ void mqttStart()
|
|||||||
mqttSubscribeTo(F("hass/status"), mqttClientId);
|
mqttSubscribeTo(F("hass/status"), mqttClientId);
|
||||||
|
|
||||||
/* Home Assistant auto-configuration */
|
/* Home Assistant auto-configuration */
|
||||||
|
#ifdef HASP_USE_HA
|
||||||
if(mqttHAautodiscover) mqttSubscribeTo(F("homeassistant/status"), mqttClientId);
|
if(mqttHAautodiscover) mqttSubscribeTo(F("homeassistant/status"), mqttClientId);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Force any subscribed clients to toggle offline/online when we first connect to
|
// Force any subscribed clients to toggle offline/online when we first connect to
|
||||||
// make sure we get a full panel refresh at power on. Sending offline,
|
// make sure we get a full panel refresh at power on. Sending offline,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user