Skip to content

Commit

Permalink
Bump ZHA library to 0.0.29 (home-assistant#123464)
Browse files Browse the repository at this point in the history
* Bump zha to 0.0.29

* Pass the Core timezone to ZHA

* Add a unit test
  • Loading branch information
puddly authored Aug 9, 2024
1 parent e6e985a commit 9741047
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 6 deletions.
19 changes: 17 additions & 2 deletions homeassistant/components/zha/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import contextlib
import logging
from zoneinfo import ZoneInfo

import voluptuous as vol
from zha.application.const import BAUD_RATES, RadioType
Expand All @@ -12,8 +13,13 @@
from zigpy.exceptions import NetworkSettingsInconsistent, TransientConnectionError

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_TYPE, EVENT_HOMEASSISTANT_STOP, Platform
from homeassistant.core import Event, HomeAssistant
from homeassistant.const import (
CONF_TYPE,
EVENT_CORE_CONFIG_UPDATE,
EVENT_HOMEASSISTANT_STOP,
Platform,
)
from homeassistant.core import Event, HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryError, ConfigEntryNotReady
from homeassistant.helpers import device_registry as dr
import homeassistant.helpers.config_validation as cv
Expand Down Expand Up @@ -204,6 +210,15 @@ async def async_shutdown(_: Event) -> None:
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, async_shutdown)
)

@callback
def update_config(event: Event) -> None:
"""Handle Core config update."""
zha_gateway.config.local_timezone = ZoneInfo(hass.config.time_zone)

config_entry.async_on_unload(
hass.bus.async_listen(EVENT_CORE_CONFIG_UPDATE, update_config)
)

await ha_zha_data.gateway_proxy.async_initialize_devices_and_entities()
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
async_dispatcher_send(hass, SIGNAL_ADD_ENTITIES)
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/zha/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import time
from types import MappingProxyType
from typing import TYPE_CHECKING, Any, Concatenate, NamedTuple, ParamSpec, TypeVar, cast
from zoneinfo import ZoneInfo

import voluptuous as vol
from zha.application.const import (
Expand Down Expand Up @@ -1273,6 +1274,7 @@ def create_zha_config(hass: HomeAssistant, ha_zha_data: HAZHAData) -> ZHAData:
quirks_configuration=quirks_config,
device_overrides=overrides_config,
),
local_timezone=ZoneInfo(hass.config.time_zone),
)


Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/zha/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"zha",
"universal_silabs_flasher"
],
"requirements": ["universal-silabs-flasher==0.0.22", "zha==0.0.28"],
"requirements": ["universal-silabs-flasher==0.0.22", "zha==0.0.29"],
"usb": [
{
"vid": "10C4",
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2989,7 +2989,7 @@ zeroconf==0.132.2
zeversolar==0.3.1

# homeassistant.components.zha
zha==0.0.28
zha==0.0.29

# homeassistant.components.zhong_hong
zhong-hong-hvac==1.0.12
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2366,7 +2366,7 @@ zeroconf==0.132.2
zeversolar==0.3.1

# homeassistant.components.zha
zha==0.0.28
zha==0.0.29

# homeassistant.components.zwave_js
zwave-js-server-python==0.57.0
Expand Down
23 changes: 22 additions & 1 deletion tests/components/zha/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import asyncio
import typing
from unittest.mock import AsyncMock, Mock, patch
import zoneinfo

import pytest
from zigpy.application import ControllerApplication
Expand All @@ -16,7 +17,7 @@
CONF_USB_PATH,
DOMAIN,
)
from homeassistant.components.zha.helpers import get_zha_data
from homeassistant.components.zha.helpers import get_zha_data, get_zha_gateway
from homeassistant.const import (
EVENT_HOMEASSISTANT_STOP,
MAJOR_VERSION,
Expand Down Expand Up @@ -288,3 +289,23 @@ async def test_shutdown_on_ha_stop(
await hass.async_block_till_done()

assert len(mock_shutdown.mock_calls) == 1


async def test_timezone_update(
hass: HomeAssistant,
config_entry: MockConfigEntry,
mock_zigpy_connect: ControllerApplication,
) -> None:
"""Test that the ZHA gateway timezone is updated when HA timezone changes."""
config_entry.add_to_hass(hass)

await hass.config_entries.async_setup(config_entry.entry_id)
gateway = get_zha_gateway(hass)

assert hass.config.time_zone == "US/Pacific"
assert gateway.config.local_timezone == zoneinfo.ZoneInfo("US/Pacific")

await hass.config.async_update(time_zone="America/New_York")

assert hass.config.time_zone == "America/New_York"
assert gateway.config.local_timezone == zoneinfo.ZoneInfo("America/New_York")

0 comments on commit 9741047

Please sign in to comment.