Files
ha-core/homeassistant/components/poolsense/binary_sensor.py
Haemish Kyd 8a2b34cc09 Updates to poolsense integration (#37613)
* Created a binary sensor and corrected some review comments.

* Updated the poolsense class and its interface to handle credentials better

* Moved the client session to the PoolSense class.

* Apply suggestions from code review

* Update binary_sensor.py

* Update homeassistant/components/poolsense/__init__.py

* Update sensor.py

* Update binary_sensor.py

Co-authored-by: Chris Talkington <chris@talkingtontech.com>
2020-07-10 21:53:34 -05:00

68 lines
1.8 KiB
Python

"""Support for PoolSense binary sensors."""
import logging
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_PROBLEM,
BinarySensorEntity,
)
from homeassistant.const import CONF_EMAIL
from . import PoolSenseEntity
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
BINARY_SENSORS = {
"pH Status": {
"unit": None,
"icon": None,
"name": "pH Status",
"device_class": DEVICE_CLASS_PROBLEM,
},
"Chlorine Status": {
"unit": None,
"icon": None,
"name": "Chlorine Status",
"device_class": DEVICE_CLASS_PROBLEM,
},
}
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Defer sensor setup to the shared sensor module."""
coordinator = hass.data[DOMAIN][config_entry.entry_id]
binary_sensors_list = []
for binary_sensor in BINARY_SENSORS:
binary_sensors_list.append(
PoolSenseBinarySensor(
coordinator, config_entry.data[CONF_EMAIL], binary_sensor
)
)
async_add_entities(binary_sensors_list, False)
class PoolSenseBinarySensor(PoolSenseEntity, BinarySensorEntity):
"""Representation of PoolSense binary sensors."""
@property
def is_on(self):
"""Return true if the binary sensor is on."""
return self.coordinator.data[self.info_type] == "red"
@property
def icon(self):
"""Return the icon."""
return BINARY_SENSORS[self.info_type]["icon"]
@property
def device_class(self):
"""Return the class of this device."""
return BINARY_SENSORS[self.info_type]["device_class"]
@property
def name(self):
"""Return the name of the binary sensor."""
return f"PoolSense {BINARY_SENSORS[self.info_type]['name']}"