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:
parent
8000b97180
commit
fb52f66da0
4 changed files with 17 additions and 13 deletions
|
@ -26,7 +26,7 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.util import get_local_ip
|
||||
|
||||
REQUIREMENTS = ['async-upnp-client==0.13.8']
|
||||
REQUIREMENTS = ['async-upnp-client==0.14.2']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -145,7 +145,7 @@ async def async_setup_platform(
|
|||
raise PlatformNotReady()
|
||||
|
||||
# wrap with DmrDevice
|
||||
from async_upnp_client.dlna import DmrDevice
|
||||
from async_upnp_client.profiles.dlna import DmrDevice
|
||||
dlna_device = DmrDevice(upnp_device, event_handler)
|
||||
|
||||
# create our own device
|
||||
|
@ -314,8 +314,8 @@ class DlnaDmrDevice(MediaPlayerDevice):
|
|||
await self._device.async_wait_for_can_play()
|
||||
|
||||
# If already playing, no need to call Play
|
||||
from async_upnp_client import dlna
|
||||
if self._device.state == dlna.STATE_PLAYING:
|
||||
from async_upnp_client.profiles.dlna import DeviceState
|
||||
if self._device.state == DeviceState.PLAYING:
|
||||
return
|
||||
|
||||
# Play it
|
||||
|
@ -355,12 +355,12 @@ class DlnaDmrDevice(MediaPlayerDevice):
|
|||
if not self._available:
|
||||
return STATE_OFF
|
||||
|
||||
from async_upnp_client import dlna
|
||||
from async_upnp_client.profiles.dlna import DeviceState
|
||||
if self._device.state is None:
|
||||
return STATE_ON
|
||||
if self._device.state == dlna.STATE_PLAYING:
|
||||
if self._device.state == DeviceState.PLAYING:
|
||||
return STATE_PLAYING
|
||||
if self._device.state == dlna.STATE_PAUSED:
|
||||
if self._device.state == DeviceState.PAUSED:
|
||||
return STATE_PAUSED
|
||||
|
||||
return STATE_IDLE
|
||||
|
|
|
@ -29,7 +29,7 @@ from .const import LOGGER as _LOGGER
|
|||
from .device import Device
|
||||
|
||||
|
||||
REQUIREMENTS = ['async-upnp-client==0.13.8']
|
||||
REQUIREMENTS = ['async-upnp-client==0.14.2']
|
||||
|
||||
NOTIFICATION_ID = 'upnp_notification'
|
||||
NOTIFICATION_TITLE = 'UPnP/IGD Setup'
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -164,7 +164,7 @@ asterisk_mbox==0.5.0
|
|||
|
||||
# homeassistant.components.upnp
|
||||
# homeassistant.components.media_player.dlna_dmr
|
||||
async-upnp-client==0.13.8
|
||||
async-upnp-client==0.14.2
|
||||
|
||||
# homeassistant.components.light.avion
|
||||
# avion==0.10
|
||||
|
|
Loading…
Add table
Reference in a new issue