mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Use local IP to discover IGD device (#20035)
* Use local_ip from config to discover IGD device In case of multi-homed server UPNP discovery finds IGD device on some "default" interface. WIth this modification discovery will be performed from 'local_ip'. * Update device.py * Changed version of async_upnp_client in requirements * Used aysnc_upnp_client==0.14.0 * Changed requirement to async_upnp_client==0.14.0.dev0 * Changed requirement to async_upnp_client==0.14.0.dev0 * Changed requirement to async_upnp_client==0.14.0.dev0 * Fixed code style * Fixed code style * Changed version of async_upnp_client in requerements * Changed version of async_upnp_client in requirements * Regenerated requirements (new async_upnp_client) * Regenerated requirements (new async_upnp_client) * Changed requirement to async_upnp_client=0.14.1 * Changed requirement to async_upnp_client=0.14.1 * Updated requirements * Updated requirements.txt * Corrected requirements * Corrected import of DeviceState * Constants changed according new async_upnp_client * Upgraded for async_upnp_client==0.14.2
This commit is contained in:
committed by
Diogo Gomes
parent
8000b97180
commit
fb52f66da0
@@ -8,6 +8,7 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
|
||||
from .const import LOGGER as _LOGGER
|
||||
from .const import (DOMAIN, CONF_LOCAL_IP)
|
||||
|
||||
|
||||
class Device:
|
||||
@@ -22,15 +23,18 @@ class Device:
|
||||
async def async_discover(cls, hass: HomeAssistantType):
|
||||
"""Discovery UPNP/IGD devices."""
|
||||
_LOGGER.debug('Discovering UPnP/IGD devices')
|
||||
local_ip = hass.data[DOMAIN]['config'].get(CONF_LOCAL_IP)
|
||||
if local_ip:
|
||||
local_ip = IPv4Address(local_ip)
|
||||
|
||||
# discover devices
|
||||
from async_upnp_client.igd import IgdDevice
|
||||
discovery_infos = await IgdDevice.async_discover()
|
||||
from async_upnp_client.profiles.igd import IgdDevice
|
||||
discovery_infos = await IgdDevice.async_search(source_ip=local_ip)
|
||||
|
||||
# add extra info and store devices
|
||||
devices = []
|
||||
for discovery_info in discovery_infos:
|
||||
discovery_info['udn'] = discovery_info['usn'].split('::')[0]
|
||||
discovery_info['udn'] = discovery_info['_udn']
|
||||
discovery_info['ssdp_description'] = discovery_info['location']
|
||||
discovery_info['source'] = 'async_upnp_client'
|
||||
_LOGGER.debug('Discovered device: %s', discovery_info)
|
||||
@@ -56,7 +60,7 @@ class Device:
|
||||
upnp_device = await factory.async_create_device(ssdp_description)
|
||||
|
||||
# wrap with async_upnp_client.IgdDevice
|
||||
from async_upnp_client.igd import IgdDevice
|
||||
from async_upnp_client.profiles.igd import IgdDevice
|
||||
igd_device = IgdDevice(upnp_device, None)
|
||||
|
||||
return cls(igd_device)
|
||||
|
||||
Reference in New Issue
Block a user