deCONZ - Improve config flow logging (#31381)

This commit is contained in:
Robert Svensson 2020-02-01 20:02:57 +01:00 committed by GitHub
parent e0704d73cc
commit 43b11f6b39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 9 deletions

View File

@ -1,5 +1,6 @@
"""Config flow to configure deCONZ component.""" """Config flow to configure deCONZ component."""
import asyncio import asyncio
from pprint import pformat
from urllib.parse import urlparse from urllib.parse import urlparse
import async_timeout import async_timeout
@ -26,6 +27,7 @@ from .const import (
DEFAULT_ALLOW_DECONZ_GROUPS, DEFAULT_ALLOW_DECONZ_GROUPS,
DEFAULT_PORT, DEFAULT_PORT,
DOMAIN, DOMAIN,
LOGGER,
) )
DECONZ_MANUFACTURERURL = "http://www.dresden-elektronik.de" DECONZ_MANUFACTURERURL = "http://www.dresden-elektronik.de"
@ -93,6 +95,8 @@ class DeconzFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
except (asyncio.TimeoutError, ResponseError): except (asyncio.TimeoutError, ResponseError):
self.bridges = [] self.bridges = []
LOGGER.debug("Discovered deCONZ gateways %s", pformat(self.bridges))
if len(self.bridges) == 1: if len(self.bridges) == 1:
return await self.async_step_user(self.bridges[0]) return await self.async_step_user(self.bridges[0])
@ -121,6 +125,10 @@ class DeconzFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
"""Attempt to link with the deCONZ bridge.""" """Attempt to link with the deCONZ bridge."""
errors = {} errors = {}
LOGGER.debug(
"Preparing linking with deCONZ gateway %s", pformat(self.deconz_config)
)
if user_input is not None: if user_input is not None:
session = aiohttp_client.async_get_clientsession(self.hass) session = aiohttp_client.async_get_clientsession(self.hass)
@ -170,6 +178,8 @@ class DeconzFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
): ):
return self.async_abort(reason="not_deconz_bridge") return self.async_abort(reason="not_deconz_bridge")
LOGGER.debug("deCONZ SSDP discovery %s", pformat(discovery_info))
self.bridge_id = normalize_bridge_id(discovery_info[ssdp.ATTR_UPNP_SERIAL]) self.bridge_id = normalize_bridge_id(discovery_info[ssdp.ATTR_UPNP_SERIAL])
parsed_url = urlparse(discovery_info[ssdp.ATTR_SSDP_LOCATION]) parsed_url = urlparse(discovery_info[ssdp.ATTR_SSDP_LOCATION])
@ -196,6 +206,8 @@ class DeconzFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
This flow is triggered by the discovery component. This flow is triggered by the discovery component.
""" """
LOGGER.debug("deCONZ HASSIO discovery %s", pformat(user_input))
self.bridge_id = normalize_bridge_id(user_input[CONF_SERIAL]) self.bridge_id = normalize_bridge_id(user_input[CONF_SERIAL])
await self.async_set_unique_id(self.bridge_id) await self.async_set_unique_id(self.bridge_id)

View File

@ -1,7 +1,7 @@
"""Constants for the deCONZ component.""" """Constants for the deCONZ component."""
import logging import logging
_LOGGER = logging.getLogger(__package__) LOGGER = logging.getLogger(__package__)
DOMAIN = "deconz" DOMAIN = "deconz"

View File

@ -3,7 +3,7 @@ from homeassistant.const import CONF_EVENT, CONF_ID
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.util import slugify from homeassistant.util import slugify
from .const import _LOGGER, CONF_GESTURE from .const import CONF_GESTURE, LOGGER
from .deconz_device import DeconzBase from .deconz_device import DeconzBase
CONF_DECONZ_EVENT = "deconz_event" CONF_DECONZ_EVENT = "deconz_event"
@ -25,7 +25,7 @@ class DeconzEvent(DeconzBase):
self.device_id = None self.device_id = None
self.event_id = slugify(self._device.name) self.event_id = slugify(self._device.name)
_LOGGER.debug("deCONZ event created: %s", self.event_id) LOGGER.debug("deCONZ event created: %s", self.event_id)
@property @property
def device(self): def device(self):

View File

@ -19,13 +19,13 @@ from homeassistant.helpers.entity_registry import (
) )
from .const import ( from .const import (
_LOGGER,
CONF_ALLOW_CLIP_SENSOR, CONF_ALLOW_CLIP_SENSOR,
CONF_ALLOW_DECONZ_GROUPS, CONF_ALLOW_DECONZ_GROUPS,
CONF_MASTER_GATEWAY, CONF_MASTER_GATEWAY,
DEFAULT_ALLOW_CLIP_SENSOR, DEFAULT_ALLOW_CLIP_SENSOR,
DEFAULT_ALLOW_DECONZ_GROUPS, DEFAULT_ALLOW_DECONZ_GROUPS,
DOMAIN, DOMAIN,
LOGGER,
NEW_DEVICE, NEW_DEVICE,
SUPPORTED_PLATFORMS, SUPPORTED_PLATFORMS,
) )
@ -103,7 +103,7 @@ class DeconzGateway:
raise ConfigEntryNotReady raise ConfigEntryNotReady
except Exception as err: # pylint: disable=broad-except except Exception as err: # pylint: disable=broad-except
_LOGGER.error("Error connecting with deCONZ gateway: %s", err) LOGGER.error("Error connecting with deCONZ gateway: %s", err)
return False return False
for component in SUPPORTED_PLATFORMS: for component in SUPPORTED_PLATFORMS:
@ -221,11 +221,11 @@ async def get_gateway(
return deconz return deconz
except errors.Unauthorized: except errors.Unauthorized:
_LOGGER.warning("Invalid key for deCONZ at %s", config[CONF_HOST]) LOGGER.warning("Invalid key for deCONZ at %s", config[CONF_HOST])
raise AuthenticationRequired raise AuthenticationRequired
except (asyncio.TimeoutError, errors.RequestError): except (asyncio.TimeoutError, errors.RequestError):
_LOGGER.error("Error connecting to deCONZ gateway at %s", config[CONF_HOST]) LOGGER.error("Error connecting to deCONZ gateway at %s", config[CONF_HOST])
raise CannotConnect raise CannotConnect

View File

@ -6,9 +6,9 @@ from homeassistant.helpers import config_validation as cv
from .config_flow import get_master_gateway from .config_flow import get_master_gateway
from .const import ( from .const import (
_LOGGER,
CONF_BRIDGE_ID, CONF_BRIDGE_ID,
DOMAIN, DOMAIN,
LOGGER,
NEW_GROUP, NEW_GROUP,
NEW_LIGHT, NEW_LIGHT,
NEW_SCENE, NEW_SCENE,
@ -110,7 +110,7 @@ async def async_configure_service(hass, data):
try: try:
field = gateway.deconz_ids[entity_id] + field field = gateway.deconz_ids[entity_id] + field
except KeyError: except KeyError:
_LOGGER.error("Could not find the entity %s", entity_id) LOGGER.error("Could not find the entity %s", entity_id)
return return
await gateway.api.request("put", field, json=data) await gateway.api.request("put", field, json=data)