Retry zoneminder connection setup (#107519)

* zoneminder setup retry connection

Makes ZM setup be async for enabling connection retry attempts

This also requires zm-py version bump v0.5.4 as that
dependency was patched in conjunction to resolve this issue

Closes #105271

Signed-off-by: Nic Boet <nic@boet.cc>

* ruff format

Signed-off-by: Nic Boet <nic@boet.cc>

* ruff fixes

Signed-off-by: Nic Boet <nic@boet.cc>

* RequestsConnectionError

Signed-off-by: Nic Boet <nic@boet.cc>

* revert async changes

Signed-off-by: Nic Boet <nic@boet.cc>

---------

Signed-off-by: Nic Boet <nic@boet.cc>
This commit is contained in:
nic 2024-01-08 13:30:44 -06:00 committed by GitHub
parent 4bb2a3ad92
commit e349608f92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 8 deletions

View File

@ -1,6 +1,7 @@
"""Support for ZoneMinder.""" """Support for ZoneMinder."""
import logging import logging
from requests.exceptions import ConnectionError as RequestsConnectionError
import voluptuous as vol import voluptuous as vol
from zoneminder.zm import ZoneMinder from zoneminder.zm import ZoneMinder
@ -75,7 +76,14 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
) )
hass.data[DOMAIN][host_name] = zm_client 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: def set_active_state(call: ServiceCall) -> None:
"""Set the ZoneMinder run state to the given state name.""" """Set the ZoneMinder run state to the given state name."""

View File

@ -8,6 +8,7 @@ from zoneminder.zm import ZoneMinder
from homeassistant.components.mjpeg import MjpegCamera, filter_urllib3_logging from homeassistant.components.mjpeg import MjpegCamera, filter_urllib3_logging
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import PlatformNotReady
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -28,8 +29,9 @@ def setup_platform(
zm_client: ZoneMinder zm_client: ZoneMinder
for zm_client in hass.data[ZONEMINDER_DOMAIN].values(): for zm_client in hass.data[ZONEMINDER_DOMAIN].values():
if not (monitors := zm_client.get_monitors()): if not (monitors := zm_client.get_monitors()):
_LOGGER.warning("Could not fetch monitors from ZoneMinder host: %s") raise PlatformNotReady(
return "Camera could not fetch any monitors from ZoneMinder"
)
for monitor in monitors: for monitor in monitors:
_LOGGER.info("Initializing camera %s", monitor.id) _LOGGER.info("Initializing camera %s", monitor.id)

View File

@ -5,5 +5,5 @@
"documentation": "https://www.home-assistant.io/integrations/zoneminder", "documentation": "https://www.home-assistant.io/integrations/zoneminder",
"iot_class": "local_polling", "iot_class": "local_polling",
"loggers": ["zoneminder"], "loggers": ["zoneminder"],
"requirements": ["zm-py==0.5.3"] "requirements": ["zm-py==0.5.4"]
} }

View File

@ -14,6 +14,7 @@ from homeassistant.components.sensor import (
) )
from homeassistant.const import CONF_MONITORED_CONDITIONS from homeassistant.const import CONF_MONITORED_CONDITIONS
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import PlatformNotReady
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -77,7 +78,9 @@ def setup_platform(
zm_client: ZoneMinder zm_client: ZoneMinder
for zm_client in hass.data[ZONEMINDER_DOMAIN].values(): for zm_client in hass.data[ZONEMINDER_DOMAIN].values():
if not (monitors := zm_client.get_monitors()): 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: for monitor in monitors:
sensors.append(ZMSensorMonitors(monitor)) sensors.append(ZMSensorMonitors(monitor))

View File

@ -11,6 +11,7 @@ from zoneminder.zm import ZoneMinder
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity
from homeassistant.const import CONF_COMMAND_OFF, CONF_COMMAND_ON from homeassistant.const import CONF_COMMAND_OFF, CONF_COMMAND_ON
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import PlatformNotReady
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -42,8 +43,9 @@ def setup_platform(
zm_client: ZoneMinder zm_client: ZoneMinder
for zm_client in hass.data[ZONEMINDER_DOMAIN].values(): for zm_client in hass.data[ZONEMINDER_DOMAIN].values():
if not (monitors := zm_client.get_monitors()): if not (monitors := zm_client.get_monitors()):
_LOGGER.warning("Could not fetch monitors from ZoneMinder") raise PlatformNotReady(
return "Switch could not fetch any monitors from ZoneMinder"
)
for monitor in monitors: for monitor in monitors:
switches.append(ZMSwitchMonitors(monitor, on_state, off_state)) switches.append(ZMSwitchMonitors(monitor, on_state, off_state))

View File

@ -2902,7 +2902,7 @@ zigpy-znp==0.12.1
zigpy==0.60.4 zigpy==0.60.4
# homeassistant.components.zoneminder # homeassistant.components.zoneminder
zm-py==0.5.3 zm-py==0.5.4
# homeassistant.components.zwave_js # homeassistant.components.zwave_js
zwave-js-server-python==0.55.3 zwave-js-server-python==0.55.3