Centralize all usages of host as a configuration param to the constant CONF_HOST (#22458)

* Centralize all usages of  as a configuration param to the constant CONF_HOST

* Clean up test
This commit is contained in:
Rohan Kapoor authored and Paulus Schoutsen committed 2019-03-27 19:48:05 -07:00
1 parent 9176e13a97
commit 78e162c1d3
16 files changed
+61 -66

No files matched your search

+3 -4
View File
@@ -8,14 +8,13 @@ import async_timeout
import voluptuous as vol
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import CONF_HOSTS
from homeassistant.const import CONF_HOSTS, CONF_HOST
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.util import Throttle
from . import config_flow # noqa pylint_disable=unused-import
from .const import KEY_HOST
REQUIREMENTS = ['pydaikin==1.3.1']
@@ -53,7 +52,7 @@ async def async_setup(hass, config):
DOMAIN,
context={'source': SOURCE_IMPORT},
data={
KEY_HOST: host,
CONF_HOST: host,
}))
return True
@@ -61,7 +60,7 @@ async def async_setup(hass, config):
async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
"""Establish connection with Daikin."""
conf = entry.data
daikin_api = await daikin_api_setup(hass, conf[KEY_HOST])
daikin_api = await daikin_api_setup(hass, conf[CONF_HOST])
if not daikin_api:
return False
hass.data.setdefault(DOMAIN, {}).update({entry.entry_id: daikin_api})
@@ -6,8 +6,9 @@ import async_timeout
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.const import CONF_HOST
from .const import KEY_HOST, KEY_IP, KEY_MAC
from .const import KEY_IP, KEY_MAC
_LOGGER = logging.getLogger(__name__)
@@ -29,7 +30,7 @@ class FlowHandler(config_entries.ConfigFlow):
return self.async_create_entry(
title=host,
data={
KEY_HOST: host,
CONF_HOST: host,
KEY_MAC: mac
})
@@ -55,14 +56,14 @@ class FlowHandler(config_entries.ConfigFlow):
return self.async_show_form(
step_id='user',
data_schema=vol.Schema({
vol.Required(KEY_HOST): str
vol.Required(CONF_HOST): str
})
)
return await self._create_device(user_input[KEY_HOST])
return await self._create_device(user_input[CONF_HOST])
async def async_step_import(self, user_input):
"""Import a config entry."""
host = user_input.get(KEY_HOST)
host = user_input.get(CONF_HOST)
if not host:
return await self.async_step_user()
return await self._create_device(host)
-1
View File
@@ -20,6 +20,5 @@ SENSOR_TYPES = {
}
}
KEY_HOST = 'host'
KEY_MAC = 'mac'
KEY_IP = 'ip'