Address venstar review comments (#59151)

* Address venstar review comments

* Apply review suggestions

* Address review suggestions
This commit is contained in:
Marvin Wichmann 2021-11-05 15:31:32 +01:00 committed by GitHub
parent c0801c1233
commit 6a0c1a78aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 18 deletions

View File

@ -19,7 +19,7 @@ from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import _LOGGER, DOMAIN, VENSTAR_TIMEOUT from .const import _LOGGER, DOMAIN, VENSTAR_TIMEOUT
PLATFORMS = ["climate", "binary_sensor"] PLATFORMS = ["binary_sensor", "climate"]
async def async_setup_entry(hass, config): async def async_setup_entry(hass, config):

View File

@ -14,12 +14,10 @@ async def async_setup_entry(hass, config_entry, async_add_entities) -> None:
if coordinator.client.alerts is None: if coordinator.client.alerts is None:
return return
sensors = [ async_add_entities(
VenstarBinarySensor(coordinator, config_entry, alert["name"]) VenstarBinarySensor(coordinator, config_entry, alert["name"])
for alert in coordinator.client.alerts for alert in coordinator.client.alerts
] )
async_add_entities(sensors, True)
class VenstarBinarySensor(VenstarEntity, BinarySensorEntity): class VenstarBinarySensor(VenstarEntity, BinarySensorEntity):
@ -31,19 +29,8 @@ class VenstarBinarySensor(VenstarEntity, BinarySensorEntity):
"""Initialize the alert.""" """Initialize the alert."""
super().__init__(coordinator, config) super().__init__(coordinator, config)
self.alert = alert self.alert = alert
self._config = config self._attr_unique_id = f"{config.entry_id}_{alert.replace(' ', '_')}"
self._unique_id = f"{self._config.entry_id}_{self.alert.replace(' ', '_')}" self._attr_name = f"{self._client.name} {alert}"
self._name = f"{self._client.name} {self.alert}"
@property
def unique_id(self):
"""Return the unique id."""
return self._unique_id
@property
def name(self):
"""Return the name of the device."""
return self._name
@property @property
def is_on(self): def is_on(self):
@ -51,3 +38,5 @@ class VenstarBinarySensor(VenstarEntity, BinarySensorEntity):
for alert in self._client.alerts: for alert in self._client.alerts:
if alert["name"] == self.alert: if alert["name"] == self.alert:
return alert["active"] return alert["active"]
return None