Skip to content

Commit

Permalink
Added support for built in ReoLink integration.
Browse files Browse the repository at this point in the history
  • Loading branch information
xannor committed Mar 7, 2023
1 parent d60b460 commit f4d3ed4
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 36 deletions.
38 changes: 19 additions & 19 deletions custom_components/reolink_discovery/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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),
)
1 change: 0 additions & 1 deletion custom_components/reolink_discovery/_utilities/__init__.py

This file was deleted.

14 changes: 0 additions & 14 deletions custom_components/reolink_discovery/_utilities/hass_typing.py

This file was deleted.

2 changes: 1 addition & 1 deletion custom_components/reolink_discovery/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion custom_components/reolink_discovery/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
9 changes: 9 additions & 0 deletions developer.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit f4d3ed4

Please sign in to comment.