From 131dbd6c8e04a2996714849fa929caa2d183d87b Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sun, 6 Feb 2022 00:43:05 +0100 Subject: [PATCH] Move Plugwise logger into constants (#65842) --- homeassistant/components/plugwise/binary_sensor.py | 7 ++----- homeassistant/components/plugwise/climate.py | 14 ++++++-------- homeassistant/components/plugwise/config_flow.py | 6 ++---- homeassistant/components/plugwise/const.py | 6 +++++- homeassistant/components/plugwise/gateway.py | 8 +++----- homeassistant/components/plugwise/sensor.py | 11 ++++------- homeassistant/components/plugwise/switch.py | 12 ++++-------- 7 files changed, 26 insertions(+), 38 deletions(-) diff --git a/homeassistant/components/plugwise/binary_sensor.py b/homeassistant/components/plugwise/binary_sensor.py index d0bfe0a2fe7..ca65a66b4da 100644 --- a/homeassistant/components/plugwise/binary_sensor.py +++ b/homeassistant/components/plugwise/binary_sensor.py @@ -1,6 +1,4 @@ """Plugwise Binary Sensor component for Home Assistant.""" -import logging - from plugwise.smile import Smile from homeassistant.components.binary_sensor import BinarySensorEntity @@ -16,6 +14,7 @@ from .const import ( FLOW_OFF_ICON, FLOW_ON_ICON, IDLE_ICON, + LOGGER, NO_NOTIFICATION_ICON, NOTIFICATION_ICON, ) @@ -27,8 +26,6 @@ BINARY_SENSOR_MAP = { } SEVERITIES = ["other", "info", "warning", "error"] -_LOGGER = logging.getLogger(__name__) - async def async_setup_entry( hass: HomeAssistant, @@ -116,7 +113,7 @@ class PwBinarySensor(SmileBinarySensor): def _async_process_data(self) -> None: """Update the entity.""" if not (data := self._api.get_device_data(self._dev_id)): - _LOGGER.error("Received no data for device %s", self._binary_sensor) + LOGGER.error("Received no data for device %s", self._binary_sensor) self.async_write_ha_state() return diff --git a/homeassistant/components/plugwise/climate.py b/homeassistant/components/plugwise/climate.py index cba9b6a095a..1063254299e 100644 --- a/homeassistant/components/plugwise/climate.py +++ b/homeassistant/components/plugwise/climate.py @@ -1,5 +1,4 @@ """Plugwise Climate component for Home Assistant.""" -import logging from typing import Any from plugwise.exceptions import PlugwiseException @@ -27,6 +26,7 @@ from .const import ( DEFAULT_MAX_TEMP, DEFAULT_MIN_TEMP, DOMAIN, + LOGGER, SCHEDULE_OFF, SCHEDULE_ON, ) @@ -35,8 +35,6 @@ from .entity import PlugwiseEntity HVAC_MODES_HEAT_ONLY = [HVAC_MODE_HEAT, HVAC_MODE_AUTO] HVAC_MODES_HEAT_COOL = [HVAC_MODE_HEAT_COOL, HVAC_MODE_AUTO] -_LOGGER = logging.getLogger(__name__) - async def async_setup_entry( hass: HomeAssistant, @@ -119,9 +117,9 @@ class PwThermostat(PlugwiseEntity, ClimateEntity): self._attr_target_temperature = temperature self.async_write_ha_state() except PlugwiseException: - _LOGGER.error("Error while communicating to device") + LOGGER.error("Error while communicating to device") else: - _LOGGER.error("Invalid temperature requested") + LOGGER.error("Invalid temperature requested") async def async_set_hvac_mode(self, hvac_mode: str) -> None: """Set the hvac mode.""" @@ -136,7 +134,7 @@ class PwThermostat(PlugwiseEntity, ClimateEntity): ) self._attr_target_temperature = climate_data.get("schedule_temperature") except PlugwiseException: - _LOGGER.error("Error while communicating to device") + LOGGER.error("Error while communicating to device") try: await self._api.set_schedule_state( @@ -145,7 +143,7 @@ class PwThermostat(PlugwiseEntity, ClimateEntity): self._attr_hvac_mode = hvac_mode self.async_write_ha_state() except PlugwiseException: - _LOGGER.error("Error while communicating to device") + LOGGER.error("Error while communicating to device") async def async_set_preset_mode(self, preset_mode: str) -> None: """Set the preset mode.""" @@ -158,7 +156,7 @@ class PwThermostat(PlugwiseEntity, ClimateEntity): self._attr_target_temperature = self._presets.get(preset_mode, "none")[0] self.async_write_ha_state() except PlugwiseException: - _LOGGER.error("Error while communicating to device") + LOGGER.error("Error while communicating to device") @callback def _async_process_data(self) -> None: diff --git a/homeassistant/components/plugwise/config_flow.py b/homeassistant/components/plugwise/config_flow.py index e611199ccf6..2ce8a686c8b 100644 --- a/homeassistant/components/plugwise/config_flow.py +++ b/homeassistant/components/plugwise/config_flow.py @@ -1,7 +1,6 @@ """Config flow for Plugwise integration.""" from __future__ import annotations -import logging from typing import Any from plugwise.exceptions import InvalidAuthentication, PlugwiseException @@ -29,6 +28,7 @@ from .const import ( DOMAIN, FLOW_SMILE, FLOW_STRETCH, + LOGGER, PW_TYPE, SMILE, STRETCH, @@ -36,8 +36,6 @@ from .const import ( ZEROCONF_MAP, ) -_LOGGER = logging.getLogger(__name__) - def _base_gw_schema(discovery_info): """Generate base schema for gateways.""" @@ -126,7 +124,7 @@ class PlugwiseConfigFlow(ConfigFlow, domain=DOMAIN): except PlugwiseException: errors[CONF_BASE] = "cannot_connect" except Exception: # pylint: disable=broad-except - _LOGGER.exception("Unexpected exception") + LOGGER.exception("Unexpected exception") errors[CONF_BASE] = "unknown" else: await self.async_set_unique_id( diff --git a/homeassistant/components/plugwise/const.py b/homeassistant/components/plugwise/const.py index cd31255a040..a885a047f7a 100644 --- a/homeassistant/components/plugwise/const.py +++ b/homeassistant/components/plugwise/const.py @@ -1,13 +1,17 @@ """Constants for Plugwise component.""" from datetime import timedelta +import logging from homeassistant.const import Platform +DOMAIN = "plugwise" + +LOGGER = logging.getLogger(__package__) + API = "api" ATTR_ILLUMINANCE = "illuminance" COORDINATOR = "coordinator" DEVICE_STATE = "device_state" -DOMAIN = "plugwise" FLOW_SMILE = "smile (Adam/Anna/P1)" FLOW_STRETCH = "stretch (Stretch)" FLOW_TYPE = "flow_type" diff --git a/homeassistant/components/plugwise/gateway.py b/homeassistant/components/plugwise/gateway.py index 611a9153cad..e851941cf27 100644 --- a/homeassistant/components/plugwise/gateway.py +++ b/homeassistant/components/plugwise/gateway.py @@ -2,7 +2,6 @@ from __future__ import annotations import asyncio -import logging import async_timeout from plugwise.exceptions import ( @@ -28,13 +27,12 @@ from .const import ( DEFAULT_USERNAME, DOMAIN, GATEWAY, + LOGGER, PLATFORMS_GATEWAY, PW_TYPE, SENSOR_PLATFORMS, ) -_LOGGER = logging.getLogger(__name__) - async def async_setup_entry_gw(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up Plugwise Smiles from a config entry.""" @@ -51,7 +49,7 @@ async def async_setup_entry_gw(hass: HomeAssistant, entry: ConfigEntry) -> bool: try: connected = await api.connect() except InvalidAuthentication: - _LOGGER.error("Invalid username or Smile ID") + LOGGER.error("Invalid username or Smile ID") return False except PlugwiseException as err: raise ConfigEntryNotReady( @@ -76,7 +74,7 @@ async def async_setup_entry_gw(hass: HomeAssistant, entry: ConfigEntry) -> bool: coordinator = DataUpdateCoordinator( hass, - _LOGGER, + LOGGER, name=f"Smile {api.smile_name}", update_method=async_update_data, update_interval=DEFAULT_SCAN_INTERVAL[api.smile_type], diff --git a/homeassistant/components/plugwise/sensor.py b/homeassistant/components/plugwise/sensor.py index 642a7a5e1e6..9d3f2d780b1 100644 --- a/homeassistant/components/plugwise/sensor.py +++ b/homeassistant/components/plugwise/sensor.py @@ -1,8 +1,6 @@ """Plugwise Sensor component for Home Assistant.""" from __future__ import annotations -import logging - from plugwise.smile import Smile from homeassistant.components.sensor import ( @@ -31,6 +29,7 @@ from .const import ( DOMAIN, FLAME_ICON, IDLE_ICON, + LOGGER, SENSOR_MAP_DEVICE_CLASS, SENSOR_MAP_MODEL, SENSOR_MAP_STATE_CLASS, @@ -39,8 +38,6 @@ from .const import ( ) from .entity import PlugwiseEntity -_LOGGER = logging.getLogger(__name__) - ATTR_TEMPERATURE = [ "Temperature", TEMP_CELSIUS, @@ -350,7 +347,7 @@ class PwThermostatSensor(SmileSensor): def _async_process_data(self) -> None: """Update the entity.""" if not (data := self._api.get_device_data(self._dev_id)): - _LOGGER.error("Received no data for device %s", self._entity_name) + LOGGER.error("Received no data for device %s", self._entity_name) self.async_write_ha_state() return @@ -382,7 +379,7 @@ class PwAuxDeviceSensor(SmileSensor): def _async_process_data(self) -> None: """Update the entity.""" if not (data := self._api.get_device_data(self._dev_id)): - _LOGGER.error("Received no data for device %s", self._entity_name) + LOGGER.error("Received no data for device %s", self._entity_name) self.async_write_ha_state() return @@ -434,7 +431,7 @@ class PwPowerSensor(SmileSensor): def _async_process_data(self) -> None: """Update the entity.""" if not (data := self._api.get_device_data(self._dev_id)): - _LOGGER.error("Received no data for device %s", self._entity_name) + LOGGER.error("Received no data for device %s", self._entity_name) self.async_write_ha_state() return diff --git a/homeassistant/components/plugwise/switch.py b/homeassistant/components/plugwise/switch.py index 161728a9474..c862983119a 100644 --- a/homeassistant/components/plugwise/switch.py +++ b/homeassistant/components/plugwise/switch.py @@ -1,6 +1,4 @@ """Plugwise Switch component for HomeAssistant.""" -import logging - from plugwise.exceptions import PlugwiseException from homeassistant.components.switch import SwitchEntity @@ -8,11 +6,9 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddEntitiesCallback -from .const import COORDINATOR, DOMAIN, SWITCH_ICON +from .const import COORDINATOR, DOMAIN, LOGGER, SWITCH_ICON from .entity import PlugwiseEntity -_LOGGER = logging.getLogger(__name__) - async def async_setup_entry( hass: HomeAssistant, @@ -90,7 +86,7 @@ class GwSwitch(PlugwiseEntity, SwitchEntity): self._is_on = True self.async_write_ha_state() except PlugwiseException: - _LOGGER.error("Error while communicating to device") + LOGGER.error("Error while communicating to device") async def async_turn_off(self, **kwargs): """Turn the device off.""" @@ -102,13 +98,13 @@ class GwSwitch(PlugwiseEntity, SwitchEntity): self._is_on = False self.async_write_ha_state() except PlugwiseException: - _LOGGER.error("Error while communicating to device") + LOGGER.error("Error while communicating to device") @callback def _async_process_data(self): """Update the data from the Plugs.""" if not (data := self._api.get_device_data(self._dev_id)): - _LOGGER.error("Received no data for device %s", self._name) + LOGGER.error("Received no data for device %s", self._name) self.async_write_ha_state() return