2016-02-10 16:32:18 +00:00
|
|
|
"""
|
|
|
|
homeassistant.components.binary_sensor.apcupsd
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
Provides a binary sensor to track online status of a UPS.
|
|
|
|
"""
|
|
|
|
from homeassistant.components.binary_sensor import BinarySensorDevice
|
|
|
|
from homeassistant.components import apcupsd
|
|
|
|
|
|
|
|
|
|
|
|
DEPENDENCIES = [apcupsd.DOMAIN]
|
|
|
|
|
|
|
|
DEFAULT_NAME = "UPS Online Status"
|
|
|
|
|
|
|
|
|
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
|
|
|
""" Instantiate an OnlineStatus binary sensor entity and add it to HA. """
|
2016-02-11 07:33:53 +00:00
|
|
|
add_entities((OnlineStatus(config, apcupsd.DATA),))
|
2016-02-10 16:32:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OnlineStatus(BinarySensorDevice):
|
|
|
|
""" Binary sensor to represent UPS online status. """
|
2016-02-11 07:33:53 +00:00
|
|
|
def __init__(self, config, data):
|
2016-02-10 16:32:18 +00:00
|
|
|
self._config = config
|
2016-02-11 07:33:53 +00:00
|
|
|
self._data = data
|
2016-02-10 16:32:18 +00:00
|
|
|
self._state = None
|
2016-02-11 07:33:53 +00:00
|
|
|
self.update()
|
2016-02-10 16:32:18 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
""" The name of the UPS online status sensor. """
|
|
|
|
return self._config.get("name", DEFAULT_NAME)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
""" True if the UPS is online, else False. """
|
|
|
|
return self._state == apcupsd.VALUE_ONLINE
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""
|
2016-02-11 07:33:53 +00:00
|
|
|
Get the status report from APCUPSd (or cache) and set this entity's
|
|
|
|
state.
|
2016-02-10 16:32:18 +00:00
|
|
|
"""
|
2016-02-11 07:33:53 +00:00
|
|
|
self._state = self._data.status[apcupsd.KEY_STATUS]
|