From 457a8f48a3ce1f06d334983154ac6d87e6dcdda1 Mon Sep 17 00:00:00 2001 From: Amy Nagle Date: Thu, 3 Feb 2022 17:23:32 -0500 Subject: [PATCH] Fix OpenHAB discovery (#1153) * Fix OpenHAB discovery * Add test for OpenHAB discovery --- main/config_mqttDiscovery.h | 81 +++++++++++++++++++------------------ platformio.ini | 13 ++++++ 2 files changed, 55 insertions(+), 39 deletions(-) diff --git a/main/config_mqttDiscovery.h b/main/config_mqttDiscovery.h index 39f91f6be5..a6d9b1c306 100644 --- a/main/config_mqttDiscovery.h +++ b/main/config_mqttDiscovery.h @@ -118,7 +118,9 @@ void announceDeviceTrigger(bool use_gateway_info, /*-------------- Auto discovery macros-----------------*/ // Set the line below to true so as to have autodiscovery working with OpenHAB -#define OpenHABDiscovery false +#ifndef OpenHABDiscovery +# define OpenHABDiscovery false +#endif #if OpenHABDiscovery // OpenHAB autodiscovery value key definition (is defined command is not supported by OpenHAB) # define jsonBatt "{{ value_json.batt }}" @@ -156,46 +158,47 @@ void announceDeviceTrigger(bool use_gateway_info, # define jsonCount "{{ value_json.count }}" # define jsonAlarm "{{ value_json.alarm }}" #else // Home assistant autodiscovery value key definition -# define jsonBatt "{{ value_json.batt | is_defined }}" -# define jsonLux "{{ value_json.lux | is_defined }}" -# define jsonPres "{{ value_json.pres | is_defined }}" -# define jsonFer "{{ value_json.fer | is_defined }}" -# define jsonFor "{{ value_json.for | is_defined }}" -# define jsonMoi "{{ value_json.moi | is_defined }}" -# define jsonHum "{{ value_json.hum | is_defined }}" -# define jsonStep "{{ value_json.steps | is_defined }}" -# define jsonWeight "{{ value_json.weight | is_defined }}" -# define jsonPresence "{{ value_json.presence | is_defined }}" -# define jsonAltim "{{ value_json.altim | is_defined }}" -# define jsonAltif "{{ value_json.altift | is_defined }}" -# define jsonTempc "{{ value_json.tempc | is_defined }}" -# define jsonTempc2 "{{ value_json.tempc2 | is_defined }}" -# define jsonTempc3 "{{ value_json.tempc3 | is_defined }}" -# define jsonTempc4 "{{ value_json.tempc4 | is_defined }}" -# define jsonTempf "{{ value_json.tempf | is_defined }}" -# define jsonMsg "{{ value_json.message | is_defined }}" -# define jsonVal "{{ value_json.value | is_defined }}" -# define jsonVolt "{{ value_json.volt | is_defined }}" -# define jsonCurrent "{{ value_json.current | is_defined }}" -# define jsonPower "{{ value_json.power | is_defined }}" -# define jsonEnergy "{{ value_json.energy | is_defined }}" -# define jsonGpio "{{ value_json.gpio | is_defined }}" -# define jsonFtcd "{{ value_json.ftcd | is_defined }}" -# define jsonWm2 "{{ value_json.wattsm2 | is_defined }}" -# define jsonAdc "{{ value_json.adc | is_defined }}" -# define jsonPa "{{ float(value_json.pa) * 0.01 | is_defined }}" -# define jsonId "{{ value_json.id | is_defined }}" -# define jsonAddress "{{ value_json.address | is_defined }}" -# define jsonOpen "{{ value_json.open | is_defined }}" -# define jsonTime "{{ value_json.time | is_defined }}" -# define jsonCount "{{ value_json.count | is_defined }}" -# define jsonAlarm "{{ value_json.alarm | is_defined }}" -# define stateClassNone "" -# define stateClassMeasurement "measurement" -# define stateClassTotal "total" -# define stateClassTotalIncreasing "total_increasing" +# define jsonBatt "{{ value_json.batt | is_defined }}" +# define jsonLux "{{ value_json.lux | is_defined }}" +# define jsonPres "{{ value_json.pres | is_defined }}" +# define jsonFer "{{ value_json.fer | is_defined }}" +# define jsonFor "{{ value_json.for | is_defined }}" +# define jsonMoi "{{ value_json.moi | is_defined }}" +# define jsonHum "{{ value_json.hum | is_defined }}" +# define jsonStep "{{ value_json.steps | is_defined }}" +# define jsonWeight "{{ value_json.weight | is_defined }}" +# define jsonPresence "{{ value_json.presence | is_defined }}" +# define jsonAltim "{{ value_json.altim | is_defined }}" +# define jsonAltif "{{ value_json.altift | is_defined }}" +# define jsonTempc "{{ value_json.tempc | is_defined }}" +# define jsonTempc2 "{{ value_json.tempc2 | is_defined }}" +# define jsonTempc3 "{{ value_json.tempc3 | is_defined }}" +# define jsonTempc4 "{{ value_json.tempc4 | is_defined }}" +# define jsonTempf "{{ value_json.tempf | is_defined }}" +# define jsonMsg "{{ value_json.message | is_defined }}" +# define jsonVal "{{ value_json.value | is_defined }}" +# define jsonVolt "{{ value_json.volt | is_defined }}" +# define jsonCurrent "{{ value_json.current | is_defined }}" +# define jsonPower "{{ value_json.power | is_defined }}" +# define jsonEnergy "{{ value_json.energy | is_defined }}" +# define jsonGpio "{{ value_json.gpio | is_defined }}" +# define jsonFtcd "{{ value_json.ftcd | is_defined }}" +# define jsonWm2 "{{ value_json.wattsm2 | is_defined }}" +# define jsonAdc "{{ value_json.adc | is_defined }}" +# define jsonPa "{{ float(value_json.pa) * 0.01 | is_defined }}" +# define jsonId "{{ value_json.id | is_defined }}" +# define jsonAddress "{{ value_json.address | is_defined }}" +# define jsonOpen "{{ value_json.open | is_defined }}" +# define jsonTime "{{ value_json.time | is_defined }}" +# define jsonCount "{{ value_json.count | is_defined }}" +# define jsonAlarm "{{ value_json.alarm | is_defined }}" #endif +#define stateClassNone "" +#define stateClassMeasurement "measurement" +#define stateClassTotal "total" +#define stateClassTotalIncreasing "total_increasing" + // From https://github.com/home-assistant/core/blob/d7ac4bd65379e11461c7ce0893d3533d8d8b8cbf/homeassistant/const.py#L225 // List of classes available in Home Assistant const char* availableHASSClasses[] = {"battery", diff --git a/platformio.ini b/platformio.ini index f7f888bc7c..0f447d7361 100644 --- a/platformio.ini +++ b/platformio.ini @@ -76,6 +76,7 @@ extra_configs = ;default_envs = uno-fastled ;default_envs = atmega-all-test ;default_envs = manual-wifi-test +;default_envs = openhab-test ;default_envs = esp32dev-mqtt-fw-test ;default_envs = nodemcuv2-mqtt-fw-test ;default_envs = nodemcuv2-rs232 @@ -1014,6 +1015,18 @@ build_flags = '-DGateway_Name="OpenMQTTGateway_TEST_MANUAL_WIFI"' board_build.flash_mode = dout +[env:openhab-test] +platform = ${com.esp8266_platform} +board = nodemcuv2 +lib_deps = + ${com-esp.lib_deps} + ${libraries.wifimanager8266} +build_flags = + ${com-esp.build_flags} + '-DOpenHABDiscovery=true' + '-DGateway_Name="OpenMQTTGateway_TEST_OPENHAB"' +board_build.flash_mode = dout + [env:nodemcuv2-mqtt-fw-test] platform = ${com.esp8266_platform} board = nodemcuv2