hass-core/homeassistant/components/screenlogic/binary_sensor.py
Kevin Worrel fb48fd7d10
ScreenLogic cleanups (#48136)
* ScreenLogic cleanup.
Bump screenlogicpy to 0.2.0.
Move heating functions from water_heater to climate platform.
Address notes from original PR.

* Fix temperature attribute

* Addressing notes.
Bump screenlogicpy to 0.2.1.
Made device_types constants.
Made (known) equipment flags constants.
Used dict.get() in places where None is the default.
Return fast with good _last_preset.

* Update homeassistant/components/screenlogic/climate.py

Let base entity handle state property.

Co-authored-by: J. Nick Koston <nick@koston.org>

* Patch integration setup functions.

* Exception, ATTR_TEMPERATURE notes

Co-authored-by: J. Nick Koston <nick@koston.org>
2021-03-21 11:56:46 +01:00

52 lines
1.5 KiB
Python

"""Support for a ScreenLogic Binary Sensor."""
import logging
from screenlogicpy.const import DEVICE_TYPE, ON_OFF
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_PROBLEM,
BinarySensorEntity,
)
from . import ScreenlogicEntity
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
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"]
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."""
@property
def name(self):
"""Return the sensor name."""
return f"{self.gateway_name} {self.sensor['name']}"
@property
def device_class(self):
"""Return the device class."""
device_class = self.sensor.get("device_type")
return SL_DEVICE_TYPE_TO_HA_DEVICE_CLASS.get(device_class)
@property
def is_on(self) -> bool:
"""Determine if the sensor is on."""
return self.sensor["value"] == ON_OFF.ON
@property
def sensor(self):
"""Shortcut to access the sensor data."""
return self.coordinator.data["sensors"][self._data_key]