mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 08:07:45 +00:00
Add workaround for sub units without main device in AVM Fritz!SmartHome (#148507)
This commit is contained in:
parent
ce5f06b1e5
commit
8aaf5756e0
@ -171,14 +171,19 @@ class FritzboxDataUpdateCoordinator(DataUpdateCoordinator[FritzboxCoordinatorDat
|
|||||||
|
|
||||||
for device in new_data.devices.values():
|
for device in new_data.devices.values():
|
||||||
# create device registry entry for new main devices
|
# create device registry entry for new main devices
|
||||||
if (
|
if device.ain not in self.data.devices and (
|
||||||
device.ain not in self.data.devices
|
device.device_and_unit_id[1] is None
|
||||||
and device.device_and_unit_id[1] is None
|
or (
|
||||||
|
# workaround for sub units without a main device, e.g. Energy 250
|
||||||
|
# https://github.com/home-assistant/core/issues/145204
|
||||||
|
device.device_and_unit_id[1] == "1"
|
||||||
|
and device.device_and_unit_id[0] not in new_data.devices
|
||||||
|
)
|
||||||
):
|
):
|
||||||
dr.async_get(self.hass).async_get_or_create(
|
dr.async_get(self.hass).async_get_or_create(
|
||||||
config_entry_id=self.config_entry.entry_id,
|
config_entry_id=self.config_entry.entry_id,
|
||||||
name=device.name,
|
name=device.name,
|
||||||
identifiers={(DOMAIN, device.ain)},
|
identifiers={(DOMAIN, device.device_and_unit_id[0])},
|
||||||
manufacturer=device.manufacturer,
|
manufacturer=device.manufacturer,
|
||||||
model=device.productname,
|
model=device.productname,
|
||||||
sw_version=device.fw_version,
|
sw_version=device.fw_version,
|
||||||
|
@ -15,7 +15,12 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
from homeassistant.util.dt import utcnow
|
from homeassistant.util.dt import utcnow
|
||||||
|
|
||||||
from . import FritzDeviceCoverMock, FritzDeviceSwitchMock, FritzEntityBaseMock
|
from . import (
|
||||||
|
FritzDeviceCoverMock,
|
||||||
|
FritzDeviceSensorMock,
|
||||||
|
FritzDeviceSwitchMock,
|
||||||
|
FritzEntityBaseMock,
|
||||||
|
)
|
||||||
from .const import MOCK_CONFIG
|
from .const import MOCK_CONFIG
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||||
@ -140,3 +145,42 @@ async def test_coordinator_automatic_registry_cleanup(
|
|||||||
|
|
||||||
assert len(er.async_entries_for_config_entry(entity_registry, entry.entry_id)) == 12
|
assert len(er.async_entries_for_config_entry(entity_registry, entry.entry_id)) == 12
|
||||||
assert len(dr.async_entries_for_config_entry(device_registry, entry.entry_id)) == 1
|
assert len(dr.async_entries_for_config_entry(device_registry, entry.entry_id)) == 1
|
||||||
|
|
||||||
|
|
||||||
|
async def test_coordinator_workaround_sub_units_without_main_device(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
fritz: Mock,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
) -> None:
|
||||||
|
"""Test the workaround for sub units without main device."""
|
||||||
|
fritz().get_devices.return_value = [
|
||||||
|
FritzDeviceSensorMock(
|
||||||
|
ain="bad_device-1",
|
||||||
|
device_and_unit_id=("bad_device", "1"),
|
||||||
|
name="bad_sensor_sub",
|
||||||
|
),
|
||||||
|
FritzDeviceSensorMock(
|
||||||
|
ain="good_device",
|
||||||
|
device_and_unit_id=("good_device", None),
|
||||||
|
name="good_sensor",
|
||||||
|
),
|
||||||
|
FritzDeviceSensorMock(
|
||||||
|
ain="good_device-1",
|
||||||
|
device_and_unit_id=("good_device", "1"),
|
||||||
|
name="good_sensor_sub",
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
entry = MockConfigEntry(
|
||||||
|
domain=DOMAIN,
|
||||||
|
data=MOCK_CONFIG[DOMAIN][CONF_DEVICES][0],
|
||||||
|
unique_id="any",
|
||||||
|
)
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
await hass.async_block_till_done(wait_background_tasks=True)
|
||||||
|
|
||||||
|
device_entries = dr.async_entries_for_config_entry(device_registry, entry.entry_id)
|
||||||
|
assert len(device_entries) == 2
|
||||||
|
assert device_entries[0].identifiers == {(DOMAIN, "good_device")}
|
||||||
|
assert device_entries[1].identifiers == {(DOMAIN, "bad_device")}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user