Move Plugwise logger into constants (#65842)

pull/65860/head
Franck Nijhof 2022-02-06 00:43:05 +01:00 committed by GitHub
parent a6e36a6eb9
commit 131dbd6c8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 26 additions and 38 deletions

View File

@ -1,6 +1,4 @@
"""Plugwise Binary Sensor component for Home Assistant.""" """Plugwise Binary Sensor component for Home Assistant."""
import logging
from plugwise.smile import Smile from plugwise.smile import Smile
from homeassistant.components.binary_sensor import BinarySensorEntity from homeassistant.components.binary_sensor import BinarySensorEntity
@ -16,6 +14,7 @@ from .const import (
FLOW_OFF_ICON, FLOW_OFF_ICON,
FLOW_ON_ICON, FLOW_ON_ICON,
IDLE_ICON, IDLE_ICON,
LOGGER,
NO_NOTIFICATION_ICON, NO_NOTIFICATION_ICON,
NOTIFICATION_ICON, NOTIFICATION_ICON,
) )
@ -27,8 +26,6 @@ BINARY_SENSOR_MAP = {
} }
SEVERITIES = ["other", "info", "warning", "error"] SEVERITIES = ["other", "info", "warning", "error"]
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry( async def async_setup_entry(
hass: HomeAssistant, hass: HomeAssistant,
@ -116,7 +113,7 @@ class PwBinarySensor(SmileBinarySensor):
def _async_process_data(self) -> None: def _async_process_data(self) -> None:
"""Update the entity.""" """Update the entity."""
if not (data := self._api.get_device_data(self._dev_id)): 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() self.async_write_ha_state()
return return

View File

@ -1,5 +1,4 @@
"""Plugwise Climate component for Home Assistant.""" """Plugwise Climate component for Home Assistant."""
import logging
from typing import Any from typing import Any
from plugwise.exceptions import PlugwiseException from plugwise.exceptions import PlugwiseException
@ -27,6 +26,7 @@ from .const import (
DEFAULT_MAX_TEMP, DEFAULT_MAX_TEMP,
DEFAULT_MIN_TEMP, DEFAULT_MIN_TEMP,
DOMAIN, DOMAIN,
LOGGER,
SCHEDULE_OFF, SCHEDULE_OFF,
SCHEDULE_ON, SCHEDULE_ON,
) )
@ -35,8 +35,6 @@ from .entity import PlugwiseEntity
HVAC_MODES_HEAT_ONLY = [HVAC_MODE_HEAT, HVAC_MODE_AUTO] HVAC_MODES_HEAT_ONLY = [HVAC_MODE_HEAT, HVAC_MODE_AUTO]
HVAC_MODES_HEAT_COOL = [HVAC_MODE_HEAT_COOL, HVAC_MODE_AUTO] HVAC_MODES_HEAT_COOL = [HVAC_MODE_HEAT_COOL, HVAC_MODE_AUTO]
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry( async def async_setup_entry(
hass: HomeAssistant, hass: HomeAssistant,
@ -119,9 +117,9 @@ class PwThermostat(PlugwiseEntity, ClimateEntity):
self._attr_target_temperature = temperature self._attr_target_temperature = temperature
self.async_write_ha_state() self.async_write_ha_state()
except PlugwiseException: except PlugwiseException:
_LOGGER.error("Error while communicating to device") LOGGER.error("Error while communicating to device")
else: else:
_LOGGER.error("Invalid temperature requested") LOGGER.error("Invalid temperature requested")
async def async_set_hvac_mode(self, hvac_mode: str) -> None: async def async_set_hvac_mode(self, hvac_mode: str) -> None:
"""Set the hvac mode.""" """Set the hvac mode."""
@ -136,7 +134,7 @@ class PwThermostat(PlugwiseEntity, ClimateEntity):
) )
self._attr_target_temperature = climate_data.get("schedule_temperature") self._attr_target_temperature = climate_data.get("schedule_temperature")
except PlugwiseException: except PlugwiseException:
_LOGGER.error("Error while communicating to device") LOGGER.error("Error while communicating to device")
try: try:
await self._api.set_schedule_state( await self._api.set_schedule_state(
@ -145,7 +143,7 @@ class PwThermostat(PlugwiseEntity, ClimateEntity):
self._attr_hvac_mode = hvac_mode self._attr_hvac_mode = hvac_mode
self.async_write_ha_state() self.async_write_ha_state()
except PlugwiseException: 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: async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set the preset mode.""" """Set the preset mode."""
@ -158,7 +156,7 @@ class PwThermostat(PlugwiseEntity, ClimateEntity):
self._attr_target_temperature = self._presets.get(preset_mode, "none")[0] self._attr_target_temperature = self._presets.get(preset_mode, "none")[0]
self.async_write_ha_state() self.async_write_ha_state()
except PlugwiseException: except PlugwiseException:
_LOGGER.error("Error while communicating to device") LOGGER.error("Error while communicating to device")
@callback @callback
def _async_process_data(self) -> None: def _async_process_data(self) -> None:

View File

@ -1,7 +1,6 @@
"""Config flow for Plugwise integration.""" """Config flow for Plugwise integration."""
from __future__ import annotations from __future__ import annotations
import logging
from typing import Any from typing import Any
from plugwise.exceptions import InvalidAuthentication, PlugwiseException from plugwise.exceptions import InvalidAuthentication, PlugwiseException
@ -29,6 +28,7 @@ from .const import (
DOMAIN, DOMAIN,
FLOW_SMILE, FLOW_SMILE,
FLOW_STRETCH, FLOW_STRETCH,
LOGGER,
PW_TYPE, PW_TYPE,
SMILE, SMILE,
STRETCH, STRETCH,
@ -36,8 +36,6 @@ from .const import (
ZEROCONF_MAP, ZEROCONF_MAP,
) )
_LOGGER = logging.getLogger(__name__)
def _base_gw_schema(discovery_info): def _base_gw_schema(discovery_info):
"""Generate base schema for gateways.""" """Generate base schema for gateways."""
@ -126,7 +124,7 @@ class PlugwiseConfigFlow(ConfigFlow, domain=DOMAIN):
except PlugwiseException: except PlugwiseException:
errors[CONF_BASE] = "cannot_connect" errors[CONF_BASE] = "cannot_connect"
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
_LOGGER.exception("Unexpected exception") LOGGER.exception("Unexpected exception")
errors[CONF_BASE] = "unknown" errors[CONF_BASE] = "unknown"
else: else:
await self.async_set_unique_id( await self.async_set_unique_id(

View File

@ -1,13 +1,17 @@
"""Constants for Plugwise component.""" """Constants for Plugwise component."""
from datetime import timedelta from datetime import timedelta
import logging
from homeassistant.const import Platform from homeassistant.const import Platform
DOMAIN = "plugwise"
LOGGER = logging.getLogger(__package__)
API = "api" API = "api"
ATTR_ILLUMINANCE = "illuminance" ATTR_ILLUMINANCE = "illuminance"
COORDINATOR = "coordinator" COORDINATOR = "coordinator"
DEVICE_STATE = "device_state" DEVICE_STATE = "device_state"
DOMAIN = "plugwise"
FLOW_SMILE = "smile (Adam/Anna/P1)" FLOW_SMILE = "smile (Adam/Anna/P1)"
FLOW_STRETCH = "stretch (Stretch)" FLOW_STRETCH = "stretch (Stretch)"
FLOW_TYPE = "flow_type" FLOW_TYPE = "flow_type"

View File

@ -2,7 +2,6 @@
from __future__ import annotations from __future__ import annotations
import asyncio import asyncio
import logging
import async_timeout import async_timeout
from plugwise.exceptions import ( from plugwise.exceptions import (
@ -28,13 +27,12 @@ from .const import (
DEFAULT_USERNAME, DEFAULT_USERNAME,
DOMAIN, DOMAIN,
GATEWAY, GATEWAY,
LOGGER,
PLATFORMS_GATEWAY, PLATFORMS_GATEWAY,
PW_TYPE, PW_TYPE,
SENSOR_PLATFORMS, SENSOR_PLATFORMS,
) )
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry_gw(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_setup_entry_gw(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Plugwise Smiles from a config entry.""" """Set up Plugwise Smiles from a config entry."""
@ -51,7 +49,7 @@ async def async_setup_entry_gw(hass: HomeAssistant, entry: ConfigEntry) -> bool:
try: try:
connected = await api.connect() connected = await api.connect()
except InvalidAuthentication: except InvalidAuthentication:
_LOGGER.error("Invalid username or Smile ID") LOGGER.error("Invalid username or Smile ID")
return False return False
except PlugwiseException as err: except PlugwiseException as err:
raise ConfigEntryNotReady( raise ConfigEntryNotReady(
@ -76,7 +74,7 @@ async def async_setup_entry_gw(hass: HomeAssistant, entry: ConfigEntry) -> bool:
coordinator = DataUpdateCoordinator( coordinator = DataUpdateCoordinator(
hass, hass,
_LOGGER, LOGGER,
name=f"Smile {api.smile_name}", name=f"Smile {api.smile_name}",
update_method=async_update_data, update_method=async_update_data,
update_interval=DEFAULT_SCAN_INTERVAL[api.smile_type], update_interval=DEFAULT_SCAN_INTERVAL[api.smile_type],

View File

@ -1,8 +1,6 @@
"""Plugwise Sensor component for Home Assistant.""" """Plugwise Sensor component for Home Assistant."""
from __future__ import annotations from __future__ import annotations
import logging
from plugwise.smile import Smile from plugwise.smile import Smile
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
@ -31,6 +29,7 @@ from .const import (
DOMAIN, DOMAIN,
FLAME_ICON, FLAME_ICON,
IDLE_ICON, IDLE_ICON,
LOGGER,
SENSOR_MAP_DEVICE_CLASS, SENSOR_MAP_DEVICE_CLASS,
SENSOR_MAP_MODEL, SENSOR_MAP_MODEL,
SENSOR_MAP_STATE_CLASS, SENSOR_MAP_STATE_CLASS,
@ -39,8 +38,6 @@ from .const import (
) )
from .entity import PlugwiseEntity from .entity import PlugwiseEntity
_LOGGER = logging.getLogger(__name__)
ATTR_TEMPERATURE = [ ATTR_TEMPERATURE = [
"Temperature", "Temperature",
TEMP_CELSIUS, TEMP_CELSIUS,
@ -350,7 +347,7 @@ class PwThermostatSensor(SmileSensor):
def _async_process_data(self) -> None: def _async_process_data(self) -> None:
"""Update the entity.""" """Update the entity."""
if not (data := self._api.get_device_data(self._dev_id)): 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() self.async_write_ha_state()
return return
@ -382,7 +379,7 @@ class PwAuxDeviceSensor(SmileSensor):
def _async_process_data(self) -> None: def _async_process_data(self) -> None:
"""Update the entity.""" """Update the entity."""
if not (data := self._api.get_device_data(self._dev_id)): 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() self.async_write_ha_state()
return return
@ -434,7 +431,7 @@ class PwPowerSensor(SmileSensor):
def _async_process_data(self) -> None: def _async_process_data(self) -> None:
"""Update the entity.""" """Update the entity."""
if not (data := self._api.get_device_data(self._dev_id)): 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() self.async_write_ha_state()
return return

View File

@ -1,6 +1,4 @@
"""Plugwise Switch component for HomeAssistant.""" """Plugwise Switch component for HomeAssistant."""
import logging
from plugwise.exceptions import PlugwiseException from plugwise.exceptions import PlugwiseException
from homeassistant.components.switch import SwitchEntity from homeassistant.components.switch import SwitchEntity
@ -8,11 +6,9 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback 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 from .entity import PlugwiseEntity
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry( async def async_setup_entry(
hass: HomeAssistant, hass: HomeAssistant,
@ -90,7 +86,7 @@ class GwSwitch(PlugwiseEntity, SwitchEntity):
self._is_on = True self._is_on = True
self.async_write_ha_state() self.async_write_ha_state()
except PlugwiseException: except PlugwiseException:
_LOGGER.error("Error while communicating to device") LOGGER.error("Error while communicating to device")
async def async_turn_off(self, **kwargs): async def async_turn_off(self, **kwargs):
"""Turn the device off.""" """Turn the device off."""
@ -102,13 +98,13 @@ class GwSwitch(PlugwiseEntity, SwitchEntity):
self._is_on = False self._is_on = False
self.async_write_ha_state() self.async_write_ha_state()
except PlugwiseException: except PlugwiseException:
_LOGGER.error("Error while communicating to device") LOGGER.error("Error while communicating to device")
@callback @callback
def _async_process_data(self): def _async_process_data(self):
"""Update the data from the Plugs.""" """Update the data from the Plugs."""
if not (data := self._api.get_device_data(self._dev_id)): 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() self.async_write_ha_state()
return return