mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-11-13 13:00:16 +00:00
Propagate timezone setting to host in OS 16.2 and newer (#6099)
* Propagate timezone setting to host in OS 16.2 and newer With home-assistant/operating-system#4224, timezone setting in OS can be peristently set in HAOS as well. Propagate the timezone configured in Supervisor config (which can be changed through general system settings in HA Core) through the DBus API for setting the timezone. * Persist timezone also when it's been obtained from Whoami * Suppress pylint fixme error
This commit is contained in:
@@ -82,6 +82,24 @@ async def test_dbus_setntp(
|
||||
assert timedate.ntp is False
|
||||
|
||||
|
||||
async def test_dbus_set_timezone(
|
||||
timedate_service: TimeDateService, dbus_session_bus: MessageBus
|
||||
):
|
||||
"""Test setting of host timezone."""
|
||||
timedate_service.SetTimezone.calls.clear()
|
||||
timedate = TimeDate()
|
||||
|
||||
with pytest.raises(DBusNotConnectedError):
|
||||
await timedate.set_timezone("Europe/Prague")
|
||||
|
||||
await timedate.connect(dbus_session_bus)
|
||||
|
||||
assert await timedate.set_timezone("Europe/Prague") is None
|
||||
assert timedate_service.SetTimezone.calls == [("Europe/Prague", False)]
|
||||
await timedate_service.ping()
|
||||
assert timedate.timezone == "Europe/Prague"
|
||||
|
||||
|
||||
async def test_dbus_timedate_connect_error(
|
||||
dbus_session_bus: MessageBus, caplog: pytest.LogCaptureFixture
|
||||
):
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
"""Test host control."""
|
||||
|
||||
import pytest
|
||||
|
||||
from supervisor.coresys import CoreSys
|
||||
|
||||
from tests.dbus_service_mocks.base import DBusServiceMock
|
||||
from tests.dbus_service_mocks.hostname import Hostname as HostnameService
|
||||
from tests.dbus_service_mocks.timedate import TimeDate as TimeDateService
|
||||
|
||||
|
||||
async def test_set_hostname(
|
||||
@@ -20,3 +23,33 @@ async def test_set_hostname(
|
||||
assert hostname_service.SetStaticHostname.calls == [("test", False)]
|
||||
await hostname_service.ping()
|
||||
assert coresys.dbus.hostname.hostname == "test"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("os_available", ["16.2"], indirect=True)
|
||||
async def test_set_timezone(
|
||||
coresys: CoreSys,
|
||||
all_dbus_services: dict[str, DBusServiceMock | dict[str, DBusServiceMock]],
|
||||
os_available: str,
|
||||
):
|
||||
"""Test set timezone."""
|
||||
timedate_service: TimeDateService = all_dbus_services["timedate"]
|
||||
timedate_service.SetTimezone.calls.clear()
|
||||
|
||||
assert coresys.dbus.timedate.timezone == "Etc/UTC"
|
||||
|
||||
await coresys.host.control.set_timezone("Europe/Prague")
|
||||
assert timedate_service.SetTimezone.calls == [("Europe/Prague", False)]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("os_available", ["16.1"], indirect=True)
|
||||
async def test_set_timezone_unsupported(
|
||||
coresys: CoreSys,
|
||||
all_dbus_services: dict[str, DBusServiceMock | dict[str, DBusServiceMock]],
|
||||
os_available: str,
|
||||
):
|
||||
"""Test DBus call is not made when OS doesn't support it."""
|
||||
timedate_service: TimeDateService = all_dbus_services["timedate"]
|
||||
timedate_service.SetTimezone.calls.clear()
|
||||
|
||||
await coresys.host.control.set_timezone("Europe/Prague")
|
||||
assert timedate_service.SetTimezone.calls == []
|
||||
|
||||
@@ -83,6 +83,7 @@ async def test_adjust_system_datetime_if_time_behind(
|
||||
side_effect=[WhoamiData("Europe/Zurich", utc_ts)],
|
||||
) as mock_retrieve_whoami,
|
||||
patch.object(SystemControl, "set_datetime") as mock_set_datetime,
|
||||
patch.object(SystemControl, "set_timezone") as mock_set_timezone,
|
||||
patch.object(
|
||||
InfoCenter, "dt_synchronized", new=PropertyMock(return_value=False)
|
||||
),
|
||||
@@ -92,6 +93,21 @@ async def test_adjust_system_datetime_if_time_behind(
|
||||
mock_retrieve_whoami.assert_called_once()
|
||||
mock_set_datetime.assert_called_once()
|
||||
mock_check_connectivity.assert_called_once()
|
||||
mock_set_timezone.assert_called_once_with("Europe/Zurich")
|
||||
|
||||
|
||||
async def test_adjust_system_datetime_sync_timezone_to_host(
|
||||
coresys: CoreSys, websession: MagicMock
|
||||
):
|
||||
"""Test _adjust_system_datetime method syncs timezone to host when different."""
|
||||
await coresys.core.sys_config.set_timezone("Europe/Prague")
|
||||
|
||||
with (
|
||||
patch.object(SystemControl, "set_timezone") as mock_set_timezone,
|
||||
patch.object(InfoCenter, "timezone", new=PropertyMock(return_value="Etc/UTC")),
|
||||
):
|
||||
await coresys.core._adjust_system_datetime()
|
||||
mock_set_timezone.assert_called_once_with("Europe/Prague")
|
||||
|
||||
|
||||
async def test_write_state_failure(
|
||||
|
||||
Reference in New Issue
Block a user