Skip to content

Commit

Permalink
Get timezone from HA
Browse files Browse the repository at this point in the history
  • Loading branch information
aeroniemi committed May 29, 2024
1 parent 37099a9 commit a3af3c5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ lib_deps =
lvgl/lvgl@>=9.1.0
smfsw/Queue@1.11
rzeldent/micro-timezonedb@1.0.3
Arduino-HomeAssistant=https://github.com/aeroniemi/arduino-homeassistant.git#257d06d
Arduino-HomeAssistant=https://github.com/aeroniemi/arduino-homeassistant.git#594d357c69085c289e3d22d53c9af11f51f6857a
M5Dial-LVGL=https://github.com/aeroniemi/M5Dial-LVGL.git#v0.1.0
jnthas/Improv WiFi Library@0.0.2
extra_scripts =
Expand Down
14 changes: 13 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <ImprovWiFiLibrary.h>
#include <WiFi.h>
#include <WebServer.h>
#include <timezonedb_lookup.h>
ImprovWiFi improvSerial(&Serial);
HomeAssistant has;
HomeAssistant *ha = &has;
Expand All @@ -33,6 +34,16 @@ void log_cb(lv_log_level_t level, const char *buf)
{
Serial.println(buf);
}
void update_timezone() {
String timezone = ha->getTimezone();
log_d("Timezone: %s", timezone);
if (timezone.length() ==0)
return;
String tz = lookup_posix_timezone_tz(timezone.c_str());
settings.putString("ntp_timezone", timezone);
settings.putString("ntp_tz_str", tz);
setupTime();
};

void initializeScreens()
{
Expand Down Expand Up @@ -125,7 +136,7 @@ void loop()
clock_timer.update();
// log_d("HA is setup? %d %s", ha->isSetup(), settings.getString("ha_refresh", "none"));
if (ha->isSetup() and not initialized_ha)
{
{
log_d("Initializing HA");
ha->createEntities();
ha->updateAllStates();
Expand All @@ -141,6 +152,7 @@ void loop()
log_d("access token: '%s'", ha->getToken().c_str());
initializeScreens();
screen_main_menu.makeActive();
update_timezone();
initialized = true;
}
};
Expand Down

0 comments on commit a3af3c5

Please sign in to comment.