Move upnp imports at top-level (#29083)
This commit is contained in:
parent
29e2201446
commit
5015993f30
3 changed files with 12 additions and 19 deletions
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Add table
Reference in a new issue