Implement ZoneMinder run states (#17198)

This commit is contained in:
Rohan Kapoor 2018-10-11 00:38:31 -07:00 committed by Martin Hjelmare
parent 7e8973a315
commit d7cd1a2b4b
6 changed files with 49 additions and 5 deletions

View file

@ -385,7 +385,7 @@ omit =
homeassistant/components/zigbee.py
homeassistant/components/*/zigbee.py
homeassistant/components/zoneminder.py
homeassistant/components/zoneminder/*
homeassistant/components/*/zoneminder.py
homeassistant/components/tuya.py

View file

@ -233,7 +233,7 @@ homeassistant/components/*/xiaomi_aqara.py @danielhiversen @syssi
homeassistant/components/*/xiaomi_miio.py @rytilahti @syssi
# Z
homeassistant/components/zoneminder.py @rohankapoorcom
homeassistant/components/zoneminder/ @rohankapoorcom
homeassistant/components/*/zoneminder.py @rohankapoorcom
# Other code

View file

@ -54,6 +54,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
for sensor in config[CONF_MONITORED_CONDITIONS]:
sensors.append(ZMSensorEvents(monitor, include_archived, sensor))
sensors.append(ZMSensorRunState(zm_client))
add_entities(sensors)
@ -114,3 +115,26 @@ class ZMSensorEvents(Entity):
"""Update the sensor."""
self._state = self._monitor.get_events(
self.time_period, self._include_archived)
class ZMSensorRunState(Entity):
"""Get the ZoneMinder run state."""
def __init__(self, client):
"""Initialize run state sensor."""
self._state = None
self._client = client
@property
def name(self):
"""Return the name of the sensor."""
return 'Run State'
@property
def state(self):
"""Return the state of the sensor."""
return self._state
def update(self):
"""Update the sensor."""
self._state = self._client.get_active_state()

View file

@ -10,12 +10,12 @@ import voluptuous as vol
from homeassistant.const import (
CONF_HOST, CONF_PASSWORD, CONF_PATH, CONF_SSL, CONF_USERNAME,
CONF_VERIFY_SSL)
CONF_VERIFY_SSL, ATTR_NAME)
import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__)
REQUIREMENTS = ['zm-py==0.0.5']
REQUIREMENTS = ['zm-py==0.1.0']
CONF_PATH_ZMS = 'path_zms'
@ -38,6 +38,11 @@ CONFIG_SCHEMA = vol.Schema({
})
}, extra=vol.ALLOW_EXTRA)
SERVICE_SET_RUN_STATE = 'set_run_state'
SET_RUN_STATE_SCHEMA = vol.Schema({
vol.Required(ATTR_NAME): cv.string
})
def setup(hass, config):
"""Set up the ZoneMinder component."""
@ -57,4 +62,13 @@ def setup(hass, config):
conf.get(CONF_PATH_ZMS),
conf.get(CONF_VERIFY_SSL))
def set_active_state(call):
"""Set the ZoneMinder run state to the given state name."""
return hass.data[DOMAIN].set_active_state(call.data[ATTR_NAME])
hass.services.register(
DOMAIN, SERVICE_SET_RUN_STATE, set_active_state,
schema=SET_RUN_STATE_SCHEMA
)
return hass.data[DOMAIN].login()

View file

@ -0,0 +1,6 @@
set_run_state:
description: Set the ZoneMinder run state
fields:
name:
description: The string name of the ZoneMinder run state to set as active.
example: 'Home'

View file

@ -1594,4 +1594,4 @@ zigpy-xbee==0.1.1
zigpy==0.2.0
# homeassistant.components.zoneminder
zm-py==0.0.5
zm-py==0.1.0