mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Fix onvif binary sensors (#90202)
* Fix httpx client creating a new ssl context with each client While working on https://github.com/home-assistant/core/issues/83524 it was discovered that each new httpx client creates a new ssl contextf1157dbc41/httpx/_transports/default.py (L261)
If an ssl context is passed in creating a new one is avoided heref1157dbc41/httpx/_config.py (L110)
This change makes httpx ssl no-verify behavior match aiohttp ssl no-verify behavior6da04694fd/aiohttp/connector.py (L892)
aiohttp solved this by wrapping the code that generates the ssl context in an lru_cache * compact * Fix onvif binary sensors fixes #83524 needs https://github.com/hunterjm/python-onvif-zeep-async/pull/9 first to avoid recreating the memory leak * Fix memory leak in onvif Work around until https://github.com/hunterjm/python-onvif-zeep-async/pull/9 followup to https://github.com/home-assistant/core/pull/83006 * move check * onvif-zeep-async 1.2.2 * fix unloading
This commit is contained in:
parent
bd08d88812
commit
0b8fb36a7e
@ -27,6 +27,13 @@ SUBSCRIPTION_ERRORS = (
|
||||
)
|
||||
|
||||
|
||||
def _stringify_onvif_error(error: Exception) -> str:
|
||||
"""Stringify ONVIF error."""
|
||||
if isinstance(error, Fault):
|
||||
return error.message or str(error) or "Device sent empty error"
|
||||
return str(error)
|
||||
|
||||
|
||||
class EventManager:
|
||||
"""ONVIF Event Manager."""
|
||||
|
||||
@ -79,7 +86,9 @@ class EventManager:
|
||||
|
||||
async def async_start(self) -> bool:
|
||||
"""Start polling events."""
|
||||
if await self.device.create_pullpoint_subscription():
|
||||
if not await self.device.create_pullpoint_subscription():
|
||||
return False
|
||||
|
||||
# Create subscription manager
|
||||
self._subscription = self.device.create_subscription_service(
|
||||
"PullPointSubscription"
|
||||
@ -102,8 +111,6 @@ class EventManager:
|
||||
self.started = True
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
async def async_stop(self) -> None:
|
||||
"""Unsubscribe from events."""
|
||||
self._listeners = []
|
||||
@ -112,6 +119,7 @@ class EventManager:
|
||||
if not self._subscription:
|
||||
return
|
||||
|
||||
with suppress(*SUBSCRIPTION_ERRORS):
|
||||
await self._subscription.Unsubscribe()
|
||||
self._subscription = None
|
||||
|
||||
@ -148,7 +156,7 @@ class EventManager:
|
||||
"Retrying later: %s"
|
||||
),
|
||||
self.unique_id,
|
||||
err,
|
||||
_stringify_onvif_error(err),
|
||||
)
|
||||
|
||||
if not restarted:
|
||||
@ -170,6 +178,10 @@ class EventManager:
|
||||
.isoformat(timespec="seconds")
|
||||
.replace("+00:00", "Z")
|
||||
)
|
||||
with suppress(*SUBSCRIPTION_ERRORS):
|
||||
# The first time we renew, we may get a Fault error so we
|
||||
# suppress it. The subscription will be restarted in
|
||||
# async_restart later.
|
||||
await self._subscription.Renew(termination_time)
|
||||
|
||||
def async_schedule_pull(self) -> None:
|
||||
@ -203,7 +215,7 @@ class EventManager:
|
||||
" '%s': %s"
|
||||
),
|
||||
self.unique_id,
|
||||
err,
|
||||
_stringify_onvif_error(err),
|
||||
)
|
||||
# Treat errors as if the camera restarted. Assume that the pullpoint
|
||||
# subscription is no longer valid.
|
||||
|
Loading…
x
Reference in New Issue
Block a user