mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Handle time zone change in time_date (#106880)
This commit is contained in:
parent
03cbf8b28d
commit
a7f4d426ee
@ -7,8 +7,8 @@ import logging
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||||
from homeassistant.const import CONF_DISPLAY_OPTIONS
|
from homeassistant.const import CONF_DISPLAY_OPTIONS, EVENT_CORE_CONFIG_UPDATE
|
||||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
from homeassistant.core import CALLBACK_TYPE, Event, HomeAssistant, callback
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.event import async_track_point_in_utc_time
|
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:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Set up first update."""
|
"""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()
|
self._update_state_and_setup_listener()
|
||||||
|
|
||||||
async def async_will_remove_from_hass(self) -> None:
|
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")
|
state = hass.states.get("sensor.date_time_iso")
|
||||||
assert state.state == "2020-10-17T12:42:00"
|
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(
|
@patch(
|
||||||
"homeassistant.components.time_date.sensor.async_track_point_in_utc_time",
|
"homeassistant.components.time_date.sensor.async_track_point_in_utc_time",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user