Cleanup of Toon (#51230)

This commit is contained in:
Franck Nijhof 2021-06-07 13:24:07 +02:00 committed by GitHub
parent fb21affe45
commit 88386a7f44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 44 additions and 206 deletions

View file

@ -13,9 +13,7 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from .const import (
ATTR_DEFAULT_ENABLED,
ATTR_ICON,
ATTR_INVERTED,
ATTR_MEASUREMENT,
ATTR_NAME,
ATTR_SECTION,
@ -44,19 +42,12 @@ class ToonSwitch(ToonEntity, SwitchEntity):
def __init__(self, coordinator: ToonDataUpdateCoordinator, *, key: str) -> None:
"""Initialize the Toon switch."""
self.key = key
super().__init__(coordinator)
super().__init__(
coordinator,
enabled_default=SWITCH_ENTITIES[key][ATTR_DEFAULT_ENABLED],
icon=SWITCH_ENTITIES[key][ATTR_ICON],
name=SWITCH_ENTITIES[key][ATTR_NAME],
)
@property
def unique_id(self) -> str:
"""Return the unique ID for this binary sensor."""
agreement_id = self.coordinator.data.agreement.agreement_id
return f"{agreement_id}_{self.key}"
switch = SWITCH_ENTITIES[key]
self._attr_icon = switch[ATTR_ICON]
self._attr_name = switch[ATTR_NAME]
self._attr_unique_id = f"{coordinator.data.agreement.agreement_id}_{key}"
@property
def is_on(self) -> bool:
@ -64,12 +55,7 @@ class ToonSwitch(ToonEntity, SwitchEntity):
section = getattr(
self.coordinator.data, SWITCH_ENTITIES[self.key][ATTR_SECTION]
)
value = getattr(section, SWITCH_ENTITIES[self.key][ATTR_MEASUREMENT])
if SWITCH_ENTITIES[self.key][ATTR_INVERTED]:
return not value
return value
return getattr(section, SWITCH_ENTITIES[self.key][ATTR_MEASUREMENT])
class ToonProgramSwitch(ToonSwitch, ToonDisplayDeviceEntity):