mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Adds option in UPnP component to override callback url (#21583)
* Add option to override callback url * Upgrade to async_upnp_client==0.14.5 * Fix requirements_all.txt
This commit is contained in:
parent
17c3c14833
commit
3ffff887d8
@ -9,6 +9,7 @@ from datetime import datetime
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import functools
|
import functools
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
@ -22,13 +23,13 @@ from homeassistant.components.media_player.const import (
|
|||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_NAME, CONF_URL, EVENT_HOMEASSISTANT_STOP, STATE_IDLE, STATE_OFF,
|
CONF_NAME, CONF_URL, EVENT_HOMEASSISTANT_STOP, STATE_IDLE, STATE_OFF,
|
||||||
STATE_ON, STATE_PAUSED, STATE_PLAYING)
|
STATE_ON, STATE_PAUSED, STATE_PLAYING)
|
||||||
from homeassistant.core import HomeAssistant
|
|
||||||
from homeassistant.exceptions import PlatformNotReady
|
from homeassistant.exceptions import PlatformNotReady
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
|
from homeassistant.helpers.typing import HomeAssistantType
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.util import get_local_ip
|
from homeassistant.util import get_local_ip
|
||||||
|
|
||||||
REQUIREMENTS = ['async-upnp-client==0.14.4']
|
REQUIREMENTS = ['async-upnp-client==0.14.5']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -39,12 +40,14 @@ DEFAULT_LISTEN_PORT = 8301
|
|||||||
|
|
||||||
CONF_LISTEN_IP = 'listen_ip'
|
CONF_LISTEN_IP = 'listen_ip'
|
||||||
CONF_LISTEN_PORT = 'listen_port'
|
CONF_LISTEN_PORT = 'listen_port'
|
||||||
|
CONF_CALLBACK_URL_OVERRIDE = 'callback_url_override'
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Required(CONF_URL): cv.string,
|
vol.Required(CONF_URL): cv.string,
|
||||||
vol.Optional(CONF_LISTEN_IP): cv.string,
|
vol.Optional(CONF_LISTEN_IP): cv.string,
|
||||||
vol.Optional(CONF_LISTEN_PORT, default=DEFAULT_LISTEN_PORT): cv.port,
|
vol.Optional(CONF_LISTEN_PORT, default=DEFAULT_LISTEN_PORT): cv.port,
|
||||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||||
|
vol.Optional(CONF_CALLBACK_URL_OVERRIDE): cv.url,
|
||||||
})
|
})
|
||||||
|
|
||||||
HOME_ASSISTANT_UPNP_CLASS_MAPPING = {
|
HOME_ASSISTANT_UPNP_CLASS_MAPPING = {
|
||||||
@ -82,7 +85,12 @@ def catch_request_errors():
|
|||||||
return call_wrapper
|
return call_wrapper
|
||||||
|
|
||||||
|
|
||||||
async def async_start_event_handler(hass, server_host, server_port, requester):
|
async def async_start_event_handler(
|
||||||
|
hass: HomeAssistantType,
|
||||||
|
server_host: str,
|
||||||
|
server_port: int,
|
||||||
|
requester,
|
||||||
|
callback_url_override: Optional[str] = None):
|
||||||
"""Register notify view."""
|
"""Register notify view."""
|
||||||
hass_data = hass.data[DLNA_DMR_DATA]
|
hass_data = hass.data[DLNA_DMR_DATA]
|
||||||
if 'event_handler' in hass_data:
|
if 'event_handler' in hass_data:
|
||||||
@ -91,10 +99,14 @@ async def async_start_event_handler(hass, server_host, server_port, requester):
|
|||||||
# start event handler
|
# start event handler
|
||||||
from async_upnp_client.aiohttp import AiohttpNotifyServer
|
from async_upnp_client.aiohttp import AiohttpNotifyServer
|
||||||
server = AiohttpNotifyServer(
|
server = AiohttpNotifyServer(
|
||||||
requester, server_port, server_host, hass.loop)
|
requester,
|
||||||
|
listen_port=server_port,
|
||||||
|
listen_host=server_host,
|
||||||
|
loop=hass.loop,
|
||||||
|
callback_url=callback_url_override)
|
||||||
await server.start_server()
|
await server.start_server()
|
||||||
_LOGGER.info(
|
_LOGGER.info(
|
||||||
'UPNP/DLNA event handler listening on: %s', server.callback_url)
|
'UPNP/DLNA event handler listening, url: %s', server.callback_url)
|
||||||
hass_data['notify_server'] = server
|
hass_data['notify_server'] = server
|
||||||
hass_data['event_handler'] = server.event_handler
|
hass_data['event_handler'] = server.event_handler
|
||||||
|
|
||||||
@ -109,7 +121,10 @@ async def async_start_event_handler(hass, server_host, server_port, requester):
|
|||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(
|
async def async_setup_platform(
|
||||||
hass: HomeAssistant, config, async_add_entities, discovery_info=None):
|
hass: HomeAssistantType,
|
||||||
|
config,
|
||||||
|
async_add_entities,
|
||||||
|
discovery_info=None):
|
||||||
"""Set up DLNA DMR platform."""
|
"""Set up DLNA DMR platform."""
|
||||||
if config.get(CONF_URL) is not None:
|
if config.get(CONF_URL) is not None:
|
||||||
url = config[CONF_URL]
|
url = config[CONF_URL]
|
||||||
@ -135,8 +150,9 @@ async def async_setup_platform(
|
|||||||
if server_host is None:
|
if server_host is None:
|
||||||
server_host = get_local_ip()
|
server_host = get_local_ip()
|
||||||
server_port = config.get(CONF_LISTEN_PORT, DEFAULT_LISTEN_PORT)
|
server_port = config.get(CONF_LISTEN_PORT, DEFAULT_LISTEN_PORT)
|
||||||
|
callback_url_override = config.get(CONF_CALLBACK_URL_OVERRIDE)
|
||||||
event_handler = await async_start_event_handler(
|
event_handler = await async_start_event_handler(
|
||||||
hass, server_host, server_port, requester)
|
hass, server_host, server_port, requester, callback_url_override)
|
||||||
|
|
||||||
# create upnp device
|
# create upnp device
|
||||||
from async_upnp_client import UpnpFactory
|
from async_upnp_client import UpnpFactory
|
||||||
|
@ -23,7 +23,7 @@ from .const import DOMAIN
|
|||||||
from .const import LOGGER as _LOGGER
|
from .const import LOGGER as _LOGGER
|
||||||
from .device import Device
|
from .device import Device
|
||||||
|
|
||||||
REQUIREMENTS = ['async-upnp-client==0.14.4']
|
REQUIREMENTS = ['async-upnp-client==0.14.5']
|
||||||
|
|
||||||
NOTIFICATION_ID = 'upnp_notification'
|
NOTIFICATION_ID = 'upnp_notification'
|
||||||
NOTIFICATION_TITLE = 'UPnP/IGD Setup'
|
NOTIFICATION_TITLE = 'UPnP/IGD Setup'
|
||||||
|
@ -174,7 +174,7 @@ asterisk_mbox==0.5.0
|
|||||||
|
|
||||||
# homeassistant.components.upnp
|
# homeassistant.components.upnp
|
||||||
# homeassistant.components.media_player.dlna_dmr
|
# homeassistant.components.media_player.dlna_dmr
|
||||||
async-upnp-client==0.14.4
|
async-upnp-client==0.14.5
|
||||||
|
|
||||||
# homeassistant.components.light.avion
|
# homeassistant.components.light.avion
|
||||||
# avion==0.10
|
# avion==0.10
|
||||||
|
Loading…
x
Reference in New Issue
Block a user