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

Retry zoneminder connection setup #107519

Merged
merged 9 commits into from
Jan 8, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion homeassistant/components/zoneminder/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Support for ZoneMinder."""
import logging

from requests.exceptions import ConnectionError as RequestsConnectionError
import voluptuous as vol
from zoneminder.zm import ZoneMinder

Expand Down Expand Up @@ -75,7 +76,14 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
)
hass.data[DOMAIN][host_name] = zm_client

success = zm_client.login() and success
try:
success = zm_client.login() and success
except RequestsConnectionError as ex:
_LOGGER.error(
"ZoneMinder connection failure to %s: %s",
host_name,
ex,
)

def set_active_state(call: ServiceCall) -> None:
"""Set the ZoneMinder run state to the given state name."""
Expand Down
6 changes: 4 additions & 2 deletions homeassistant/components/zoneminder/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from homeassistant.components.mjpeg import MjpegCamera, filter_urllib3_logging
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import PlatformNotReady
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType

Expand All @@ -28,8 +29,9 @@ def setup_platform(
zm_client: ZoneMinder
for zm_client in hass.data[ZONEMINDER_DOMAIN].values():
if not (monitors := zm_client.get_monitors()):
_LOGGER.warning("Could not fetch monitors from ZoneMinder host: %s")
return
raise PlatformNotReady(
"Camera could not fetch any monitors from ZoneMinder"
)

for monitor in monitors:
_LOGGER.info("Initializing camera %s", monitor.id)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/zoneminder/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"documentation": "https://www.home-assistant.io/integrations/zoneminder",
"iot_class": "local_polling",
"loggers": ["zoneminder"],
"requirements": ["zm-py==0.5.3"]
"requirements": ["zm-py==0.5.4"]
}
5 changes: 4 additions & 1 deletion homeassistant/components/zoneminder/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
)
from homeassistant.const import CONF_MONITORED_CONDITIONS
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import PlatformNotReady
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
Expand Down Expand Up @@ -77,7 +78,9 @@ def setup_platform(
zm_client: ZoneMinder
for zm_client in hass.data[ZONEMINDER_DOMAIN].values():
if not (monitors := zm_client.get_monitors()):
_LOGGER.warning("Could not fetch any monitors from ZoneMinder")
raise PlatformNotReady(
"Sensor could not fetch any monitors from ZoneMinder"
)

for monitor in monitors:
sensors.append(ZMSensorMonitors(monitor))
Expand Down
6 changes: 4 additions & 2 deletions homeassistant/components/zoneminder/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity
from homeassistant.const import CONF_COMMAND_OFF, CONF_COMMAND_ON
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import PlatformNotReady
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
Expand Down Expand Up @@ -42,8 +43,9 @@ def setup_platform(
zm_client: ZoneMinder
for zm_client in hass.data[ZONEMINDER_DOMAIN].values():
if not (monitors := zm_client.get_monitors()):
_LOGGER.warning("Could not fetch monitors from ZoneMinder")
return
raise PlatformNotReady(
"Switch could not fetch any monitors from ZoneMinder"
)

for monitor in monitors:
switches.append(ZMSwitchMonitors(monitor, on_state, off_state))
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2902,7 +2902,7 @@ zigpy-znp==0.12.1
zigpy==0.60.4

# homeassistant.components.zoneminder
zm-py==0.5.3
zm-py==0.5.4

# homeassistant.components.zwave_js
zwave-js-server-python==0.55.3
Expand Down