1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

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:
Steven Looman
2018-10-29 08:10:01 +01:00
committed by Paulus Schoutsen
parent 851d7e22e7
commit 96c5e4c507
5 changed files with 22 additions and 22 deletions

View File

@@ -5,6 +5,7 @@ import voluptuous as vol
from homeassistant import config_entries
from homeassistant import data_entry_flow
from homeassistant.util import get_local_ip
from .const import (
CONF_ENABLE_PORT_MAPPING, CONF_ENABLE_SENSORS,
@@ -13,7 +14,7 @@ from .const import (
from .const import DOMAIN
def ensure_domain_data(hass):
async def async_ensure_domain_data(hass):
"""Ensure hass.data is filled properly."""
hass.data[DOMAIN] = hass.data.get(DOMAIN, {})
hass.data[DOMAIN]['devices'] = hass.data[DOMAIN].get('devices', {})
@@ -24,6 +25,9 @@ def ensure_domain_data(hass):
'enable_port_mapping': False,
'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)
@@ -64,7 +68,7 @@ class UpnpFlowHandler(data_entry_flow.FlowHandler):
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.
"""
ensure_domain_data(self.hass)
await async_ensure_domain_data(self.hass)
# store discovered device
discovery_info['friendly_name'] = \
@@ -91,7 +95,7 @@ class UpnpFlowHandler(data_entry_flow.FlowHandler):
async def async_step_user(self, user_input=None):
"""Manual set up."""
ensure_domain_data(self.hass)
await async_ensure_domain_data(self.hass)
# if user input given, handle it
user_input = user_input or {}
@@ -132,13 +136,13 @@ class UpnpFlowHandler(data_entry_flow.FlowHandler):
async def async_step_import(self, import_info):
"""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)
async def _async_save_entry(self, import_info):
"""Store UPNP/IGD as new entry."""
ensure_domain_data(self.hass)
await async_ensure_domain_data(self.hass)
# ensure we know the host
name = import_info['name']