Refactor screenlogic API data selection (#49682)

This commit is contained in:
Kevin Worrel 2021-04-25 16:17:42 -07:00 committed by GitHub
parent 73b7a68e97
commit 6f1273cf1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 78 deletions

View file

@ -1,7 +1,7 @@
"""Support for a ScreenLogic Binary Sensor."""
import logging
from screenlogicpy.const import DEVICE_TYPE, ON_OFF
from screenlogicpy.const import DATA as SL_DATA, DEVICE_TYPE, ON_OFF
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_PROBLEM,
@ -19,16 +19,16 @@ SL_DEVICE_TYPE_TO_HA_DEVICE_CLASS = {DEVICE_TYPE.ALARM: DEVICE_CLASS_PROBLEM}
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up entry."""
entities = []
data = hass.data[DOMAIN][config_entry.entry_id]
coordinator = data["coordinator"]
coordinator = hass.data[DOMAIN][config_entry.entry_id]["coordinator"]
# Generic binary sensor
entities.append(ScreenLogicBinarySensor(coordinator, "chem_alarm"))
for binary_sensor in data["devices"]["binary_sensor"]:
entities.append(ScreenLogicBinarySensor(coordinator, binary_sensor))
async_add_entities(entities)
class ScreenLogicBinarySensor(ScreenlogicEntity, BinarySensorEntity):
"""Representation of a ScreenLogic binary sensor entity."""
"""Representation of the basic ScreenLogic binary sensor entity."""
@property
def name(self):
@ -49,4 +49,4 @@ class ScreenLogicBinarySensor(ScreenlogicEntity, BinarySensorEntity):
@property
def sensor(self):
"""Shortcut to access the sensor data."""
return self.coordinator.data["sensors"][self._data_key]
return self.coordinator.data[SL_DATA.KEY_SENSORS][self._data_key]