Move Plugwise logger into constants (#65842)
parent
a6e36a6eb9
commit
131dbd6c8e
|
@ -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
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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],
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue