Skip to content

Commit

Permalink
v5.12.0b - Fix Hass define compile error
Browse files Browse the repository at this point in the history
5.12.0b
 * Fix compile error when define HOME_ASSISTANT_DISCOVERY_ENABLE
is not set (#1937)
  • Loading branch information
arendst committed Feb 17, 2018
1 parent 1c81b0c commit feb7184
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions sonoff/_releasenotes.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions sonoff/settings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
#define MTX_ADDRESS8 0
#endif

#ifndef HOME_ASSISTANT_DISCOVERY_ENABLE
#define HOME_ASSISTANT_DISCOVERY_ENABLE 0
#endif

/*********************************************************************************************\
* RTC memory
\*********************************************************************************************/
Expand Down
1 change: 1 addition & 0 deletions sonoff/sonoff.h
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
8 changes: 4 additions & 4 deletions sonoff/sonoff.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 4 additions & 8 deletions sonoff/support.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 "";
}
Expand Down
2 changes: 1 addition & 1 deletion sonoff/webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion sonoff/xdrv_03_energy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion sonoff/xplg_wemohue.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down

0 comments on commit feb7184

Please sign in to comment.