mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +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
|
import asyncio
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import logging
|
|
||||||
|
|
||||||
from aiohttp import ClientError, ServerDisconnectedError
|
from aiohttp import ClientError, ServerDisconnectedError
|
||||||
from pyoverkiz.client import OverkizClient
|
from pyoverkiz.client import OverkizClient
|
||||||
@ -26,6 +25,7 @@ from homeassistant.helpers.aiohttp_client import async_create_clientsession
|
|||||||
from .const import (
|
from .const import (
|
||||||
CONF_HUB,
|
CONF_HUB,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
LOGGER,
|
||||||
OVERKIZ_DEVICE_TO_PLATFORM,
|
OVERKIZ_DEVICE_TO_PLATFORM,
|
||||||
PLATFORMS,
|
PLATFORMS,
|
||||||
UPDATE_INTERVAL,
|
UPDATE_INTERVAL,
|
||||||
@ -33,8 +33,6 @@ from .const import (
|
|||||||
)
|
)
|
||||||
from .coordinator import OverkizDataUpdateCoordinator
|
from .coordinator import OverkizDataUpdateCoordinator
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class HomeAssistantOverkizData:
|
class HomeAssistantOverkizData:
|
||||||
@ -67,7 +65,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
except BadCredentialsException:
|
except BadCredentialsException:
|
||||||
_LOGGER.error("Invalid authentication")
|
LOGGER.error("Invalid authentication")
|
||||||
return False
|
return False
|
||||||
except TooManyRequestsException as exception:
|
except TooManyRequestsException as exception:
|
||||||
raise ConfigEntryNotReady("Too many requests, try again later") from 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(
|
coordinator = OverkizDataUpdateCoordinator(
|
||||||
hass,
|
hass,
|
||||||
_LOGGER,
|
LOGGER,
|
||||||
name="device events",
|
name="device events",
|
||||||
client=client,
|
client=client,
|
||||||
devices=setup.devices,
|
devices=setup.devices,
|
||||||
@ -90,7 +88,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
if coordinator.is_stateless:
|
if coordinator.is_stateless:
|
||||||
_LOGGER.debug(
|
LOGGER.debug(
|
||||||
"All devices have an assumed state. Update interval has been reduced to: %s",
|
"All devices have an assumed state. Update interval has been reduced to: %s",
|
||||||
UPDATE_INTERVAL_ALL_ASSUMED_STATE,
|
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
|
# Map Overkiz entities to Home Assistant platform
|
||||||
for device in coordinator.data.values():
|
for device in coordinator.data.values():
|
||||||
_LOGGER.debug(
|
LOGGER.debug(
|
||||||
"The following device has been retrieved. Report an issue if not supported correctly (%s)",
|
"The following device has been retrieved. Report an issue if not supported correctly (%s)",
|
||||||
device,
|
device,
|
||||||
)
|
)
|
||||||
@ -119,7 +117,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
device_registry = dr.async_get(hass)
|
device_registry = dr.async_get(hass)
|
||||||
|
|
||||||
for gateway in setup.gateways:
|
for gateway in setup.gateways:
|
||||||
_LOGGER.debug("Added gateway (%s)", gateway)
|
LOGGER.debug("Added gateway (%s)", gateway)
|
||||||
|
|
||||||
device_registry.async_get_or_create(
|
device_registry.async_get_or_create(
|
||||||
config_entry_id=entry.entry_id,
|
config_entry_id=entry.entry_id,
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
"""Config flow for Overkiz (by Somfy) integration."""
|
"""Config flow for Overkiz (by Somfy) integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from aiohttp import ClientError
|
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.data_entry_flow import FlowResult
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
|
|
||||||
from .const import CONF_HUB, DEFAULT_HUB, DOMAIN
|
from .const import CONF_HUB, DEFAULT_HUB, DOMAIN, LOGGER
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
@ -68,7 +65,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
errors["base"] = "server_in_maintenance"
|
errors["base"] = "server_in_maintenance"
|
||||||
except Exception as exception: # pylint: disable=broad-except
|
except Exception as exception: # pylint: disable=broad-except
|
||||||
errors["base"] = "unknown"
|
errors["base"] = "unknown"
|
||||||
_LOGGER.exception(exception)
|
LOGGER.exception(exception)
|
||||||
else:
|
else:
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
@ -94,7 +91,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
hostname = discovery_info.hostname
|
hostname = discovery_info.hostname
|
||||||
gateway_id = hostname[8:22]
|
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)
|
await self.async_set_unique_id(gateway_id)
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
import logging
|
||||||
from typing import Final
|
from typing import Final
|
||||||
|
|
||||||
from pyoverkiz.enums import UIClass
|
from pyoverkiz.enums import UIClass
|
||||||
@ -10,6 +11,7 @@ from pyoverkiz.enums.ui import UIWidget
|
|||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
|
|
||||||
DOMAIN: Final = "overkiz"
|
DOMAIN: Final = "overkiz"
|
||||||
|
LOGGER: logging.Logger = logging.getLogger(__package__)
|
||||||
|
|
||||||
CONF_HUB: Final = "hub"
|
CONF_HUB: Final = "hub"
|
||||||
DEFAULT_HUB: Final = "somfy_europe"
|
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.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
from homeassistant.util.decorator import Registry
|
from homeassistant.util.decorator import Registry
|
||||||
|
|
||||||
from .const import DOMAIN, UPDATE_INTERVAL
|
from .const import DOMAIN, LOGGER, UPDATE_INTERVAL
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
EVENT_HANDLERS = Registry()
|
EVENT_HANDLERS = Registry()
|
||||||
|
|
||||||
@ -89,7 +87,7 @@ class OverkizDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Device]]):
|
|||||||
return self.devices
|
return self.devices
|
||||||
|
|
||||||
for event in events:
|
for event in events:
|
||||||
_LOGGER.debug(event)
|
LOGGER.debug(event)
|
||||||
|
|
||||||
if event_handler := EVENT_HANDLERS.get(event.name):
|
if event_handler := EVENT_HANDLERS.get(event.name):
|
||||||
await event_handler(self, event)
|
await event_handler(self, event)
|
||||||
@ -101,7 +99,7 @@ class OverkizDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Device]]):
|
|||||||
|
|
||||||
async def _get_devices(self) -> dict[str, Device]:
|
async def _get_devices(self) -> dict[str, Device]:
|
||||||
"""Fetch devices."""
|
"""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)}
|
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]:
|
def _places_to_area(self, place: Place) -> dict[str, str]:
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
"""Class for helpers and communication with the OverKiz API."""
|
"""Class for helpers and communication with the OverKiz API."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from pyoverkiz.models import Command, Device
|
from pyoverkiz.models import Command, Device
|
||||||
from pyoverkiz.types import StateType as OverkizStateType
|
from pyoverkiz.types import StateType as OverkizStateType
|
||||||
|
|
||||||
|
from .const import LOGGER
|
||||||
from .coordinator import OverkizDataUpdateCoordinator
|
from .coordinator import OverkizDataUpdateCoordinator
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class OverkizExecutor:
|
class OverkizExecutor:
|
||||||
"""Representation of an Overkiz device with execution handler."""
|
"""Representation of an Overkiz device with execution handler."""
|
||||||
@ -67,7 +65,7 @@ class OverkizExecutor:
|
|||||||
"Home Assistant",
|
"Home Assistant",
|
||||||
)
|
)
|
||||||
except Exception as exception: # pylint: disable=broad-except
|
except Exception as exception: # pylint: disable=broad-except
|
||||||
_LOGGER.error(exception)
|
LOGGER.error(exception)
|
||||||
return
|
return
|
||||||
|
|
||||||
# ExecutionRegisteredEvent doesn't contain the device_url, thus we need to register it here
|
# ExecutionRegisteredEvent doesn't contain the device_url, thus we need to register it here
|
||||||
|
Loading…
x
Reference in New Issue
Block a user