2019-02-13 20:21:14 +00:00
|
|
|
"""Support for ZoneMinder binary sensors."""
|
2020-09-12 18:21:57 +00:00
|
|
|
from homeassistant.components.binary_sensor import (
|
|
|
|
DEVICE_CLASS_CONNECTIVITY,
|
|
|
|
BinarySensorEntity,
|
|
|
|
)
|
2019-01-17 18:52:53 +00:00
|
|
|
|
2020-10-07 14:28:49 +00:00
|
|
|
from . import DOMAIN as ZONEMINDER_DOMAIN
|
2019-01-17 18:52:53 +00:00
|
|
|
|
|
|
|
|
2020-10-07 14:28:49 +00:00
|
|
|
async def async_setup_platform(hass, config, add_entities, discovery_info=None):
|
|
|
|
"""Set up the ZoneMinder binary sensor platform."""
|
|
|
|
sensors = []
|
|
|
|
for host_name, zm_client in hass.data[ZONEMINDER_DOMAIN].items():
|
|
|
|
sensors.append(ZMAvailabilitySensor(host_name, zm_client))
|
|
|
|
add_entities(sensors)
|
|
|
|
return True
|
2019-01-17 18:52:53 +00:00
|
|
|
|
|
|
|
|
2020-04-23 19:57:07 +00:00
|
|
|
class ZMAvailabilitySensor(BinarySensorEntity):
|
2019-01-17 18:52:53 +00:00
|
|
|
"""Representation of the availability of ZoneMinder as a binary sensor."""
|
|
|
|
|
2020-10-07 14:28:49 +00:00
|
|
|
def __init__(self, host_name, client):
|
2019-01-17 18:52:53 +00:00
|
|
|
"""Initialize availability sensor."""
|
|
|
|
self._state = None
|
2020-10-07 14:28:49 +00:00
|
|
|
self._name = host_name
|
2019-01-17 18:52:53 +00:00
|
|
|
self._client = client
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of this binary sensor."""
|
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return true if the binary sensor is on."""
|
|
|
|
return self._state
|
|
|
|
|
|
|
|
@property
|
|
|
|
def device_class(self):
|
|
|
|
"""Return the class of this device, from component DEVICE_CLASSES."""
|
2020-09-12 18:21:57 +00:00
|
|
|
return DEVICE_CLASS_CONNECTIVITY
|
2019-01-17 18:52:53 +00:00
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""Update the state of this sensor (availability of ZoneMinder)."""
|
|
|
|
self._state = self._client.is_available
|