Use the shared Zeroconf instance in devolo_home_control (#40800)

pull/41171/head
Guido Schmitz 2020-10-03 22:31:19 +02:00 committed by GitHub
parent f9f17dc718
commit a73daa5f20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 9 deletions

View File

@ -4,7 +4,7 @@ from functools import partial
from devolo_home_control_api.homecontrol import HomeControl
from devolo_home_control_api.mydevolo import Mydevolo
from homeassistant.components import switch as ha_switch
from homeassistant.components import zeroconf
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, EVENT_HOMEASSISTANT_STOP
from homeassistant.exceptions import ConfigEntryNotReady
@ -12,8 +12,6 @@ from homeassistant.helpers.typing import HomeAssistantType
from .const import CONF_HOMECONTROL, CONF_MYDEVOLO, DOMAIN, PLATFORMS
SUPPORTED_PLATFORMS = [ha_switch.DOMAIN]
async def async_setup(hass, config):
"""Get all devices and add them to hass."""
@ -32,7 +30,6 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
mydevolo.user = conf[CONF_USERNAME]
mydevolo.password = conf[CONF_PASSWORD]
mydevolo.url = conf[CONF_MYDEVOLO]
mydevolo.mprm = conf[CONF_HOMECONTROL]
credentials_valid = await hass.async_add_executor_job(mydevolo.credentials_valid)
@ -44,11 +41,16 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
gateway_ids = await hass.async_add_executor_job(mydevolo.get_gateway_ids)
gateway_id = gateway_ids[0]
mprm_url = mydevolo.mprm
try:
zeroconf_instance = await zeroconf.async_get_instance(hass)
hass.data[DOMAIN]["homecontrol"] = await hass.async_add_executor_job(
partial(HomeControl, gateway_id=gateway_id, url=mprm_url)
partial(
HomeControl,
gateway_id=gateway_id,
zeroconf_instance=zeroconf_instance,
url=conf[CONF_HOMECONTROL],
)
)
except ConnectionError as err:
raise ConfigEntryNotReady from err

View File

@ -53,10 +53,10 @@ class DevoloHomeControlFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
mydevolo.password = password
if self.show_advanced_options:
mydevolo.url = user_input[CONF_MYDEVOLO]
mydevolo.mprm = user_input[CONF_HOMECONTROL]
mprm = user_input[CONF_HOMECONTROL]
else:
mydevolo.url = DEFAULT_MYDEVOLO
mydevolo.mprm = DEFAULT_MPRM
mprm = DEFAULT_MPRM
credentials_valid = await self.hass.async_add_executor_job(
mydevolo.credentials_valid
)
@ -73,7 +73,7 @@ class DevoloHomeControlFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
CONF_PASSWORD: password,
CONF_USERNAME: user,
CONF_MYDEVOLO: mydevolo.url,
CONF_HOMECONTROL: mydevolo.mprm,
CONF_HOMECONTROL: mprm,
},
)

View File

@ -3,6 +3,7 @@
"name": "devolo Home Control",
"documentation": "https://www.home-assistant.io/integrations/devolo_home_control",
"requirements": ["devolo-home-control-api==0.15.0"],
"after_dependencies": ["zeroconf"],
"config_flow": true,
"codeowners": ["@2Fake", "@Shutgun"],
"quality_scale": "silver"