From 43b11f6b390484788dc3b6d45e061a19944e30ed Mon Sep 17 00:00:00 2001
From: Robert Svensson <Kane610@users.noreply.github.com>
Date: Sat, 1 Feb 2020 20:02:57 +0100
Subject: [PATCH] deCONZ - Improve config flow logging (#31381)

---
 homeassistant/components/deconz/config_flow.py  | 12 ++++++++++++
 homeassistant/components/deconz/const.py        |  2 +-
 homeassistant/components/deconz/deconz_event.py |  4 ++--
 homeassistant/components/deconz/gateway.py      |  8 ++++----
 homeassistant/components/deconz/services.py     |  4 ++--
 5 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/homeassistant/components/deconz/config_flow.py b/homeassistant/components/deconz/config_flow.py
index 614d2378c88..3a38a67f0c6 100644
--- a/homeassistant/components/deconz/config_flow.py
+++ b/homeassistant/components/deconz/config_flow.py
@@ -1,5 +1,6 @@
 """Config flow to configure deCONZ component."""
 import asyncio
+from pprint import pformat
 from urllib.parse import urlparse
 
 import async_timeout
@@ -26,6 +27,7 @@ from .const import (
     DEFAULT_ALLOW_DECONZ_GROUPS,
     DEFAULT_PORT,
     DOMAIN,
+    LOGGER,
 )
 
 DECONZ_MANUFACTURERURL = "http://www.dresden-elektronik.de"
@@ -93,6 +95,8 @@ class DeconzFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
         except (asyncio.TimeoutError, ResponseError):
             self.bridges = []
 
+        LOGGER.debug("Discovered deCONZ gateways %s", pformat(self.bridges))
+
         if len(self.bridges) == 1:
             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."""
         errors = {}
 
+        LOGGER.debug(
+            "Preparing linking with deCONZ gateway %s", pformat(self.deconz_config)
+        )
+
         if user_input is not None:
             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")
 
+        LOGGER.debug("deCONZ SSDP discovery %s", pformat(discovery_info))
+
         self.bridge_id = normalize_bridge_id(discovery_info[ssdp.ATTR_UPNP_SERIAL])
         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.
         """
+        LOGGER.debug("deCONZ HASSIO discovery %s", pformat(user_input))
+
         self.bridge_id = normalize_bridge_id(user_input[CONF_SERIAL])
         await self.async_set_unique_id(self.bridge_id)
 
diff --git a/homeassistant/components/deconz/const.py b/homeassistant/components/deconz/const.py
index 293e0d9719c..11dbd07e86a 100644
--- a/homeassistant/components/deconz/const.py
+++ b/homeassistant/components/deconz/const.py
@@ -1,7 +1,7 @@
 """Constants for the deCONZ component."""
 import logging
 
-_LOGGER = logging.getLogger(__package__)
+LOGGER = logging.getLogger(__package__)
 
 DOMAIN = "deconz"
 
diff --git a/homeassistant/components/deconz/deconz_event.py b/homeassistant/components/deconz/deconz_event.py
index 527e8d2ab7a..aad133f583b 100644
--- a/homeassistant/components/deconz/deconz_event.py
+++ b/homeassistant/components/deconz/deconz_event.py
@@ -3,7 +3,7 @@ from homeassistant.const import CONF_EVENT, CONF_ID
 from homeassistant.core import callback
 from homeassistant.util import slugify
 
-from .const import _LOGGER, CONF_GESTURE
+from .const import CONF_GESTURE, LOGGER
 from .deconz_device import DeconzBase
 
 CONF_DECONZ_EVENT = "deconz_event"
@@ -25,7 +25,7 @@ class DeconzEvent(DeconzBase):
 
         self.device_id = None
         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
     def device(self):
diff --git a/homeassistant/components/deconz/gateway.py b/homeassistant/components/deconz/gateway.py
index 04452cc313c..f33e753e600 100644
--- a/homeassistant/components/deconz/gateway.py
+++ b/homeassistant/components/deconz/gateway.py
@@ -19,13 +19,13 @@ from homeassistant.helpers.entity_registry import (
 )
 
 from .const import (
-    _LOGGER,
     CONF_ALLOW_CLIP_SENSOR,
     CONF_ALLOW_DECONZ_GROUPS,
     CONF_MASTER_GATEWAY,
     DEFAULT_ALLOW_CLIP_SENSOR,
     DEFAULT_ALLOW_DECONZ_GROUPS,
     DOMAIN,
+    LOGGER,
     NEW_DEVICE,
     SUPPORTED_PLATFORMS,
 )
@@ -103,7 +103,7 @@ class DeconzGateway:
             raise ConfigEntryNotReady
 
         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
 
         for component in SUPPORTED_PLATFORMS:
@@ -221,11 +221,11 @@ async def get_gateway(
         return deconz
 
     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
 
     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
 
 
diff --git a/homeassistant/components/deconz/services.py b/homeassistant/components/deconz/services.py
index f1b19c79fce..c85fa8073a3 100644
--- a/homeassistant/components/deconz/services.py
+++ b/homeassistant/components/deconz/services.py
@@ -6,9 +6,9 @@ from homeassistant.helpers import config_validation as cv
 
 from .config_flow import get_master_gateway
 from .const import (
-    _LOGGER,
     CONF_BRIDGE_ID,
     DOMAIN,
+    LOGGER,
     NEW_GROUP,
     NEW_LIGHT,
     NEW_SCENE,
@@ -110,7 +110,7 @@ async def async_configure_service(hass, data):
         try:
             field = gateway.deconz_ids[entity_id] + field
         except KeyError:
-            _LOGGER.error("Could not find the entity %s", entity_id)
+            LOGGER.error("Could not find the entity %s", entity_id)
             return
 
     await gateway.api.request("put", field, json=data)