mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Move logger to constants (#64431)
This commit is contained in:
parent
4c952f09ac
commit
24e24a5157
@ -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,
|
||||
|
@ -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()
|
||||
|
@ -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"
|
||||
|
@ -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]:
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user