Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose ZoneMinder availability to Home Assistant #18946

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions homeassistant/components/camera/zoneminder.py
Expand Up @@ -44,6 +44,7 @@ def __init__(self, monitor):
}
super().__init__(device_info)
self._is_recording = None
self._is_available = None
self._monitor = monitor

@property
Expand All @@ -55,8 +56,14 @@ def update(self):
"""Update our recording state from the ZM API."""
_LOGGER.debug("Updating camera state for monitor %i", self._monitor.id)
self._is_recording = self._monitor.is_recording
self._is_available = self._monitor.is_available

@property
def is_recording(self):
"""Return whether the monitor is in alarm mode."""
return self._is_recording

@property
def available(self):
"""Return True if entity is available."""
return self._is_available
16 changes: 15 additions & 1 deletion homeassistant/components/sensor/zoneminder.py
Expand Up @@ -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):
Expand All @@ -76,13 +77,19 @@ def state(self):
"""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
if not state:
self._state = None
else:
self._state = state.value
self._is_available = self._monitor.is_available


class ZMSensorEvents(Entity):
Expand Down Expand Up @@ -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
Expand All @@ -135,6 +143,12 @@ def state(self):
"""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
2 changes: 1 addition & 1 deletion homeassistant/components/zoneminder/__init__.py
Expand Up @@ -15,7 +15,7 @@

_LOGGER = logging.getLogger(__name__)

REQUIREMENTS = ['zm-py==0.1.0']
REQUIREMENTS = ['zm-py==0.2.0']

CONF_PATH_ZMS = 'path_zms'

Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Expand Up @@ -1679,4 +1679,4 @@ zigpy-xbee==0.1.1
zigpy==0.2.0

# homeassistant.components.zoneminder
zm-py==0.1.0
zm-py==0.2.0