Handle time zone change in time_date (#106880)
This commit is contained in:
parent
03cbf8b28d
commit
a7f4d426ee
2 changed files with 36 additions and 2 deletions
|
@ -7,8 +7,8 @@ import logging
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||
from homeassistant.const import CONF_DISPLAY_OPTIONS
|
||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
||||
from homeassistant.const import CONF_DISPLAY_OPTIONS, EVENT_CORE_CONFIG_UPDATE
|
||||
from homeassistant.core import CALLBACK_TYPE, Event, HomeAssistant, callback
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.event import async_track_point_in_utc_time
|
||||
|
@ -107,6 +107,15 @@ class TimeDateSensor(SensorEntity):
|
|||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Set up first update."""
|
||||
|
||||
async def async_update_config(event: Event) -> None:
|
||||
"""Handle core config update."""
|
||||
self._update_state_and_setup_listener()
|
||||
self.async_write_ha_state()
|
||||
|
||||
self.async_on_remove(
|
||||
self.hass.bus.async_listen(EVENT_CORE_CONFIG_UPDATE, async_update_config)
|
||||
)
|
||||
self._update_state_and_setup_listener()
|
||||
|
||||
async def async_will_remove_from_hass(self) -> None:
|
||||
|
|
|
@ -181,6 +181,31 @@ async def test_states_non_default_timezone(
|
|||
state = hass.states.get("sensor.date_time_iso")
|
||||
assert state.state == "2020-10-17T12:42:00"
|
||||
|
||||
# Change time zone
|
||||
await hass.config.async_update(time_zone="Europe/Prague")
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.time")
|
||||
assert state.state == "18:42"
|
||||
|
||||
state = hass.states.get("sensor.date")
|
||||
assert state.state == "2020-10-17"
|
||||
|
||||
state = hass.states.get("sensor.time_utc")
|
||||
assert state.state == "16:42"
|
||||
|
||||
state = hass.states.get("sensor.date_time")
|
||||
assert state.state == "2020-10-17, 18:42"
|
||||
|
||||
state = hass.states.get("sensor.date_time_utc")
|
||||
assert state.state == "2020-10-17, 16:42"
|
||||
|
||||
state = hass.states.get("sensor.internet_time")
|
||||
assert state.state == "@738"
|
||||
|
||||
state = hass.states.get("sensor.date_time_iso")
|
||||
assert state.state == "2020-10-17T18:42:00"
|
||||
|
||||
|
||||
@patch(
|
||||
"homeassistant.components.time_date.sensor.async_track_point_in_utc_time",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue