Skip to content

Commit

Permalink
Minor fix, and lib bump
Browse files Browse the repository at this point in the history
  • Loading branch information
xannor committed Sep 15, 2022
1 parent 86091ce commit 5737b25
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
3 changes: 2 additions & 1 deletion custom_components/reolink_rest/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@

from async_reolink.api.errors import ReolinkResponseError

from async_reolink.api.typings import StreamTypes

from async_reolink.api.const import (
IntStreamTypes as StreamTypes,
DEFAULT_USERNAME,
DEFAULT_PASSWORD,
)
Expand Down
4 changes: 2 additions & 2 deletions custom_components/reolink_rest/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"name": "Reolink IP Device",
"documentation": "https://github.com/xannor/ha_reolink_rest",
"issue_tracker": "https://github.com/xannor/ha_reolink_rest/issues",
"version": "0.6.0",
"version": "0.6.1",
"iot_class": "local_polling",
"requirements": ["async-reolink.rest==0.6.0"],
"requirements": ["async-reolink.rest==0.6.1"],
"dependencies": ["camera"],
"after_dependencies": ["stream", "webhook", "reolink_discovery"],
"codeowners": ["@xannor"],
Expand Down
24 changes: 15 additions & 9 deletions custom_components/reolink_rest/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import base64
from dataclasses import asdict, dataclass
from datetime import timedelta, datetime
from enum import Enum
import hashlib

import logging
Expand All @@ -25,8 +26,6 @@
from homeassistant.helpers.singleton import singleton
from homeassistant.util import dt

from homeassistant.backports.enum import StrEnum

from homeassistant.const import CONF_HOST, CONF_USERNAME, CONF_PASSWORD

from async_reolink.api.const import DEFAULT_USERNAME, DEFAULT_PASSWORD
Expand All @@ -43,7 +42,7 @@
_LOGGER = logging.getLogger(__name__)


class _Namespaces(StrEnum):
class _Namespaces(str, Enum):

SOAP_ENV = "http://www.w3.org/2003/05/soap-envelope"
WSNT = "http://docs.oasis-open.org/wsn/b-2"
Expand Down Expand Up @@ -378,10 +377,17 @@ def _task():
self._renew_task = loop.call_later(delay, _task)

async def _process_subscription(
self, response: et.Element, entry_id: str, save: bool = True
self,
response: et.Element,
reference: str | None,
entry_id: str,
save: bool = True,
):
reference = _find(_Namespaces.WSNT.tag("SubscriptionReference"), response)
reference = _text(_find(_Namespaces.WSA.tag("Address"), reference), reference)
if reference is None:
reference = _find(_Namespaces.WSNT.tag("SubscriptionReference"), response)
reference = _text(
_find(_Namespaces.WSA.tag("Address"), reference), reference
)
time = _text(_find(_Namespaces.WSNT.tag("CurrentTime"), response))
expires = _text(_find(_Namespaces.WSNT.tag("TerminationTime"), response))
if not reference or not time:
Expand Down Expand Up @@ -455,7 +461,7 @@ async def _subscribe(
return None

response = response.find(f".//{_Namespaces.WSNT.tag('SubscribeResponse')}")
return await self._process_subscription(response, entry_id, save)
return await self._process_subscription(response, None, entry_id, save)

async def _renew(
self,
Expand Down Expand Up @@ -512,8 +518,8 @@ async def _renew(
self._handle_failed_subscription(url, entry_id, save)
return None

response = response.find(f".//{_Namespaces.WSNT.tag('SubscribeResponse')}")
return await self._process_subscription(response, entry_id, save)
response = response.find(f".//{_Namespaces.WSNT.tag('RenewResponse')}")
return await self._process_subscription(response, manager_url, entry_id, save)

async def _unsubscribe(self, entry_id: str, save: bool = True):
if entry_id == self._renew_id:
Expand Down

0 comments on commit 5737b25

Please sign in to comment.