mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-10 21:25:49 +00:00
Changed discovery to sent msg, fixed power check
This commit is contained in:
@ -1257,11 +1257,24 @@ int http_fn_ha_discovery(http_request_t* request) {
|
||||
char topic[32];
|
||||
int relayCount = 0;
|
||||
int pwmCount = 0;
|
||||
bool measuringPower = false;
|
||||
|
||||
http_setup(request, httpMimeTypeText);
|
||||
|
||||
if (MQTT_IsReady() == false) {
|
||||
poststr(request, "MQTT not running.");
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef OBK_DISABLE_ALL_DRIVERS
|
||||
measuringPower = DRV_IsMeasuringPower();
|
||||
#endif
|
||||
|
||||
get_Relay_PWM_Count(&relayCount, &pwmCount);
|
||||
|
||||
if ((relayCount == 0) && (pwmCount == 0)) {
|
||||
if ((relayCount == 0) && (pwmCount == 0) && !measuringPower) {
|
||||
poststr(request, "No relay, PWM or power driver running.");
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
@ -1308,8 +1321,8 @@ int http_fn_ha_discovery(http_request_t* request) {
|
||||
}
|
||||
|
||||
#ifndef OBK_DISABLE_ALL_DRIVERS
|
||||
if (DRV_IsMeasuringPower()) {
|
||||
for (i = 0;i < OBK_NUM_SENSOR_COUNT;i++)
|
||||
if (measuringPower == true) {
|
||||
for (i = 0;i < OBK_NUM_MEASUREMENTS;i++)
|
||||
{
|
||||
HassDeviceInfo* dev_info = hass_init_light_device_info(ENTITY_SENSOR, i);
|
||||
MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN);
|
||||
@ -1318,6 +1331,7 @@ int http_fn_ha_discovery(http_request_t* request) {
|
||||
}
|
||||
#endif
|
||||
|
||||
poststr(request, "MQTT discovery queued.");
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -615,5 +615,5 @@ const char pageScript[] = "<script type='text/javascript'>var firstTime,lastTime
|
||||
//region_end pageScript
|
||||
|
||||
//region_start ha_discovery_script
|
||||
const char ha_discovery_script[] = "<script type='text/javascript'>function send_ha_disc(){var e=new XMLHttpRequest;e.open(\"GET\",\"/ha_discovery?prefix=\"+document.getElementById(\"ha_disc_topic\").value,!1),e.onload=function(){200===e.status?alert(\"MQTT discovery queued\"):404===e.status&&alert(\"Error invoking ha_discovery\")},e.onerror=function(){alert(\"Error invoking ha_discovery\")},e.send()}</script>";
|
||||
const char ha_discovery_script[] = "<script type='text/javascript'>function send_ha_disc(){var e=new XMLHttpRequest;e.open(\"GET\",\"/ha_discovery?prefix=\"+document.getElementById(\"ha_disc_topic\").value,!1),e.onload=function(){200===e.status?alert(e.responseText):404===e.status&&alert(\"Error invoking ha_discovery\")},e.onerror=function(){alert(\"Error invoking ha_discovery\")},e.send()}</script>";
|
||||
//region_end ha_discovery_script
|
||||
@ -9,7 +9,7 @@ function send_ha_disc() {
|
||||
);
|
||||
xhr.onload = function () {
|
||||
if (xhr.status === 200) {
|
||||
alert("MQTT discovery queued");
|
||||
alert(xhr.responseText);
|
||||
} else if (xhr.status === 404) {
|
||||
alert("Error invoking ha_discovery");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user