mirror of
https://github.com/home-assistant/core.git
synced 2026-09-26 17:31:15 -04:00
Add explicit device creation for DALI lines of lunatone (#180895)
This commit is contained in:
@@ -99,6 +99,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: LunatoneConfigEntry) ->
|
||||
assert entry.unique_id
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
|
||||
device_registry.async_get_or_create(
|
||||
config_entry_id=entry.entry_id,
|
||||
identifiers={(DOMAIN, entry.unique_id)},
|
||||
@@ -114,6 +115,29 @@ async def async_setup_entry(hass: HomeAssistant, entry: LunatoneConfigEntry) ->
|
||||
),
|
||||
)
|
||||
|
||||
for line_id, line_info in info_api.data.lines.items():
|
||||
line_unique_id = f"{entry.unique_id}-line{line_id}"
|
||||
|
||||
extra_info: dict = {}
|
||||
if line_info.device.serial != info_api.data.device.serial:
|
||||
extra_info.update(
|
||||
serial_number=str(line_info.device.serial),
|
||||
hw_version=line_info.device.pcb,
|
||||
model_id=(
|
||||
f"{line_info.device.article_number}{line_info.device.article_info}"
|
||||
),
|
||||
)
|
||||
|
||||
device_registry.async_get_or_create(
|
||||
config_entry_id=entry.entry_id,
|
||||
identifiers={(DOMAIN, line_unique_id)},
|
||||
name=f"DALI Line {line_id}",
|
||||
via_device_id=dr.async_get_device_id_by_identifier(
|
||||
hass, (DOMAIN, entry.unique_id), config_entry_id=entry.entry_id
|
||||
),
|
||||
**extra_info,
|
||||
)
|
||||
|
||||
devices_api = Devices(auth_api, info_api.data.version)
|
||||
coordinator_devices = LunatoneDevicesDataUpdateCoordinator(hass, entry, devices_api)
|
||||
await coordinator_devices.async_config_entry_first_refresh()
|
||||
|
||||
@@ -250,30 +250,9 @@ class LunatoneLineBroadcastLight(
|
||||
self._coordinator_info = coordinator_info
|
||||
self._broadcast = broadcast
|
||||
|
||||
line = broadcast.line
|
||||
|
||||
self._attr_unique_id = f"{config_entry_unique_id}-line{line}"
|
||||
|
||||
line_device = self._coordinator_info.data.lines[str(line)].device
|
||||
extra_info: dict = {}
|
||||
if line_device.serial != self._coordinator_info.data.device.serial:
|
||||
extra_info.update(
|
||||
serial_number=str(line_device.serial),
|
||||
hw_version=line_device.pcb,
|
||||
model_id=f"{line_device.article_number}{line_device.article_info}",
|
||||
)
|
||||
|
||||
assert self.unique_id
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, self.unique_id)},
|
||||
name=f"DALI Line {line}",
|
||||
via_device_id=dr.async_get_device_id_by_identifier(
|
||||
self.coordinator.hass,
|
||||
(DOMAIN, config_entry_unique_id),
|
||||
config_entry_id=self.coordinator.config_entry.entry_id,
|
||||
),
|
||||
**extra_info,
|
||||
)
|
||||
line_unique_id = f"{config_entry_unique_id}-line{broadcast.line}"
|
||||
self._attr_device_info = DeviceInfo(identifiers={(DOMAIN, line_unique_id)})
|
||||
self._attr_unique_id = line_unique_id
|
||||
|
||||
@override
|
||||
async def async_added_to_hass(self) -> None:
|
||||
|
||||
@@ -47,6 +47,13 @@ async def test_load_unload_config_entry(
|
||||
assert device_entry.configuration_url == BASE_URL
|
||||
assert device_entry.model == PRODUCT_NAME
|
||||
|
||||
for line_id in mock_lunatone_info.data.lines:
|
||||
device_entry = device_registry.async_get_device_by_identifier(
|
||||
(DOMAIN, f"{mock_config_entry.unique_id}-line{line_id}"),
|
||||
mock_config_entry.entry_id,
|
||||
)
|
||||
assert device_entry is not None
|
||||
|
||||
await hass.config_entries.async_unload(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
@@ -256,23 +256,6 @@ async def test_line_broadcast_available_status(
|
||||
assert state.state == "unavailable"
|
||||
|
||||
|
||||
async def test_line_broadcast_line_present(
|
||||
hass: HomeAssistant,
|
||||
mock_lunatone_info: AsyncMock,
|
||||
mock_lunatone_devices: AsyncMock,
|
||||
mock_lunatone_sensors: AsyncMock,
|
||||
mock_lunatone_scan: AsyncMock,
|
||||
mock_lunatone_dali_broadcast: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test if the broadcast light line is present."""
|
||||
mock_lunatone_dali_broadcast.line = None
|
||||
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
assert not hass.states.async_entity_ids("light")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"color_temp_kelvin",
|
||||
[10000, 5000, 1000],
|
||||
|
||||
Reference in New Issue
Block a user