core/homeassistant/components/binary_sensor/apcupsd.py

42 lines
1.3 KiB
Python
Raw Normal View History

2016-02-10 16:32:18 +00:00
"""
2016-03-07 19:21:08 +00:00
Support for tracking the online status of a UPS.
2016-02-12 06:54:25 +00:00
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/binary_sensor.apcupsd/
2016-02-10 16:32:18 +00:00
"""
from homeassistant.components import apcupsd
2016-02-19 05:27:50 +00:00
from homeassistant.components.binary_sensor import BinarySensorDevice
2016-02-10 16:32:18 +00:00
DEPENDENCIES = [apcupsd.DOMAIN]
DEFAULT_NAME = "UPS Online Status"
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Instantiate an OnlineStatus binary sensor entity."""
add_entities((OnlineStatus(config, apcupsd.DATA),))
2016-02-10 16:32:18 +00:00
class OnlineStatus(BinarySensorDevice):
2016-03-07 19:21:08 +00:00
"""Represent UPS online status."""
def __init__(self, config, data):
2016-03-07 19:21:08 +00:00
"""Initialize the APCUPSd device."""
2016-02-10 16:32:18 +00:00
self._config = config
self._data = data
2016-02-10 16:32:18 +00:00
self._state = None
self.update()
2016-02-10 16:32:18 +00:00
@property
def name(self):
2016-03-07 19:21:08 +00:00
"""Return the name of the UPS online status sensor."""
2016-02-10 16:32:18 +00:00
return self._config.get("name", DEFAULT_NAME)
@property
def is_on(self):
2016-03-07 19:21:08 +00:00
"""Return true if the UPS is online, else false."""
2016-02-10 16:32:18 +00:00
return self._state == apcupsd.VALUE_ONLINE
def update(self):
2016-03-07 19:21:08 +00:00
"""Get the status report from APCUPSd and set this entity's state."""
self._state = self._data.status[apcupsd.KEY_STATUS]