diff --git a/custom_components/reolink_discovery/__init__.py b/custom_components/reolink_discovery/__init__.py index d89198a..87fc8cf 100644 --- a/custom_components/reolink_discovery/__init__.py +++ b/custom_components/reolink_discovery/__init__.py @@ -1,24 +1,18 @@ """Reolink Discovery Component""" -from dataclasses import asdict, dataclass, field -from datetime import datetime, timedelta +from dataclasses import asdict +from datetime import timedelta import logging -from typing import TYPE_CHECKING -from homeassistant.core import HomeAssistant, CALLBACK_TYPE, Event, callback +from homeassistant.core import HomeAssistant, CALLBACK_TYPE from homeassistant import config_entries from homeassistant.components.network import async_get_ipv4_broadcast_addresses -from homeassistant.util import dt +from homeassistant.helpers.discovery import discover +from homeassistant.helpers.discovery_flow import async_create_flow from homeassistant.helpers.event import async_track_time_interval +from homeassistant.components import dhcp from homeassistant.loader import async_get_custom_components -if TYPE_CHECKING: - from homeassistant.helpers import ( - discovery as helper_discovery, - discovery_flow as helper_discovery_flow, - ) -from ._utilities.hass_typing import hass_bound - from homeassistant.const import CONF_SCAN_INTERVAL from .typing import DiscoveredDevice @@ -105,7 +99,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: config_entries.ConfigEnt ) entry.async_on_unload(transport.close) - pinger = _Ping(hass, entry) + # pinger = + _Ping(hass, entry) return True @@ -127,13 +122,18 @@ def __init__( def discovered_device(self, device: DiscoveredDevice) -> None: super().discovered_device(device) + component: str = self.config_entry.options.get(CONF_COMPONENT, SUPPORTED_INTEGRATIONS[0]) data = asdict(device) - component: str = self.config_entry.options.get(CONF_COMPONENT, None) - discovery: helper_discovery = self.hass.helpers.discovery - hass_bound(discovery.discover)(DOMAIN, data, component, self._hass_config) - discovery_flow: helper_discovery_flow = self.hass.helpers.discovery_flow - hass_bound(discovery_flow.async_create_flow)( + async_create_flow( + self.hass, component, - {"source": config_entries.SOURCE_DISCOVERY, "provider": DOMAIN}, + {"source": config_entries.SOURCE_INTEGRATION_DISCOVERY, "provider": DOMAIN}, data, ) + discover(self.hass,DOMAIN, data, component, self._hass_config) + async_create_flow( + self.hass, + component, + {"source": config_entries.SOURCE_DHCP, "provider": DOMAIN}, + dhcp.DhcpServiceInfo(device.ip, device.name, device.mac), + ) diff --git a/custom_components/reolink_discovery/_utilities/__init__.py b/custom_components/reolink_discovery/_utilities/__init__.py deleted file mode 100644 index 5598760..0000000 --- a/custom_components/reolink_discovery/_utilities/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""Utilities""" diff --git a/custom_components/reolink_discovery/_utilities/hass_typing.py b/custom_components/reolink_discovery/_utilities/hass_typing.py deleted file mode 100644 index 5c9b602..0000000 --- a/custom_components/reolink_discovery/_utilities/hass_typing.py +++ /dev/null @@ -1,14 +0,0 @@ -"""Home Assistant Helpers/Components Typing Helpers""" - -from typing import Callable, Concatenate, ParamSpec -from typing_extensions import TypeVar - -from homeassistant.core import HomeAssistant - -_P = ParamSpec("_P") -_R = TypeVar("_R", infer_variance=True) - - -def hass_bound(func: Callable[Concatenate[HomeAssistant, _P], _R]) -> Callable[_P, _R]: - """return function bound through helper/components, for typing purposes only""" - return func diff --git a/custom_components/reolink_discovery/const.py b/custom_components/reolink_discovery/const.py index 7763fd0..02877fc 100644 --- a/custom_components/reolink_discovery/const.py +++ b/custom_components/reolink_discovery/const.py @@ -10,4 +10,4 @@ CONF_BROADCAST: Final = "broadcast_addr" CONF_COMPONENT: Final = "notify_component" -SUPPORTED_INTEGRATIONS: Final = ["reolink_rest"] +SUPPORTED_INTEGRATIONS: Final = ["reolink", "reolink_rest"] diff --git a/custom_components/reolink_discovery/manifest.json b/custom_components/reolink_discovery/manifest.json index 5c6c813..586a19b 100644 --- a/custom_components/reolink_discovery/manifest.json +++ b/custom_components/reolink_discovery/manifest.json @@ -3,7 +3,7 @@ "name": "Reolink Discovery", "documentation": "https://github.com/xannor/ha_reolink_discovery", "issue_tracker": "https://github.com/xannor/ha_reolink_discovery/issues", - "version": "1.1.2", + "version": "1.2.0", "iot_class": "local_polling", "dependencies": ["network"], "codeowners": ["@xannor"], diff --git a/developer.md b/developer.md index 2134a5d..f3d6fa4 100644 --- a/developer.md +++ b/developer.md @@ -1,5 +1,14 @@ Developer information +Update #3: + +Moved discovery config push to two places, async_step_integration_discovery and async_step_dhcp. + +Docs point to async_step_discovery being deprecated and the defaults for that and async_step_integration_discovery are the same so the change is simple (just rename the method and create a new functionn for async_step_discovery that calls the integration one) + +Added async_step_dhcp (and emulated dhcp push) to support the "official" ReoLink integration without code +changes to that integration. using async_step_integration_discovery is preferred. + Update #2: The discovery signal approach is still valid, but I also added config_flow push discovery as well.