diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index d5b3e337d..afb273229 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -9,6 +9,7 @@ * Add Home Assistant clear other device (#1931) * Add Restart time to Status 1 (#1938) * Change Sonoff SC JSON format (#1939) + * Fix compile error when define HOME_ASSISTANT_DISCOVERY_ENABLE is not set (#1937) * * 5.12.0a * Change platformio option sonoff-ds18x20 to sonoff-xxl enabling ds18x20 and all other sensors in one image diff --git a/sonoff/settings.ino b/sonoff/settings.ino index 0c3edfe8c..f77955ebd 100644 --- a/sonoff/settings.ino +++ b/sonoff/settings.ino @@ -50,6 +50,10 @@ #define MTX_ADDRESS8 0 #endif +#ifndef HOME_ASSISTANT_DISCOVERY_ENABLE +#define HOME_ASSISTANT_DISCOVERY_ENABLE 0 +#endif + /*********************************************************************************************\ * RTC memory \*********************************************************************************************/ diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index 834ba3f40..a46044910 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -114,6 +114,7 @@ enum WeekInMonthOptions {Last, First, Second, Third, Fourth}; enum DayOfTheWeekOptions {Sun=1, Mon, Tue, Wed, Thu, Fri, Sat}; enum MonthNamesOptions {Jan=1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec}; enum HemisphereOptions {North, South}; +enum GetDateAndTimeOptions { DT_LOCAL, DT_UTC, DT_RESTART, DT_UPTIME }; enum LoggingLevels {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE, LOG_LEVEL_ALL}; diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 711a296fd..1f2a524d9 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -1743,7 +1743,7 @@ void PublishStatus(uint8_t payload) if ((0 == payload) || (1 == payload)) { snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_STATUS D_STATUS1_PARAMETER "\":{\"" D_JSON_BAUDRATE "\":%d,\"" D_CMND_GROUPTOPIC "\":\"%s\",\"" D_CMND_OTAURL "\":\"%s\",\"" D_JSON_UPTIME "\":\"%s\",\"" D_JSON_STARTUPUTC "\":\"%s\",\"" D_CMND_SLEEP "\":%d,\"" D_JSON_BOOTCOUNT "\":%d,\"" D_JSON_SAVECOUNT "\":%d,\"" D_JSON_SAVEADDRESS "\":\"%X\"}}"), - baudrate, Settings.mqtt_grptopic, Settings.ota_url, GetDateAndTime(3).c_str(), GetDateAndTime(2).c_str(), Settings.sleep, Settings.bootcount, Settings.save_flag, GetSettingsAddress()); + baudrate, Settings.mqtt_grptopic, Settings.ota_url, GetDateAndTime(DT_UPTIME).c_str(), GetDateAndTime(DT_RESTART).c_str(), Settings.sleep, Settings.bootcount, Settings.save_flag, GetSettingsAddress()); MqttPublishPrefixTopic_P(option, PSTR(D_CMND_STATUS "1")); } @@ -1816,7 +1816,7 @@ void MqttShowState() { char stemp1[33]; - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s{\"" D_JSON_TIME "\":\"%s\",\"" D_JSON_UPTIME "\":\"%s\""), mqtt_data, GetDateAndTime(0).c_str(), GetDateAndTime(3).c_str()); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s{\"" D_JSON_TIME "\":\"%s\",\"" D_JSON_UPTIME "\":\"%s\""), mqtt_data, GetDateAndTime(DT_LOCAL).c_str(), GetDateAndTime(DT_UPTIME).c_str()); #ifdef USE_ADC_VCC dtostrfd((double)ESP.getVcc()/1000, 3, stemp1); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_VCC "\":%s"), mqtt_data, stemp1); @@ -1836,7 +1836,7 @@ void MqttShowState() boolean MqttShowSensor() { - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s{\"" D_JSON_TIME "\":\"%s\""), mqtt_data, GetDateAndTime(0).c_str()); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s{\"" D_JSON_TIME "\":\"%s\""), mqtt_data, GetDateAndTime(DT_LOCAL).c_str()); int json_data_start = strlen(mqtt_data); for (byte i = 0; i < MAX_SWITCHES; i++) { if (pin[GPIO_SWT1 +i] < 99) { @@ -1927,7 +1927,7 @@ void PerformEverySecond() if ((2 == RtcTime.minute) && latest_uptime_flag) { latest_uptime_flag = false; - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_TIME "\":\"%s\",\"" D_JSON_UPTIME "\":\"%s\"}"), GetDateAndTime(0).c_str(), GetDateAndTime(3).c_str()); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_TIME "\":\"%s\",\"" D_JSON_UPTIME "\":\"%s\"}"), GetDateAndTime(DT_LOCAL).c_str(), GetDateAndTime(DT_UPTIME).c_str()); MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_UPTIME)); } if ((3 == RtcTime.minute) && !latest_uptime_flag) { diff --git a/sonoff/support.ino b/sonoff/support.ino index 870b7556c..a086f1207 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -1027,16 +1027,12 @@ String GetBuildDateAndTime() String GetDateAndTime(byte time_type) { - /* 0 - Local Date and Time - 1 - UTC Date and Time - 2 - UTC Restart Date and Time - 3 - Uptime - */ + // enum GetDateAndTimeOptions { DT_LOCAL, DT_UTC, DT_RESTART, DT_UPTIME }; // "2017-03-07T11:08:02" - ISO8601:2004 char dt[21]; TIME_T tmpTime; - if (3 == time_type) { + if (DT_UPTIME == time_type) { if (restart_time) { BreakTime(utc_time - restart_time, tmpTime); } else { @@ -1050,11 +1046,11 @@ String GetDateAndTime(byte time_type) tmpTime.days, tmpTime.hour, tmpTime.minute, tmpTime.second); } else { switch (time_type) { - case 1: + case DT_UTC: BreakTime(utc_time, tmpTime); tmpTime.year += 1970; break; - case 2: + case DT_RESTART: if (restart_time == 0) { return ""; } diff --git a/sonoff/webserver.ino b/sonoff/webserver.ino index 83f91208e..87766e73d 100644 --- a/sonoff/webserver.ino +++ b/sonoff/webserver.ino @@ -1598,7 +1598,7 @@ void HandleInformation() func += F(D_PROGRAM_VERSION "}2"); func += my_version; func += F("}1" D_BUILD_DATE_AND_TIME "}2"); func += GetBuildDateAndTime(); func += F("}1" D_CORE_AND_SDK_VERSION "}2" ARDUINO_ESP8266_RELEASE "/"); func += String(ESP.getSdkVersion()); - func += F("}1" D_UPTIME "}2"); func += GetDateAndTime(3); + func += F("}1" D_UPTIME "}2"); func += GetDateAndTime(DT_UPTIME); snprintf_P(stopic, sizeof(stopic), PSTR(" at %X"), GetSettingsAddress()); func += F("}1" D_FLASH_WRITE_COUNT "}2"); func += String(Settings.save_flag); func += stopic; func += F("}1" D_BOOT_COUNT "}2"); func += String(Settings.bootcount); diff --git a/sonoff/xdrv_03_energy.ino b/sonoff/xdrv_03_energy.ino index 81376a9d5..bf29ed6be 100644 --- a/sonoff/xdrv_03_energy.ino +++ b/sonoff/xdrv_03_energy.ino @@ -748,7 +748,7 @@ void EnergyMarginCheck() void EnergyMqttShow() { // {"Time":"2017-12-16T11:48:55","ENERGY":{"Total":0.212,"Yesterday":0.000,"Today":0.014,"Period":2.0,"Power":22.0,"Factor":1.00,"Voltage":213.6,"Current":0.100}} - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_TIME "\":\"%s\""), GetDateAndTime(0).c_str()); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_TIME "\":\"%s\""), GetDateAndTime(DT_LOCAL).c_str()); EnergyShow(1); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data); MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_ENERGY), Settings.flag.mqtt_sensor_retain); diff --git a/sonoff/xplg_wemohue.ino b/sonoff/xplg_wemohue.ino index 986dd9947..a1f3d8ce8 100644 --- a/sonoff/xplg_wemohue.ino +++ b/sonoff/xplg_wemohue.ino @@ -544,7 +544,7 @@ void HueConfigResponse(String *response) response->replace("{ms", WiFi.subnetMask().toString()); response->replace("{gw", WiFi.gatewayIP().toString()); response->replace("{br", HueBridgeId()); - response->replace("{dt", GetDateAndTime(1)); + response->replace("{dt", GetDateAndTime(DT_UTC)); response->replace("{id", GetHueUserId()); }