diff --git a/homeassistant/components/upnp/__init__.py b/homeassistant/components/upnp/__init__.py index bbb49ebd1d4..9a7e06738db 100644 --- a/homeassistant/components/upnp/__init__.py +++ b/homeassistant/components/upnp/__init__.py @@ -7,11 +7,12 @@ import voluptuous as vol from homeassistant import config_entries from homeassistant.config_entries import ConfigEntry from homeassistant.const import EVENT_HOMEASSISTANT_STOP -from homeassistant.helpers import config_validation as cv -from homeassistant.helpers import device_registry as dr -from homeassistant.helpers import dispatcher -from homeassistant.helpers.typing import ConfigType -from homeassistant.helpers.typing import HomeAssistantType +from homeassistant.helpers import ( + config_validation as cv, + device_registry as dr, + dispatcher, +) +from homeassistant.helpers.typing import ConfigType, HomeAssistantType from homeassistant.util import get_local_ip from .const import ( @@ -20,10 +21,10 @@ from .const import ( CONF_HASS, CONF_LOCAL_IP, CONF_PORTS, + DOMAIN, + LOGGER as _LOGGER, SIGNAL_REMOVE_SENSOR, ) -from .const import DOMAIN -from .const import LOGGER as _LOGGER from .device import Device NOTIFICATION_ID = "upnp_notification" diff --git a/homeassistant/components/upnp/config_flow.py b/homeassistant/components/upnp/config_flow.py index cdcce76dbc3..1601595b6a9 100644 --- a/homeassistant/components/upnp/config_flow.py +++ b/homeassistant/components/upnp/config_flow.py @@ -1,11 +1,10 @@ """Config flow for UPNP.""" -from homeassistant.helpers import config_entry_flow from homeassistant import config_entries +from homeassistant.helpers import config_entry_flow from .const import DOMAIN from .device import Device - config_entry_flow.register_discovery_flow( DOMAIN, "UPnP/IGD", Device.async_discover, config_entries.CONN_CLASS_LOCAL_POLL ) diff --git a/homeassistant/components/upnp/device.py b/homeassistant/components/upnp/device.py index de3c93a82ed..b87c3dc96b6 100644 --- a/homeassistant/components/upnp/device.py +++ b/homeassistant/components/upnp/device.py @@ -3,13 +3,14 @@ import asyncio from ipaddress import IPv4Address import aiohttp +from async_upnp_client import UpnpError, UpnpFactory +from async_upnp_client.aiohttp import AiohttpSessionRequester from async_upnp_client.profiles.igd import IgdDevice 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 +from .const import CONF_LOCAL_IP, DOMAIN, LOGGER as _LOGGER class Device: @@ -48,14 +49,10 @@ class Device: async def async_create_device(cls, hass: HomeAssistantType, ssdp_description: str): """Create UPnP/IGD device.""" # build async_upnp_client requester - from async_upnp_client.aiohttp import AiohttpSessionRequester - session = async_get_clientsession(hass) requester = AiohttpSessionRequester(session, True) # create async_upnp_client device - from async_upnp_client import UpnpFactory - factory = UpnpFactory(requester, disable_state_variable_validation=True) upnp_device = await factory.async_create_device(ssdp_description) @@ -99,8 +96,6 @@ class Device: async def _async_add_port_mapping(self, external_port, local_ip, internal_port): """Add a port mapping.""" # create port mapping - from async_upnp_client import UpnpError - _LOGGER.info( "Creating port mapping %s:%s:%s (TCP)", external_port, @@ -135,8 +130,6 @@ class Device: async def _async_delete_port_mapping(self, external_port): """Remove a port mapping.""" - from async_upnp_client import UpnpError - _LOGGER.info("Deleting port mapping %s (TCP)", external_port) try: await self._igd_device.async_delete_port_mapping(