hass-core/homeassistant/components/sleepiq/binary_sensor.py
cgtobi 2c07bfb9e0 Remove dependencies and requirements (#23024)
* Remove dependencies and requirements

* Revert "Remove dependencies and requirements"

This reverts commit fe7171b4cd.

* Remove dependencies and requirements

* Revert "Remove dependencies and requirements"

This reverts commit 391355ee2c.

* Remove dependencies and requirements

* Fix flake8 complaints

* Fix more flake8 complaints

* Revert non-component removals
2019-04-12 10:13:30 -07:00

45 lines
1.3 KiB
Python

"""Support for SleepIQ sensors."""
from homeassistant.components import sleepiq
from homeassistant.components.binary_sensor import BinarySensorDevice
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the SleepIQ sensors."""
if discovery_info is None:
return
data = sleepiq.DATA
data.update()
dev = list()
for bed_id, _ in data.beds.items():
for side in sleepiq.SIDES:
dev.append(IsInBedBinarySensor(data, bed_id, side))
add_entities(dev)
class IsInBedBinarySensor(sleepiq.SleepIQSensor, BinarySensorDevice):
"""Implementation of a SleepIQ presence sensor."""
def __init__(self, sleepiq_data, bed_id, side):
"""Initialize the sensor."""
sleepiq.SleepIQSensor.__init__(self, sleepiq_data, bed_id, side)
self.type = sleepiq.IS_IN_BED
self._state = None
self._name = sleepiq.SENSOR_TYPES[self.type]
self.update()
@property
def is_on(self):
"""Return the status of the sensor."""
return self._state is True
@property
def device_class(self):
"""Return the class of this sensor."""
return "occupancy"
def update(self):
"""Get the latest data from SleepIQ and updates the states."""
sleepiq.SleepIQSensor.update(self)
self._state = self.side.is_in_bed