From 24e24a51579484a5c40fd9ec87b9cc4004e5a7ae Mon Sep 17 00:00:00 2001 From: Mick Vleeshouwer Date: Wed, 19 Jan 2022 07:19:49 -0800 Subject: [PATCH] Move logger to constants (#64431) --- homeassistant/components/overkiz/__init__.py | 14 ++++++-------- homeassistant/components/overkiz/config_flow.py | 9 +++------ homeassistant/components/overkiz/const.py | 2 ++ homeassistant/components/overkiz/coordinator.py | 8 +++----- homeassistant/components/overkiz/executor.py | 6 ++---- 5 files changed, 16 insertions(+), 23 deletions(-) diff --git a/homeassistant/components/overkiz/__init__.py b/homeassistant/components/overkiz/__init__.py index 8baad82d378..6bd95d6d1fc 100644 --- a/homeassistant/components/overkiz/__init__.py +++ b/homeassistant/components/overkiz/__init__.py @@ -4,7 +4,6 @@ from __future__ import annotations import asyncio from collections import defaultdict from dataclasses import dataclass -import logging from aiohttp import ClientError, ServerDisconnectedError from pyoverkiz.client import OverkizClient @@ -26,6 +25,7 @@ from homeassistant.helpers.aiohttp_client import async_create_clientsession from .const import ( CONF_HUB, DOMAIN, + LOGGER, OVERKIZ_DEVICE_TO_PLATFORM, PLATFORMS, UPDATE_INTERVAL, @@ -33,8 +33,6 @@ from .const import ( ) from .coordinator import OverkizDataUpdateCoordinator -_LOGGER = logging.getLogger(__name__) - @dataclass class HomeAssistantOverkizData: @@ -67,7 +65,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: ] ) except BadCredentialsException: - _LOGGER.error("Invalid authentication") + LOGGER.error("Invalid authentication") return False except TooManyRequestsException as exception: raise ConfigEntryNotReady("Too many requests, try again later") from exception @@ -78,7 +76,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: coordinator = OverkizDataUpdateCoordinator( hass, - _LOGGER, + LOGGER, name="device events", client=client, devices=setup.devices, @@ -90,7 +88,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: await coordinator.async_config_entry_first_refresh() if coordinator.is_stateless: - _LOGGER.debug( + LOGGER.debug( "All devices have an assumed state. Update interval has been reduced to: %s", UPDATE_INTERVAL_ALL_ASSUMED_STATE, ) @@ -104,7 +102,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: # Map Overkiz entities to Home Assistant platform for device in coordinator.data.values(): - _LOGGER.debug( + LOGGER.debug( "The following device has been retrieved. Report an issue if not supported correctly (%s)", device, ) @@ -119,7 +117,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: device_registry = dr.async_get(hass) for gateway in setup.gateways: - _LOGGER.debug("Added gateway (%s)", gateway) + LOGGER.debug("Added gateway (%s)", gateway) device_registry.async_get_or_create( config_entry_id=entry.entry_id, diff --git a/homeassistant/components/overkiz/config_flow.py b/homeassistant/components/overkiz/config_flow.py index 005a930c682..467bb9f007b 100644 --- a/homeassistant/components/overkiz/config_flow.py +++ b/homeassistant/components/overkiz/config_flow.py @@ -1,7 +1,6 @@ """Config flow for Overkiz (by Somfy) integration.""" from __future__ import annotations -import logging from typing import Any from aiohttp import ClientError @@ -21,9 +20,7 @@ from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.data_entry_flow import FlowResult from homeassistant.helpers.aiohttp_client import async_get_clientsession -from .const import CONF_HUB, DEFAULT_HUB, DOMAIN - -_LOGGER = logging.getLogger(__name__) +from .const import CONF_HUB, DEFAULT_HUB, DOMAIN, LOGGER class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): @@ -68,7 +65,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): errors["base"] = "server_in_maintenance" except Exception as exception: # pylint: disable=broad-except errors["base"] = "unknown" - _LOGGER.exception(exception) + LOGGER.exception(exception) else: self._abort_if_unique_id_configured() return self.async_create_entry( @@ -94,7 +91,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): hostname = discovery_info.hostname gateway_id = hostname[8:22] - _LOGGER.debug("DHCP discovery detected gateway %s", obfuscate_id(gateway_id)) + LOGGER.debug("DHCP discovery detected gateway %s", obfuscate_id(gateway_id)) await self.async_set_unique_id(gateway_id) self._abort_if_unique_id_configured() diff --git a/homeassistant/components/overkiz/const.py b/homeassistant/components/overkiz/const.py index 876ce37c67a..749d769d41e 100644 --- a/homeassistant/components/overkiz/const.py +++ b/homeassistant/components/overkiz/const.py @@ -2,6 +2,7 @@ from __future__ import annotations from datetime import timedelta +import logging from typing import Final from pyoverkiz.enums import UIClass @@ -10,6 +11,7 @@ from pyoverkiz.enums.ui import UIWidget from homeassistant.const import Platform DOMAIN: Final = "overkiz" +LOGGER: logging.Logger = logging.getLogger(__package__) CONF_HUB: Final = "hub" DEFAULT_HUB: Final = "somfy_europe" diff --git a/homeassistant/components/overkiz/coordinator.py b/homeassistant/components/overkiz/coordinator.py index 3d3121ab134..a931c11c984 100644 --- a/homeassistant/components/overkiz/coordinator.py +++ b/homeassistant/components/overkiz/coordinator.py @@ -20,9 +20,7 @@ from homeassistant.helpers import device_registry as dr from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from homeassistant.util.decorator import Registry -from .const import DOMAIN, UPDATE_INTERVAL - -_LOGGER = logging.getLogger(__name__) +from .const import DOMAIN, LOGGER, UPDATE_INTERVAL EVENT_HANDLERS = Registry() @@ -89,7 +87,7 @@ class OverkizDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Device]]): return self.devices for event in events: - _LOGGER.debug(event) + LOGGER.debug(event) if event_handler := EVENT_HANDLERS.get(event.name): await event_handler(self, event) @@ -101,7 +99,7 @@ class OverkizDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Device]]): async def _get_devices(self) -> dict[str, Device]: """Fetch devices.""" - _LOGGER.debug("Fetching all devices and state via /setup/devices") + LOGGER.debug("Fetching all devices and state via /setup/devices") return {d.device_url: d for d in await self.client.get_devices(refresh=True)} def _places_to_area(self, place: Place) -> dict[str, str]: diff --git a/homeassistant/components/overkiz/executor.py b/homeassistant/components/overkiz/executor.py index 0fdda36822e..43564d015f8 100644 --- a/homeassistant/components/overkiz/executor.py +++ b/homeassistant/components/overkiz/executor.py @@ -1,17 +1,15 @@ """Class for helpers and communication with the OverKiz API.""" from __future__ import annotations -import logging from typing import Any from urllib.parse import urlparse from pyoverkiz.models import Command, Device from pyoverkiz.types import StateType as OverkizStateType +from .const import LOGGER from .coordinator import OverkizDataUpdateCoordinator -_LOGGER = logging.getLogger(__name__) - class OverkizExecutor: """Representation of an Overkiz device with execution handler.""" @@ -67,7 +65,7 @@ class OverkizExecutor: "Home Assistant", ) except Exception as exception: # pylint: disable=broad-except - _LOGGER.error(exception) + LOGGER.error(exception) return # ExecutionRegisteredEvent doesn't contain the device_url, thus we need to register it here