mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Cleanups related to improved typing on radios objects (#141455)
* Improved handling of radio objects * Drop get_radio helper * Remove mock of get_radio in tests
This commit is contained in:
parent
043603c9be
commit
57d02d7a17
@ -2,7 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pysmlight import Api2, Info, Radio
|
||||
from pysmlight import Api2
|
||||
|
||||
from homeassistant.const import CONF_HOST, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
@ -50,9 +50,3 @@ async def async_setup_entry(hass: HomeAssistant, entry: SmConfigEntry) -> bool:
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: SmConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
|
||||
def get_radio(info: Info, idx: int) -> Radio:
|
||||
"""Get the radio object from the info."""
|
||||
assert info.radios is not None
|
||||
return info.radios[idx]
|
||||
|
@ -22,7 +22,6 @@ from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from . import get_radio
|
||||
from .const import LOGGER
|
||||
from .coordinator import SmConfigEntry, SmFirmwareUpdateCoordinator, SmFwData
|
||||
from .entity import SmEntity
|
||||
@ -56,7 +55,7 @@ CORE_UPDATE_ENTITY = SmUpdateEntityDescription(
|
||||
ZB_UPDATE_ENTITY = SmUpdateEntityDescription(
|
||||
key="zigbee_update",
|
||||
translation_key="zigbee_update",
|
||||
installed_version=lambda x, idx: get_radio(x, idx).zb_version,
|
||||
installed_version=lambda x, idx: x.radios[idx].zb_version,
|
||||
latest_version=zigbee_latest_version,
|
||||
)
|
||||
|
||||
@ -75,7 +74,6 @@ async def async_setup_entry(
|
||||
|
||||
entities = [SmUpdateEntity(coordinator, CORE_UPDATE_ENTITY)]
|
||||
radios = coordinator.data.info.radios
|
||||
assert radios is not None
|
||||
|
||||
entities.extend(
|
||||
SmUpdateEntity(coordinator, ZB_UPDATE_ENTITY, idx)
|
||||
|
@ -154,10 +154,9 @@ async def test_update_zigbee2_firmware(
|
||||
mock_smlight_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test update of zigbee2 firmware where available."""
|
||||
mock_info = Info.from_dict(load_json_object_fixture("info-MR1.json", DOMAIN))
|
||||
mock_smlight_client.get_info.side_effect = None
|
||||
mock_smlight_client.get_info.return_value = Info.from_dict(
|
||||
load_json_object_fixture("info-MR1.json", DOMAIN)
|
||||
)
|
||||
mock_smlight_client.get_info.return_value = mock_info
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
entity_id = "update.mock_title_zigbee_firmware_2"
|
||||
state = hass.states.get(entity_id)
|
||||
@ -177,9 +176,9 @@ async def test_update_zigbee2_firmware(
|
||||
event_function = get_mock_event_function(mock_smlight_client, SmEvents.FW_UPD_done)
|
||||
|
||||
event_function(MOCK_FIRMWARE_DONE)
|
||||
with patch(
|
||||
"homeassistant.components.smlight.update.get_radio", return_value=MOCK_RADIO
|
||||
):
|
||||
|
||||
mock_info.radios[1] = MOCK_RADIO
|
||||
|
||||
freezer.tick(timedelta(seconds=5))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
Loading…
x
Reference in New Issue
Block a user