Align Switcher cover platform with changes from light platform (#130094)

Switcher small fix for cover
This commit is contained in:
YogevBokobza
2024-11-08 02:59:30 +02:00
committed by GitHub
parent dac6271e01
commit 0d19e85a0d

View File

@@ -41,16 +41,20 @@ async def async_setup_entry(
def async_add_cover(coordinator: SwitcherDataUpdateCoordinator) -> None: def async_add_cover(coordinator: SwitcherDataUpdateCoordinator) -> None:
"""Add cover from Switcher device.""" """Add cover from Switcher device."""
entities: list[CoverEntity] = [] entities: list[CoverEntity] = []
if coordinator.data.device_type.category in ( if coordinator.data.device_type.category in (
DeviceCategory.SHUTTER, DeviceCategory.SHUTTER,
DeviceCategory.SINGLE_SHUTTER_DUAL_LIGHT, DeviceCategory.SINGLE_SHUTTER_DUAL_LIGHT,
DeviceCategory.DUAL_SHUTTER_SINGLE_LIGHT,
): ):
entities.append(SwitcherSingleCoverEntity(coordinator, 0)) number_of_covers = len(cast(SwitcherShutter, coordinator.data).position)
if ( if number_of_covers == 1:
coordinator.data.device_type.category entities.append(SwitcherSingleCoverEntity(coordinator, 0))
== DeviceCategory.DUAL_SHUTTER_SINGLE_LIGHT else:
): entities.extend(
entities.extend(SwitcherDualCoverEntity(coordinator, i) for i in range(2)) SwitcherMultiCoverEntity(coordinator, i)
for i in range(number_of_covers)
)
async_add_entities(entities) async_add_entities(entities)
config_entry.async_on_unload( config_entry.async_on_unload(
@@ -152,8 +156,8 @@ class SwitcherSingleCoverEntity(SwitcherBaseCoverEntity):
self._update_data() self._update_data()
class SwitcherDualCoverEntity(SwitcherBaseCoverEntity): class SwitcherMultiCoverEntity(SwitcherBaseCoverEntity):
"""Representation of a Switcher dual cover entity.""" """Representation of a Switcher multiple cover entity."""
_attr_translation_key = "cover" _attr_translation_key = "cover"