Push country config to Supervisor (#143871)

This commit is contained in:
Stefan Agner 2025-04-30 18:02:18 +02:00 committed by GitHub
parent daf143f66e
commit f1b8c8855e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 15 additions and 10 deletions

View File

@ -385,18 +385,20 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
) )
last_timezone = None last_timezone = None
last_country = None
async def push_config(_: Event | None) -> None: async def push_config(_: Event | None) -> None:
"""Push core config to Hass.io.""" """Push core config to Hass.io."""
nonlocal last_timezone nonlocal last_timezone
nonlocal last_country
new_timezone = str(hass.config.time_zone) new_timezone = str(hass.config.time_zone)
new_country = str(hass.config.country)
if new_timezone == last_timezone: if new_timezone != last_timezone or new_country != last_country:
return last_timezone = new_timezone
last_country = new_country
last_timezone = new_timezone await hassio.update_hass_config(new_timezone, new_country)
await hassio.update_hass_timezone(new_timezone)
hass.bus.async_listen(EVENT_CORE_CONFIG_UPDATE, push_config) hass.bus.async_listen(EVENT_CORE_CONFIG_UPDATE, push_config)

View File

@ -248,12 +248,14 @@ class HassIO:
return await self.send_command("/homeassistant/options", payload=options) return await self.send_command("/homeassistant/options", payload=options)
@_api_bool @_api_bool
def update_hass_timezone(self, timezone: str) -> Coroutine: def update_hass_config(self, timezone: str, country: str | None) -> Coroutine:
"""Update Home-Assistant timezone data on Hass.io. """Update Home-Assistant timezone data on Hass.io.
This method returns a coroutine. This method returns a coroutine.
""" """
return self.send_command("/supervisor/options", payload={"timezone": timezone}) return self.send_command(
"/supervisor/options", payload={"timezone": timezone, "country": country}
)
@_api_bool @_api_bool
def update_diagnostics(self, diagnostics: bool) -> Coroutine: def update_diagnostics(self, diagnostics: bool) -> Coroutine:

View File

@ -404,7 +404,7 @@ async def test_setup_api_existing_hassio_user(
assert aioclient_mock.mock_calls[0][2]["refresh_token"] == token.token assert aioclient_mock.mock_calls[0][2]["refresh_token"] == token.token
async def test_setup_core_push_timezone( async def test_setup_core_push_config(
hass: HomeAssistant, hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker, aioclient_mock: AiohttpClientMocker,
supervisor_client: AsyncMock, supervisor_client: AsyncMock,
@ -421,9 +421,10 @@ async def test_setup_core_push_timezone(
assert aioclient_mock.mock_calls[1][2]["timezone"] == "testzone" assert aioclient_mock.mock_calls[1][2]["timezone"] == "testzone"
with patch("homeassistant.util.dt.set_default_time_zone"): with patch("homeassistant.util.dt.set_default_time_zone"):
await hass.config.async_update(time_zone="America/New_York") await hass.config.async_update(time_zone="America/New_York", country="US")
await hass.async_block_till_done() await hass.async_block_till_done()
assert aioclient_mock.mock_calls[-1][2]["timezone"] == "America/New_York" assert aioclient_mock.mock_calls[-1][2]["timezone"] == "America/New_York"
assert aioclient_mock.mock_calls[-1][2]["country"] == "US"
async def test_setup_hassio_no_additional_data( async def test_setup_hassio_no_additional_data(

View File

@ -1942,7 +1942,7 @@ async def hassio_stubs(
return_value={"result": "ok"}, return_value={"result": "ok"},
) as hass_api, ) as hass_api,
patch( patch(
"homeassistant.components.hassio.HassIO.update_hass_timezone", "homeassistant.components.hassio.HassIO.update_hass_config",
return_value={"result": "ok"}, return_value={"result": "ok"},
), ),
patch( patch(