Add a Zoneminder availability sensor (#20184)
* Embed zoneminder platforms into component * Add a binary sensor for ZoneMinder availability * Lint * Add missing docstringspull/20196/head
parent
0fe5d567a2
commit
5232df34cb
|
@ -12,6 +12,7 @@ import homeassistant.helpers.config_validation as cv
|
|||
from homeassistant.const import (
|
||||
CONF_HOST, CONF_PASSWORD, CONF_PATH, CONF_SSL, CONF_USERNAME,
|
||||
CONF_VERIFY_SSL, ATTR_NAME, ATTR_ID)
|
||||
from homeassistant.helpers.discovery import async_load_platform
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -93,4 +94,8 @@ def setup(hass, config):
|
|||
schema=SET_RUN_STATE_SCHEMA
|
||||
)
|
||||
|
||||
hass.async_create_task(
|
||||
async_load_platform(hass, 'binary_sensor', DOMAIN, {}, config)
|
||||
)
|
||||
|
||||
return success
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
"""
|
||||
Support for ZoneMinder Binary Sensor.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/binary_sensor.zoneminder/
|
||||
"""
|
||||
from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||
|
||||
from homeassistant.components.zoneminder import DOMAIN as ZONEMINDER_DOMAIN
|
||||
|
||||
DEPENDENCIES = ['zoneminder']
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
class ZMAvailabilitySensor(BinarySensorDevice):
|
||||
"""Representation of the availability of ZoneMinder as a binary sensor."""
|
||||
|
||||
def __init__(self, host_name, client):
|
||||
"""Initialize availability sensor."""
|
||||
self._state = None
|
||||
self._name = host_name
|
||||
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."""
|
||||
return 'connectivity'
|
||||
|
||||
def update(self):
|
||||
"""Update the state of this sensor (availability of ZoneMinder)."""
|
||||
self._state = self._client.is_available
|
Loading…
Reference in New Issue