Expose ZoneMinder availability to Home Assistant (#18946)

* Expose ZoneMinder availability to Home Assistant

* Bump zm-py to 0.2.0 with the availability changes published
This commit is contained in:
Rohan Kapoor authored and Martin Hjelmare committed 2018-12-14 08:10:54 +01:00
1 parent f60f9bae00
commit e8ec74b944
4 files changed
+24 -3

No files matched your search

+15 -1
View File
@@ -64,7 +64,8 @@ class ZMSensorMonitors(Entity):
def __init__(self, monitor):
"""Initialize monitor sensor."""
self._monitor = monitor
self._state = monitor.function.value
self._state = None
self._is_available = None
@property
def name(self):
@@ -76,6 +77,11 @@ class ZMSensorMonitors(Entity):
"""Return the state of the sensor."""
return self._state
@property
def available(self):
"""Return True if Monitor is available."""
return self._is_available
def update(self):
"""Update the sensor."""
state = self._monitor.function
@@ -83,6 +89,7 @@ class ZMSensorMonitors(Entity):
self._state = None
else:
self._state = state.value
self._is_available = self._monitor.is_available
class ZMSensorEvents(Entity):
@@ -123,6 +130,7 @@ class ZMSensorRunState(Entity):
def __init__(self, client):
"""Initialize run state sensor."""
self._state = None
self._is_available = None
self._client = client
@property
@@ -135,6 +143,12 @@ class ZMSensorRunState(Entity):
"""Return the state of the sensor."""
return self._state
@property
def available(self):
"""Return True if ZoneMinder is available."""
return self._is_available
def update(self):
"""Update the sensor."""
self._state = self._client.get_active_state()
self._is_available = self._client.is_available