mirror of https://github.com/home-assistant/core
Fixes for upnp-component/#17753 and missing hass-data when only setup from config entry (#17868)
* Upgrade to async_upnp_client==0.13.0, fixing #17753 * Fix missing 'local_ip' when upnp-component itself is not setup, but ConfigEntry is
This commit is contained in:
parent
851d7e22e7
commit
96c5e4c507
|
@ -25,7 +25,7 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
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.12.7']
|
REQUIREMENTS = ['async-upnp-client==0.13.0']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@ from homeassistant.helpers import config_validation as cv
|
||||||
from homeassistant.helpers import dispatcher
|
from homeassistant.helpers import dispatcher
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.helpers.typing import HomeAssistantType
|
from homeassistant.helpers.typing import HomeAssistantType
|
||||||
from homeassistant.util import get_local_ip
|
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_ENABLE_PORT_MAPPING, CONF_ENABLE_SENSORS,
|
CONF_ENABLE_PORT_MAPPING, CONF_ENABLE_SENSORS,
|
||||||
|
@ -26,11 +25,11 @@ from .const import (
|
||||||
)
|
)
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .const import LOGGER as _LOGGER
|
from .const import LOGGER as _LOGGER
|
||||||
from .config_flow import ensure_domain_data
|
from .config_flow import async_ensure_domain_data
|
||||||
from .device import Device
|
from .device import Device
|
||||||
|
|
||||||
|
|
||||||
REQUIREMENTS = ['async-upnp-client==0.12.7']
|
REQUIREMENTS = ['async-upnp-client==0.13.0']
|
||||||
|
|
||||||
NOTIFICATION_ID = 'upnp_notification'
|
NOTIFICATION_ID = 'upnp_notification'
|
||||||
NOTIFICATION_TITLE = 'UPnP/IGD Setup'
|
NOTIFICATION_TITLE = 'UPnP/IGD Setup'
|
||||||
|
@ -87,7 +86,7 @@ def _substitute_hass_ports(ports, hass_port=None):
|
||||||
# config
|
# config
|
||||||
async def async_setup(hass: HomeAssistantType, config: ConfigType):
|
async def async_setup(hass: HomeAssistantType, config: ConfigType):
|
||||||
"""Register a port mapping for Home Assistant via UPnP."""
|
"""Register a port mapping for Home Assistant via UPnP."""
|
||||||
ensure_domain_data(hass)
|
await async_ensure_domain_data(hass)
|
||||||
|
|
||||||
# ensure sane config
|
# ensure sane config
|
||||||
if DOMAIN not in config:
|
if DOMAIN not in config:
|
||||||
|
@ -97,9 +96,6 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType):
|
||||||
# overridden local ip
|
# overridden local ip
|
||||||
if CONF_LOCAL_IP in upnp_config:
|
if CONF_LOCAL_IP in upnp_config:
|
||||||
hass.data[DOMAIN]['local_ip'] = upnp_config[CONF_LOCAL_IP]
|
hass.data[DOMAIN]['local_ip'] = upnp_config[CONF_LOCAL_IP]
|
||||||
else:
|
|
||||||
hass.data[DOMAIN]['local_ip'] = \
|
|
||||||
await hass.async_add_executor_job(get_local_ip)
|
|
||||||
|
|
||||||
# determine ports
|
# determine ports
|
||||||
ports = {CONF_HASS: CONF_HASS} # default, port_mapping disabled by default
|
ports = {CONF_HASS: CONF_HASS} # default, port_mapping disabled by default
|
||||||
|
@ -121,7 +117,7 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType):
|
||||||
async def async_setup_entry(hass: HomeAssistantType,
|
async def async_setup_entry(hass: HomeAssistantType,
|
||||||
config_entry: ConfigEntry):
|
config_entry: ConfigEntry):
|
||||||
"""Set up UPnP/IGD-device from a config entry."""
|
"""Set up UPnP/IGD-device from a config entry."""
|
||||||
ensure_domain_data(hass)
|
await async_ensure_domain_data(hass)
|
||||||
data = config_entry.data
|
data = config_entry.data
|
||||||
|
|
||||||
# build UPnP/IGD device
|
# build UPnP/IGD device
|
||||||
|
|
|
@ -5,6 +5,7 @@ import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant import data_entry_flow
|
from homeassistant import data_entry_flow
|
||||||
|
from homeassistant.util import get_local_ip
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_ENABLE_PORT_MAPPING, CONF_ENABLE_SENSORS,
|
CONF_ENABLE_PORT_MAPPING, CONF_ENABLE_SENSORS,
|
||||||
|
@ -13,7 +14,7 @@ from .const import (
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
|
||||||
def ensure_domain_data(hass):
|
async def async_ensure_domain_data(hass):
|
||||||
"""Ensure hass.data is filled properly."""
|
"""Ensure hass.data is filled properly."""
|
||||||
hass.data[DOMAIN] = hass.data.get(DOMAIN, {})
|
hass.data[DOMAIN] = hass.data.get(DOMAIN, {})
|
||||||
hass.data[DOMAIN]['devices'] = hass.data[DOMAIN].get('devices', {})
|
hass.data[DOMAIN]['devices'] = hass.data[DOMAIN].get('devices', {})
|
||||||
|
@ -24,6 +25,9 @@ def ensure_domain_data(hass):
|
||||||
'enable_port_mapping': False,
|
'enable_port_mapping': False,
|
||||||
'ports': {'hass': 'hass'},
|
'ports': {'hass': 'hass'},
|
||||||
})
|
})
|
||||||
|
if 'local_ip' not in hass.data[DOMAIN]:
|
||||||
|
hass.data[DOMAIN]['local_ip'] = \
|
||||||
|
await hass.async_add_executor_job(get_local_ip)
|
||||||
|
|
||||||
|
|
||||||
@config_entries.HANDLERS.register(DOMAIN)
|
@config_entries.HANDLERS.register(DOMAIN)
|
||||||
|
@ -64,7 +68,7 @@ class UpnpFlowHandler(data_entry_flow.FlowHandler):
|
||||||
This flow is triggered by the discovery component. It will check if the
|
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.
|
host is already configured and delegate to the import step if not.
|
||||||
"""
|
"""
|
||||||
ensure_domain_data(self.hass)
|
await async_ensure_domain_data(self.hass)
|
||||||
|
|
||||||
# store discovered device
|
# store discovered device
|
||||||
discovery_info['friendly_name'] = \
|
discovery_info['friendly_name'] = \
|
||||||
|
@ -91,7 +95,7 @@ class UpnpFlowHandler(data_entry_flow.FlowHandler):
|
||||||
|
|
||||||
async def async_step_user(self, user_input=None):
|
async def async_step_user(self, user_input=None):
|
||||||
"""Manual set up."""
|
"""Manual set up."""
|
||||||
ensure_domain_data(self.hass)
|
await async_ensure_domain_data(self.hass)
|
||||||
|
|
||||||
# if user input given, handle it
|
# if user input given, handle it
|
||||||
user_input = user_input or {}
|
user_input = user_input or {}
|
||||||
|
@ -132,13 +136,13 @@ class UpnpFlowHandler(data_entry_flow.FlowHandler):
|
||||||
|
|
||||||
async def async_step_import(self, import_info):
|
async def async_step_import(self, import_info):
|
||||||
"""Import a new UPnP/IGD as a config entry."""
|
"""Import a new UPnP/IGD as a config entry."""
|
||||||
ensure_domain_data(self.hass)
|
await async_ensure_domain_data(self.hass)
|
||||||
|
|
||||||
return await self._async_save_entry(import_info)
|
return await self._async_save_entry(import_info)
|
||||||
|
|
||||||
async def _async_save_entry(self, import_info):
|
async def _async_save_entry(self, import_info):
|
||||||
"""Store UPNP/IGD as new entry."""
|
"""Store UPNP/IGD as new entry."""
|
||||||
ensure_domain_data(self.hass)
|
await async_ensure_domain_data(self.hass)
|
||||||
|
|
||||||
# ensure we know the host
|
# ensure we know the host
|
||||||
name = import_info['name']
|
name = import_info['name']
|
||||||
|
|
|
@ -156,7 +156,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.12.7
|
async-upnp-client==0.13.0
|
||||||
|
|
||||||
# homeassistant.components.light.avion
|
# homeassistant.components.light.avion
|
||||||
# avion==0.7
|
# avion==0.7
|
||||||
|
|
|
@ -55,7 +55,7 @@ async def test_async_setup_no_auto_config(hass):
|
||||||
# no upnp
|
# no upnp
|
||||||
}
|
}
|
||||||
with MockDependency('netdisco.discovery'), \
|
with MockDependency('netdisco.discovery'), \
|
||||||
patch('homeassistant.components.upnp.get_local_ip',
|
patch('homeassistant.components.upnp.config_flow.get_local_ip',
|
||||||
return_value='192.168.1.10'):
|
return_value='192.168.1.10'):
|
||||||
await async_setup_component(hass, 'upnp', config)
|
await async_setup_component(hass, 'upnp', config)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -76,7 +76,7 @@ async def test_async_setup_auto_config(hass):
|
||||||
'upnp': {},
|
'upnp': {},
|
||||||
}
|
}
|
||||||
with MockDependency('netdisco.discovery'), \
|
with MockDependency('netdisco.discovery'), \
|
||||||
patch('homeassistant.components.upnp.get_local_ip',
|
patch('homeassistant.components.upnp.config_flow.get_local_ip',
|
||||||
return_value='192.168.1.10'):
|
return_value='192.168.1.10'):
|
||||||
await async_setup_component(hass, 'upnp', config)
|
await async_setup_component(hass, 'upnp', config)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -100,7 +100,7 @@ async def test_async_setup_auto_config_port_mapping(hass):
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
with MockDependency('netdisco.discovery'), \
|
with MockDependency('netdisco.discovery'), \
|
||||||
patch('homeassistant.components.upnp.get_local_ip',
|
patch('homeassistant.components.upnp.config_flow.get_local_ip',
|
||||||
return_value='192.168.1.10'):
|
return_value='192.168.1.10'):
|
||||||
await async_setup_component(hass, 'upnp', config)
|
await async_setup_component(hass, 'upnp', config)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -121,7 +121,7 @@ async def test_async_setup_auto_config_no_sensors(hass):
|
||||||
'upnp': {'sensors': False},
|
'upnp': {'sensors': False},
|
||||||
}
|
}
|
||||||
with MockDependency('netdisco.discovery'), \
|
with MockDependency('netdisco.discovery'), \
|
||||||
patch('homeassistant.components.upnp.get_local_ip',
|
patch('homeassistant.components.upnp.config_flow.get_local_ip',
|
||||||
return_value='192.168.1.10'):
|
return_value='192.168.1.10'):
|
||||||
await async_setup_component(hass, 'upnp', config)
|
await async_setup_component(hass, 'upnp', config)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -150,7 +150,7 @@ async def test_async_setup_entry_default(hass):
|
||||||
# no upnp
|
# no upnp
|
||||||
}
|
}
|
||||||
with MockDependency('netdisco.discovery'), \
|
with MockDependency('netdisco.discovery'), \
|
||||||
patch('homeassistant.components.upnp.get_local_ip',
|
patch('homeassistant.components.upnp.config_flow.get_local_ip',
|
||||||
return_value='192.168.1.10'):
|
return_value='192.168.1.10'):
|
||||||
await async_setup_component(hass, 'http', config)
|
await async_setup_component(hass, 'http', config)
|
||||||
await async_setup_component(hass, 'upnp', config)
|
await async_setup_component(hass, 'upnp', config)
|
||||||
|
@ -160,7 +160,7 @@ async def test_async_setup_entry_default(hass):
|
||||||
mock_device = MockDevice(udn)
|
mock_device = MockDevice(udn)
|
||||||
with patch.object(Device, 'async_create_device') as create_device:
|
with patch.object(Device, 'async_create_device') as create_device:
|
||||||
create_device.return_value = mock_coro(return_value=mock_device)
|
create_device.return_value = mock_coro(return_value=mock_device)
|
||||||
with patch('homeassistant.components.upnp.get_local_ip',
|
with patch('homeassistant.components.upnp.config_flow.get_local_ip',
|
||||||
return_value='192.168.1.10'):
|
return_value='192.168.1.10'):
|
||||||
assert await upnp.async_setup_entry(hass, entry) is True
|
assert await upnp.async_setup_entry(hass, entry) is True
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ async def test_async_setup_entry_port_mapping(hass):
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
with MockDependency('netdisco.discovery'), \
|
with MockDependency('netdisco.discovery'), \
|
||||||
patch('homeassistant.components.upnp.get_local_ip',
|
patch('homeassistant.components.upnp.config_flow.get_local_ip',
|
||||||
return_value='192.168.1.10'):
|
return_value='192.168.1.10'):
|
||||||
await async_setup_component(hass, 'http', config)
|
await async_setup_component(hass, 'http', config)
|
||||||
await async_setup_component(hass, 'upnp', config)
|
await async_setup_component(hass, 'upnp', config)
|
||||||
|
|
Loading…
Reference in New Issue