mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
Rename igd to upnp
This commit is contained in:
parent
6588dceadd
commit
c19665fed4
@ -49,7 +49,7 @@ CONFIG_ENTRY_HANDLERS = {
|
||||
'google_cast': 'cast',
|
||||
SERVICE_HUE: 'hue',
|
||||
'sonos': 'sonos',
|
||||
'igd': 'igd',
|
||||
'upnp': 'igd',
|
||||
}
|
||||
|
||||
SERVICE_HANDLERS = {
|
||||
|
@ -1,20 +1,20 @@
|
||||
"""
|
||||
Support for IGD Sensors.
|
||||
Support for UPnP/IGD Sensors.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/sensor.igd/
|
||||
https://home-assistant.io/components/sensor.upnp/
|
||||
"""
|
||||
# pylint: disable=invalid-name
|
||||
from datetime import datetime
|
||||
import logging
|
||||
|
||||
from homeassistant.components.igd import DOMAIN
|
||||
from homeassistant.components.upnp import DOMAIN
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEPENDENCIES = ['igd']
|
||||
DEPENDENCIES = ['upnp']
|
||||
|
||||
BYTES_RECEIVED = 'bytes_received'
|
||||
BYTES_SENT = 'bytes_sent'
|
||||
@ -47,7 +47,7 @@ KBYTE = 1024
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_devices,
|
||||
discovery_info=None):
|
||||
"""Set up the IGD sensors."""
|
||||
"""Set up the UPnP/IGD sensors."""
|
||||
if discovery_info is None:
|
||||
return
|
||||
|
||||
@ -56,25 +56,25 @@ async def async_setup_platform(hass, config, async_add_devices,
|
||||
|
||||
# raw sensors + per-second sensors
|
||||
sensors = [
|
||||
RawIGDSensor(device, name, sensor_type)
|
||||
RawUPnPIGDSensor(device, name, sensor_type)
|
||||
for name, sensor_type in SENSOR_TYPES.items()
|
||||
]
|
||||
sensors += [
|
||||
KBytePerSecondIGDSensor(device, IN),
|
||||
KBytePerSecondIGDSensor(device, OUT),
|
||||
PacketsPerSecondIGDSensor(device, IN),
|
||||
PacketsPerSecondIGDSensor(device, OUT),
|
||||
KBytePerSecondUPnPIGDSensor(device, IN),
|
||||
KBytePerSecondUPnPIGDSensor(device, OUT),
|
||||
PacketsPerSecondUPnPIGDSensor(device, IN),
|
||||
PacketsPerSecondUPnPIGDSensor(device, OUT),
|
||||
]
|
||||
hass.data[DOMAIN]['sensors'][udn] = sensors
|
||||
async_add_devices(sensors, True)
|
||||
return True
|
||||
|
||||
|
||||
class RawIGDSensor(Entity):
|
||||
"""Representation of a UPnP IGD sensor."""
|
||||
class RawUPnPIGDSensor(Entity):
|
||||
"""Representation of a UPnP/IGD sensor."""
|
||||
|
||||
def __init__(self, device, sensor_type_name, sensor_type):
|
||||
"""Initialize the IGD sensor."""
|
||||
"""Initialize the UPnP/IGD sensor."""
|
||||
self._device = device
|
||||
self._type_name = sensor_type_name
|
||||
self._type = sensor_type
|
||||
@ -118,7 +118,7 @@ class RawIGDSensor(Entity):
|
||||
self._state = await self._device.async_get_total_packets_sent()
|
||||
|
||||
|
||||
class PerSecondIGDSensor(Entity):
|
||||
class PerSecondUPnPIGDSensor(Entity):
|
||||
"""Abstract representation of a X Sent/Received per second sensor."""
|
||||
|
||||
def __init__(self, device, direction):
|
||||
@ -169,7 +169,7 @@ class PerSecondIGDSensor(Entity):
|
||||
return new_value < self._last_value
|
||||
|
||||
async def async_update(self):
|
||||
"""Get the latest information from the IGD."""
|
||||
"""Get the latest information from the UPnP/IGD."""
|
||||
new_value = await self._async_fetch_value()
|
||||
|
||||
if self._last_value is None:
|
||||
@ -189,7 +189,7 @@ class PerSecondIGDSensor(Entity):
|
||||
self._last_update_time = now
|
||||
|
||||
|
||||
class KBytePerSecondIGDSensor(PerSecondIGDSensor):
|
||||
class KBytePerSecondUPnPIGDSensor(PerSecondUPnPIGDSensor):
|
||||
"""Representation of a KBytes Sent/Received per second sensor."""
|
||||
|
||||
@property
|
||||
@ -213,7 +213,7 @@ class KBytePerSecondIGDSensor(PerSecondIGDSensor):
|
||||
return format(float(self._state / KBYTE), '.1f')
|
||||
|
||||
|
||||
class PacketsPerSecondIGDSensor(PerSecondIGDSensor):
|
||||
class PacketsPerSecondUPnPIGDSensor(PerSecondUPnPIGDSensor):
|
||||
"""Representation of a Packets Sent/Received per second sensor."""
|
||||
|
||||
@property
|
@ -1,14 +1,14 @@
|
||||
{
|
||||
"config": {
|
||||
"title": "IGD",
|
||||
"title": "UPnP/IGD",
|
||||
"step": {
|
||||
"init": {
|
||||
"title": "IGD"
|
||||
"title": "UPnP/IGD"
|
||||
},
|
||||
"user": {
|
||||
"title": "Configuration options for the IGD",
|
||||
"title": "Configuration options for the UPnP/IGD",
|
||||
"data":{
|
||||
"igd": "IGD",
|
||||
"igd": "UPnP/IGD",
|
||||
"sensors": "Add traffic sensors",
|
||||
"port_forward": "Enable port forward for Home Assistant"
|
||||
}
|
||||
@ -17,10 +17,9 @@
|
||||
"error": {
|
||||
},
|
||||
"abort": {
|
||||
"no_devices_discovered": "No IGDs discovered",
|
||||
"already_configured": "IGD is already configured",
|
||||
"no_sensors_or_port_forward": "Enable at least sensors or port forward",
|
||||
"no_igds": "No IGDs discovered"
|
||||
"no_devices_discovered": "No UPnP/IGDs discovered",
|
||||
"already_configured": "UPnP/IGD is already configured",
|
||||
"no_sensors_or_port_forward": "Enable at least sensors or port forward"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +1,14 @@
|
||||
{
|
||||
"config": {
|
||||
"title": "IGD",
|
||||
"title": "UPnP/IGD",
|
||||
"step": {
|
||||
"init": {
|
||||
"title": "IGD"
|
||||
"title": "UPnP/IGD"
|
||||
},
|
||||
"user": {
|
||||
"title": "Extra configuratie options voor IGD",
|
||||
"title": "Extra configuratie options voor UPnP/IGD",
|
||||
"data":{
|
||||
"igd": "IGD",
|
||||
"igd": "UPnP/IGD",
|
||||
"sensors": "Verkeer sensors toevoegen",
|
||||
"port_forward": "Maak port forward voor Home Assistant"
|
||||
}
|
||||
@ -17,10 +17,9 @@
|
||||
"error": {
|
||||
},
|
||||
"abort": {
|
||||
"no_devices_discovered": "Geen IGDs gevonden",
|
||||
"already_configured": "IGD is reeds geconfigureerd",
|
||||
"no_sensors_or_port_forward": "Kies ten minste sensors of port forward",
|
||||
"no_igds": "Geen IGDs gevonden"
|
||||
"no_devices_discovered": "Geen UPnP/IGDs gevonden",
|
||||
"already_configured": "UPnP/IGD is reeds geconfigureerd",
|
||||
"no_sensors_or_port_forward": "Kies ten minste sensors of port forward"
|
||||
}
|
||||
}
|
||||
}
|
@ -2,9 +2,8 @@
|
||||
Will open a port in your router for Home Assistant and provide statistics.
|
||||
|
||||
For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/igd/
|
||||
https://home-assistant.io/components/upnp/
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from ipaddress import ip_address
|
||||
|
||||
@ -34,7 +33,7 @@ from .device import Device
|
||||
REQUIREMENTS = ['async-upnp-client==0.12.4']
|
||||
DEPENDENCIES = ['http']
|
||||
|
||||
NOTIFICATION_ID = 'igd_notification'
|
||||
NOTIFICATION_ID = 'upnp_notification'
|
||||
NOTIFICATION_TITLE = 'UPnP/IGD Setup'
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
@ -72,25 +71,25 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType):
|
||||
return True
|
||||
|
||||
if DISCOVERY_DOMAIN not in config:
|
||||
_LOGGER.warning('IGD needs discovery, please enable it')
|
||||
_LOGGER.warning('UPNP needs discovery, please enable it')
|
||||
return False
|
||||
|
||||
# overridden local ip
|
||||
igd_config = config[DOMAIN]
|
||||
if CONF_LOCAL_IP in igd_config:
|
||||
hass.data[DOMAIN]['local_ip'] = igd_config[CONF_LOCAL_IP]
|
||||
upnp_config = config[DOMAIN]
|
||||
if CONF_LOCAL_IP in upnp_config:
|
||||
hass.data[DOMAIN]['local_ip'] = upnp_config[CONF_LOCAL_IP]
|
||||
|
||||
# determine ports
|
||||
ports = {CONF_HASS: CONF_HASS} # default, port_forward disabled by default
|
||||
if CONF_PORTS in igd_config:
|
||||
if CONF_PORTS in upnp_config:
|
||||
# copy from config
|
||||
ports = igd_config[CONF_PORTS]
|
||||
ports = upnp_config[CONF_PORTS]
|
||||
|
||||
hass.data[DOMAIN]['auto_config'] = {
|
||||
'active': True,
|
||||
'port_forward': igd_config[CONF_ENABLE_PORT_MAPPING],
|
||||
'port_forward': upnp_config[CONF_ENABLE_PORT_MAPPING],
|
||||
'ports': ports,
|
||||
'sensors': igd_config[CONF_ENABLE_SENSORS],
|
||||
'sensors': upnp_config[CONF_ENABLE_SENSORS],
|
||||
}
|
||||
|
||||
return True
|
||||
@ -104,7 +103,7 @@ async def async_setup_entry(hass: HomeAssistantType,
|
||||
ensure_domain_data(hass)
|
||||
data = config_entry.data
|
||||
|
||||
# build IGD device
|
||||
# build UPnP/IGD device
|
||||
ssdp_description = data[CONF_SSDP_DESCRIPTION]
|
||||
try:
|
||||
device = await Device.async_create_device(hass, ssdp_description)
|
@ -1,4 +1,4 @@
|
||||
"""Config flow for IGD."""
|
||||
"""Config flow for UPNP."""
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
@ -26,13 +26,13 @@ def ensure_domain_data(hass):
|
||||
|
||||
|
||||
@config_entries.HANDLERS.register(DOMAIN)
|
||||
class IgdFlowHandler(data_entry_flow.FlowHandler):
|
||||
class UpnpFlowHandler(data_entry_flow.FlowHandler):
|
||||
"""Handle a Hue config flow."""
|
||||
|
||||
VERSION = 1
|
||||
|
||||
@property
|
||||
def _configured_igds(self):
|
||||
def _configured_upnp_igds(self):
|
||||
"""Get all configured IGDs."""
|
||||
return {
|
||||
entry.data[CONF_UDN]: {
|
||||
@ -42,7 +42,7 @@ class IgdFlowHandler(data_entry_flow.FlowHandler):
|
||||
}
|
||||
|
||||
@property
|
||||
def _discovered_igds(self):
|
||||
def _discovered_upnp_igds(self):
|
||||
"""Get all discovered entries."""
|
||||
return self.hass.data[DOMAIN]['discovered']
|
||||
|
||||
@ -57,7 +57,7 @@ class IgdFlowHandler(data_entry_flow.FlowHandler):
|
||||
|
||||
async def async_step_discovery(self, discovery_info):
|
||||
"""
|
||||
Handle a discovered IGD.
|
||||
Handle a discovered UPnP/IGD.
|
||||
|
||||
This flow is triggered by the discovery component. It will check if the
|
||||
host is already configured and delegate to the import step if not.
|
||||
@ -71,7 +71,7 @@ class IgdFlowHandler(data_entry_flow.FlowHandler):
|
||||
|
||||
# ensure not already discovered/configured
|
||||
udn = discovery_info['udn']
|
||||
if udn in self._configured_igds:
|
||||
if udn in self._configured_upnp_igds:
|
||||
return self.async_abort(reason='already_configured')
|
||||
|
||||
# auto config?
|
||||
@ -98,19 +98,19 @@ class IgdFlowHandler(data_entry_flow.FlowHandler):
|
||||
# ensure not already configured
|
||||
configured_names = [
|
||||
entry['friendly_name']
|
||||
for udn, entry in self._discovered_igds.items()
|
||||
if udn in self._configured_igds
|
||||
for udn, entry in self._discovered_upnp_igds.items()
|
||||
if udn in self._configured_upnp_igds
|
||||
]
|
||||
if user_input['name'] in configured_names:
|
||||
return self.async_abort(reason='already_configured')
|
||||
|
||||
return await self._async_save_entry(user_input)
|
||||
|
||||
# let user choose from all discovered, non-configured, IGDs
|
||||
# let user choose from all discovered, non-configured, UPnP/IGDs
|
||||
names = [
|
||||
entry['friendly_name']
|
||||
for udn, entry in self._discovered_igds.items()
|
||||
if udn not in self._configured_igds
|
||||
for udn, entry in self._discovered_upnp_igds.items()
|
||||
if udn not in self._configured_upnp_igds
|
||||
]
|
||||
if not names:
|
||||
return self.async_abort(reason='no_devices_discovered')
|
||||
@ -125,15 +125,15 @@ class IgdFlowHandler(data_entry_flow.FlowHandler):
|
||||
)
|
||||
|
||||
async def async_step_import(self, import_info):
|
||||
"""Import a new IGD as a config entry."""
|
||||
"""Import a new UPnP/IGD as a config entry."""
|
||||
return await self._async_save_entry(import_info)
|
||||
|
||||
async def _async_save_entry(self, import_info):
|
||||
"""Store IGD as new entry."""
|
||||
"""Store UPNP/IGD as new entry."""
|
||||
# ensure we know the host
|
||||
name = import_info['name']
|
||||
discovery_infos = [info
|
||||
for info in self._discovered_igds.values()
|
||||
for info in self._discovered_upnp_igds.values()
|
||||
if info['friendly_name'] == name]
|
||||
if not discovery_infos:
|
||||
return self.async_abort(reason='host_not_found')
|
@ -9,5 +9,5 @@ CONF_LOCAL_IP = 'local_ip'
|
||||
CONF_PORTS = 'ports'
|
||||
CONF_SSDP_DESCRIPTION = 'ssdp_description'
|
||||
CONF_UDN = 'udn'
|
||||
DOMAIN = 'igd'
|
||||
LOGGER = logging.getLogger('homeassistant.components.igd')
|
||||
DOMAIN = 'upnp'
|
||||
LOGGER = logging.getLogger('homeassistant.components.upnp')
|
@ -1,5 +1,4 @@
|
||||
"""Hass representation of an IGD."""
|
||||
|
||||
"""Hass representation of an UPnP/IGD."""
|
||||
import asyncio
|
||||
from ipaddress import IPv4Address
|
||||
|
||||
@ -13,7 +12,7 @@ from .const import LOGGER as _LOGGER
|
||||
|
||||
|
||||
class Device:
|
||||
"""Hass representation of an IGD."""
|
||||
"""Hass representation of an UPnP/IGD."""
|
||||
|
||||
def __init__(self, igd_device):
|
||||
"""Initializer."""
|
||||
@ -24,7 +23,7 @@ class Device:
|
||||
async def async_create_device(cls,
|
||||
hass: HomeAssistantType,
|
||||
ssdp_description: str):
|
||||
"""Create IGD device."""
|
||||
"""Create UPnP/IGD device."""
|
||||
# build async_upnp_client requester
|
||||
from async_upnp_client.aiohttp import AiohttpSessionRequester
|
||||
session = async_get_clientsession(hass)
|
@ -1,14 +1,14 @@
|
||||
{
|
||||
"config": {
|
||||
"title": "IGD",
|
||||
"title": "UPnP/IGD",
|
||||
"step": {
|
||||
"init": {
|
||||
"title": "IGD"
|
||||
"title": "UPnP/IGD"
|
||||
},
|
||||
"user": {
|
||||
"title": "Configuration options for the IGD",
|
||||
"title": "Configuration options for the UPnP/IGD",
|
||||
"data":{
|
||||
"igd": "IGD",
|
||||
"igd": "UPnP/IGD",
|
||||
"sensors": "Add traffic sensors",
|
||||
"port_forward": "Enable port forward for Home Assistant"
|
||||
}
|
@ -143,7 +143,7 @@ FLOWS = [
|
||||
'nest',
|
||||
'sonos',
|
||||
'zone',
|
||||
'igd',
|
||||
'upnp',
|
||||
]
|
||||
|
||||
|
||||
|
@ -1,16 +1,16 @@
|
||||
"""Tests for IGD config flow."""
|
||||
"""Tests for UPnP/IGD config flow."""
|
||||
|
||||
from homeassistant.components import igd
|
||||
from homeassistant.components.igd import config_flow as igd_config_flow
|
||||
from homeassistant.components import upnp
|
||||
from homeassistant.components.upnp import config_flow as upnp_config_flow
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_flow_none_discovered(hass):
|
||||
"""Test no device discovered flow."""
|
||||
flow = igd_config_flow.IgdFlowHandler()
|
||||
flow = upnp_config_flow.UpnpFlowHandler()
|
||||
flow.hass = hass
|
||||
hass.data[igd.DOMAIN] = {
|
||||
hass.data[upnp.DOMAIN] = {
|
||||
'discovered': {}
|
||||
}
|
||||
|
||||
@ -21,12 +21,12 @@ async def test_flow_none_discovered(hass):
|
||||
|
||||
async def test_flow_already_configured(hass):
|
||||
"""Test device already configured flow."""
|
||||
flow = igd_config_flow.IgdFlowHandler()
|
||||
flow = upnp_config_flow.UpnpFlowHandler()
|
||||
flow.hass = hass
|
||||
|
||||
# discovered device
|
||||
udn = 'uuid:device_1'
|
||||
hass.data[igd.DOMAIN] = {
|
||||
hass.data[upnp.DOMAIN] = {
|
||||
'discovered': {
|
||||
udn: {
|
||||
'friendly_name': '192.168.1.1 (Test device)',
|
||||
@ -37,7 +37,7 @@ async def test_flow_already_configured(hass):
|
||||
}
|
||||
|
||||
# configured entry
|
||||
MockConfigEntry(domain=igd.DOMAIN, data={
|
||||
MockConfigEntry(domain=upnp.DOMAIN, data={
|
||||
'udn': udn,
|
||||
'host': '192.168.1.1',
|
||||
}).add_to_hass(hass)
|
||||
@ -53,12 +53,12 @@ async def test_flow_already_configured(hass):
|
||||
|
||||
async def test_flow_no_sensors_no_port_forward(hass):
|
||||
"""Test single device, no sensors, no port_forward."""
|
||||
flow = igd_config_flow.IgdFlowHandler()
|
||||
flow = upnp_config_flow.UpnpFlowHandler()
|
||||
flow.hass = hass
|
||||
|
||||
# discovered device
|
||||
udn = 'uuid:device_1'
|
||||
hass.data[igd.DOMAIN] = {
|
||||
hass.data[upnp.DOMAIN] = {
|
||||
'discovered': {
|
||||
udn: {
|
||||
'friendly_name': '192.168.1.1 (Test device)',
|
||||
@ -69,7 +69,7 @@ async def test_flow_no_sensors_no_port_forward(hass):
|
||||
}
|
||||
|
||||
# configured entry
|
||||
MockConfigEntry(domain=igd.DOMAIN, data={
|
||||
MockConfigEntry(domain=upnp.DOMAIN, data={
|
||||
'udn': udn,
|
||||
'host': '192.168.1.1',
|
||||
}).add_to_hass(hass)
|
||||
@ -85,12 +85,12 @@ async def test_flow_no_sensors_no_port_forward(hass):
|
||||
|
||||
async def test_flow_discovered_form(hass):
|
||||
"""Test single device discovered, show form flow."""
|
||||
flow = igd_config_flow.IgdFlowHandler()
|
||||
flow = upnp_config_flow.UpnpFlowHandler()
|
||||
flow.hass = hass
|
||||
|
||||
# discovered device
|
||||
udn = 'uuid:device_1'
|
||||
hass.data[igd.DOMAIN] = {
|
||||
hass.data[upnp.DOMAIN] = {
|
||||
'discovered': {
|
||||
udn: {
|
||||
'friendly_name': '192.168.1.1 (Test device)',
|
||||
@ -107,13 +107,13 @@ async def test_flow_discovered_form(hass):
|
||||
|
||||
async def test_flow_two_discovered_form(hass):
|
||||
"""Test single device discovered, show form flow."""
|
||||
flow = igd_config_flow.IgdFlowHandler()
|
||||
flow = upnp_config_flow.UpnpFlowHandler()
|
||||
flow.hass = hass
|
||||
|
||||
# discovered device
|
||||
udn_1 = 'uuid:device_1'
|
||||
udn_2 = 'uuid:device_2'
|
||||
hass.data[igd.DOMAIN] = {
|
||||
hass.data[upnp.DOMAIN] = {
|
||||
'discovered': {
|
||||
udn_1: {
|
||||
'friendly_name': '192.168.1.1 (Test device)',
|
||||
@ -145,11 +145,11 @@ async def test_flow_two_discovered_form(hass):
|
||||
|
||||
async def test_config_entry_created(hass):
|
||||
"""Test config entry is created."""
|
||||
flow = igd_config_flow.IgdFlowHandler()
|
||||
flow = upnp_config_flow.UpnpFlowHandler()
|
||||
flow.hass = hass
|
||||
|
||||
# discovered device
|
||||
hass.data[igd.DOMAIN] = {
|
||||
hass.data[upnp.DOMAIN] = {
|
||||
'discovered': {
|
||||
'uuid:device_1': {
|
||||
'friendly_name': '192.168.1.1 (Test device)',
|
||||
@ -178,11 +178,11 @@ async def test_config_entry_created(hass):
|
||||
|
||||
async def test_flow_discovery_auto_config_sensors(hass):
|
||||
"""Test creation of device with auto_config."""
|
||||
flow = igd_config_flow.IgdFlowHandler()
|
||||
flow = upnp_config_flow.UpnpFlowHandler()
|
||||
flow.hass = hass
|
||||
|
||||
# auto_config active
|
||||
hass.data[igd.DOMAIN] = {
|
||||
hass.data[upnp.DOMAIN] = {
|
||||
'auto_config': {
|
||||
'active': True,
|
||||
'port_forward': False,
|
||||
@ -210,11 +210,11 @@ async def test_flow_discovery_auto_config_sensors(hass):
|
||||
|
||||
async def test_flow_discovery_auto_config_sensors_port_forward(hass):
|
||||
"""Test creation of device with auto_config, with port forward."""
|
||||
flow = igd_config_flow.IgdFlowHandler()
|
||||
flow = upnp_config_flow.UpnpFlowHandler()
|
||||
flow.hass = hass
|
||||
|
||||
# auto_config active, with port_forward
|
||||
hass.data[igd.DOMAIN] = {
|
||||
hass.data[upnp.DOMAIN] = {
|
||||
'auto_config': {
|
||||
'active': True,
|
||||
'port_forward': True,
|
@ -1,11 +1,11 @@
|
||||
"""Test IGD setup process."""
|
||||
"""Test UPnP/IGD setup process."""
|
||||
|
||||
from ipaddress import ip_address
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components import igd
|
||||
from homeassistant.components.igd.device import Device
|
||||
from homeassistant.components import upnp
|
||||
from homeassistant.components.upnp.device import Device
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
@ -49,9 +49,9 @@ class MockDevice(Device):
|
||||
async def test_async_setup_no_auto_config(hass):
|
||||
"""Test async_setup."""
|
||||
# setup component, enable auto_config
|
||||
await async_setup_component(hass, 'igd')
|
||||
await async_setup_component(hass, 'upnp')
|
||||
|
||||
assert hass.data[igd.DOMAIN]['auto_config'] == {
|
||||
assert hass.data[upnp.DOMAIN]['auto_config'] == {
|
||||
'active': False,
|
||||
'port_forward': False,
|
||||
'ports': {'hass': 'hass'},
|
||||
@ -62,9 +62,9 @@ async def test_async_setup_no_auto_config(hass):
|
||||
async def test_async_setup_auto_config(hass):
|
||||
"""Test async_setup."""
|
||||
# setup component, enable auto_config
|
||||
await async_setup_component(hass, 'igd', {'igd': {}, 'discovery': {}})
|
||||
await async_setup_component(hass, 'upnp', {'upnp': {}, 'discovery': {}})
|
||||
|
||||
assert hass.data[igd.DOMAIN]['auto_config'] == {
|
||||
assert hass.data[upnp.DOMAIN]['auto_config'] == {
|
||||
'active': True,
|
||||
'port_forward': False,
|
||||
'ports': {'hass': 'hass'},
|
||||
@ -75,14 +75,14 @@ async def test_async_setup_auto_config(hass):
|
||||
async def test_async_setup_auto_config_port_forward(hass):
|
||||
"""Test async_setup."""
|
||||
# setup component, enable auto_config
|
||||
await async_setup_component(hass, 'igd', {
|
||||
'igd': {
|
||||
await async_setup_component(hass, 'upnp', {
|
||||
'upnp': {
|
||||
'port_forward': True,
|
||||
'ports': {'hass': 'hass'},
|
||||
},
|
||||
'discovery': {}})
|
||||
|
||||
assert hass.data[igd.DOMAIN]['auto_config'] == {
|
||||
assert hass.data[upnp.DOMAIN]['auto_config'] == {
|
||||
'active': True,
|
||||
'port_forward': True,
|
||||
'ports': {'hass': 'hass'},
|
||||
@ -93,11 +93,11 @@ async def test_async_setup_auto_config_port_forward(hass):
|
||||
async def test_async_setup_auto_config_no_sensors(hass):
|
||||
"""Test async_setup."""
|
||||
# setup component, enable auto_config
|
||||
await async_setup_component(hass, 'igd', {
|
||||
'igd': {'sensors': False},
|
||||
await async_setup_component(hass, 'upnp', {
|
||||
'upnp': {'sensors': False},
|
||||
'discovery': {}})
|
||||
|
||||
assert hass.data[igd.DOMAIN]['auto_config'] == {
|
||||
assert hass.data[upnp.DOMAIN]['auto_config'] == {
|
||||
'active': True,
|
||||
'port_forward': False,
|
||||
'ports': {'hass': 'hass'},
|
||||
@ -108,7 +108,7 @@ async def test_async_setup_auto_config_no_sensors(hass):
|
||||
async def test_async_setup_entry_default(hass):
|
||||
"""Test async_setup_entry."""
|
||||
udn = 'uuid:device_1'
|
||||
entry = MockConfigEntry(domain=igd.DOMAIN, data={
|
||||
entry = MockConfigEntry(domain=upnp.DOMAIN, data={
|
||||
'ssdp_description': 'http://192.168.1.1/desc.xml',
|
||||
'udn': udn,
|
||||
'sensors': True,
|
||||
@ -116,9 +116,9 @@ async def test_async_setup_entry_default(hass):
|
||||
})
|
||||
|
||||
# ensure hass.http is available
|
||||
await async_setup_component(hass, 'igd')
|
||||
await async_setup_component(hass, 'upnp')
|
||||
|
||||
# mock homeassistant.components.igd.device.Device
|
||||
# mock homeassistant.components.upnp.device.Device
|
||||
mock_device = MagicMock()
|
||||
mock_device.udn = udn
|
||||
mock_device.async_add_port_mappings.return_value = mock_coro()
|
||||
@ -126,18 +126,18 @@ async def test_async_setup_entry_default(hass):
|
||||
with patch.object(Device, 'async_create_device') as mock_create_device:
|
||||
mock_create_device.return_value = mock_coro(
|
||||
return_value=mock_device)
|
||||
with patch('homeassistant.components.igd.device.get_local_ip',
|
||||
with patch('homeassistant.components.upnp.device.get_local_ip',
|
||||
return_value='192.168.1.10'):
|
||||
assert await igd.async_setup_entry(hass, entry) is True
|
||||
assert await upnp.async_setup_entry(hass, entry) is True
|
||||
|
||||
# ensure device is stored/used
|
||||
assert hass.data[igd.DOMAIN]['devices'][udn] == mock_device
|
||||
assert hass.data[upnp.DOMAIN]['devices'][udn] == mock_device
|
||||
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# ensure cleaned up
|
||||
assert udn not in hass.data[igd.DOMAIN]['devices']
|
||||
assert udn not in hass.data[upnp.DOMAIN]['devices']
|
||||
|
||||
# ensure no port-mapping-methods called
|
||||
assert len(mock_device.async_add_port_mappings.mock_calls) == 0
|
||||
@ -147,7 +147,7 @@ async def test_async_setup_entry_default(hass):
|
||||
async def test_async_setup_entry_port_forward(hass):
|
||||
"""Test async_setup_entry."""
|
||||
udn = 'uuid:device_1'
|
||||
entry = MockConfigEntry(domain=igd.DOMAIN, data={
|
||||
entry = MockConfigEntry(domain=upnp.DOMAIN, data={
|
||||
'ssdp_description': 'http://192.168.1.1/desc.xml',
|
||||
'udn': udn,
|
||||
'sensors': False,
|
||||
@ -155,8 +155,8 @@ async def test_async_setup_entry_port_forward(hass):
|
||||
})
|
||||
|
||||
# ensure hass.http is available
|
||||
await async_setup_component(hass, 'igd', {
|
||||
'igd': {
|
||||
await async_setup_component(hass, 'upnp', {
|
||||
'upnp': {
|
||||
'port_forward': True,
|
||||
'ports': {'hass': 'hass'},
|
||||
},
|
||||
@ -166,12 +166,12 @@ async def test_async_setup_entry_port_forward(hass):
|
||||
mock_device = MockDevice(udn)
|
||||
with patch.object(Device, 'async_create_device') as mock_create_device:
|
||||
mock_create_device.return_value = mock_coro(return_value=mock_device)
|
||||
with patch('homeassistant.components.igd.device.get_local_ip',
|
||||
with patch('homeassistant.components.upnp.device.get_local_ip',
|
||||
return_value='192.168.1.10'):
|
||||
assert await igd.async_setup_entry(hass, entry) is True
|
||||
assert await upnp.async_setup_entry(hass, entry) is True
|
||||
|
||||
# ensure device is stored/used
|
||||
assert hass.data[igd.DOMAIN]['devices'][udn] == mock_device
|
||||
assert hass.data[upnp.DOMAIN]['devices'][udn] == mock_device
|
||||
|
||||
# ensure add-port-mapping-methods called
|
||||
assert mock_device.added_port_mappings == [
|
||||
@ -182,7 +182,7 @@ async def test_async_setup_entry_port_forward(hass):
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# ensure cleaned up
|
||||
assert udn not in hass.data[igd.DOMAIN]['devices']
|
||||
assert udn not in hass.data[upnp.DOMAIN]['devices']
|
||||
|
||||
# ensure delete-port-mapping-methods called
|
||||
assert mock_device.removed_port_mappings == [8123]
|
Loading…
x
Reference in New Issue
Block a user