Adjust Plenticore switch initialisation (#78871)

This commit is contained in:
epenet 2022-09-21 11:54:14 +02:00 committed by GitHub
parent 1800e98f05
commit 9e31cf51cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -69,33 +69,28 @@ async def async_setup_entry(
timedelta(seconds=30), timedelta(seconds=30),
plenticore, plenticore,
) )
for switch in SWITCH_SETTINGS_DATA: for description in SWITCH_SETTINGS_DATA:
if switch.module_id not in available_settings_data or switch.key not in ( if (
setting.id for setting in available_settings_data[switch.module_id] description.module_id not in available_settings_data
or description.key
not in (
setting.id for setting in available_settings_data[description.module_id]
)
): ):
_LOGGER.debug( _LOGGER.debug(
"Skipping non existing setting data %s/%s", "Skipping non existing setting data %s/%s",
switch.module_id, description.module_id,
switch.key, description.key,
) )
continue continue
entities.append( entities.append(
PlenticoreDataSwitch( PlenticoreDataSwitch(
settings_data_update_coordinator, settings_data_update_coordinator,
description,
entry.entry_id, entry.entry_id,
entry.title, entry.title,
switch.module_id,
switch.key,
switch.name,
switch.is_on,
switch.on_value,
switch.on_label,
switch.off_value,
switch.off_label,
plenticore.device_info, plenticore.device_info,
f"{entry.title} {switch.name}",
f"{entry.entry_id}_{switch.module_id}_{switch.key}",
) )
) )
@ -106,38 +101,31 @@ class PlenticoreDataSwitch(CoordinatorEntity, SwitchEntity, ABC):
"""Representation of a Plenticore Switch.""" """Representation of a Plenticore Switch."""
_attr_entity_category = EntityCategory.CONFIG _attr_entity_category = EntityCategory.CONFIG
entity_description: PlenticoreSwitchEntityDescription
def __init__( def __init__(
self, self,
coordinator, coordinator: SettingDataUpdateCoordinator,
description: PlenticoreSwitchEntityDescription,
entry_id: str, entry_id: str,
platform_name: str, platform_name: str,
module_id: str,
data_id: str,
name: str | None,
is_on: str,
on_value: str,
on_label: str,
off_value: str,
off_label: str,
device_info: DeviceInfo, device_info: DeviceInfo,
attr_name: str, ) -> None:
attr_unique_id: str,
):
"""Create a new Switch Entity for Plenticore process data.""" """Create a new Switch Entity for Plenticore process data."""
super().__init__(coordinator) super().__init__(coordinator)
self.entity_description = description
self.entry_id = entry_id self.entry_id = entry_id
self.platform_name = platform_name self.platform_name = platform_name
self.module_id = module_id self.module_id = description.module_id
self.data_id = data_id self.data_id = description.key
self._name = name self._name = description.name
self._is_on = is_on self._is_on = description.is_on
self._attr_name = attr_name self._attr_name = f"{platform_name} {description.name}"
self.on_value = on_value self.on_value = description.on_value
self.on_label = on_label self.on_label = description.on_label
self.off_value = off_value self.off_value = description.off_value
self.off_label = off_label self.off_label = description.off_label
self._attr_unique_id = attr_unique_id self._attr_unique_id = f"{entry_id}_{description.module_id}_{description.key}"
self._device_info = device_info self._device_info = device_info