mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +00:00
Cleanup logger in sharkiq (#64552)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
f083b97f9f
commit
7d66d4c219
@ -17,7 +17,7 @@ from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
from .const import _LOGGER, API_TIMEOUT, DOMAIN, PLATFORMS
|
||||
from .const import API_TIMEOUT, DOMAIN, LOGGER, PLATFORMS
|
||||
from .update_coordinator import SharkIqUpdateCoordinator
|
||||
|
||||
|
||||
@ -29,13 +29,13 @@ async def async_connect_or_timeout(ayla_api: AylaApi) -> bool:
|
||||
"""Connect to vacuum."""
|
||||
try:
|
||||
async with async_timeout.timeout(API_TIMEOUT):
|
||||
_LOGGER.debug("Initialize connection to Ayla networks API")
|
||||
LOGGER.debug("Initialize connection to Ayla networks API")
|
||||
await ayla_api.async_sign_in()
|
||||
except SharkIqAuthError:
|
||||
_LOGGER.error("Authentication error connecting to Shark IQ api")
|
||||
LOGGER.error("Authentication error connecting to Shark IQ api")
|
||||
return False
|
||||
except asyncio.TimeoutError as exc:
|
||||
_LOGGER.error("Timeout expired")
|
||||
LOGGER.error("Timeout expired")
|
||||
raise CannotConnect from exc
|
||||
|
||||
return True
|
||||
@ -57,7 +57,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
||||
|
||||
shark_vacs = await ayla_api.async_get_devices(False)
|
||||
device_names = ", ".join(d.name for d in shark_vacs)
|
||||
_LOGGER.debug("Found %d Shark IQ device(s): %s", len(shark_vacs), device_names)
|
||||
LOGGER.debug("Found %d Shark IQ device(s): %s", len(shark_vacs), device_names)
|
||||
coordinator = SharkIqUpdateCoordinator(hass, config_entry, ayla_api, shark_vacs)
|
||||
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
@ -72,7 +72,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
||||
|
||||
async def async_disconnect_or_timeout(coordinator: SharkIqUpdateCoordinator):
|
||||
"""Disconnect to vacuum."""
|
||||
_LOGGER.debug("Disconnecting from Ayla Api")
|
||||
LOGGER.debug("Disconnecting from Ayla Api")
|
||||
async with async_timeout.timeout(5):
|
||||
with suppress(
|
||||
SharkIqAuthError, SharkIqAuthExpiringError, SharkIqNotAuthedError
|
||||
|
@ -12,7 +12,7 @@ from homeassistant import config_entries, core, exceptions
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
from .const import _LOGGER, DOMAIN
|
||||
from .const import DOMAIN, LOGGER
|
||||
|
||||
SHARKIQ_SCHEMA = vol.Schema(
|
||||
{vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str}
|
||||
@ -29,7 +29,7 @@ async def validate_input(hass: core.HomeAssistant, data):
|
||||
|
||||
try:
|
||||
async with async_timeout.timeout(10):
|
||||
_LOGGER.debug("Initialize connection to Ayla networks API")
|
||||
LOGGER.debug("Initialize connection to Ayla networks API")
|
||||
await ayla_api.async_sign_in()
|
||||
except (asyncio.TimeoutError, aiohttp.ClientError) as errors:
|
||||
raise CannotConnect from errors
|
||||
@ -58,7 +58,7 @@ class SharkIqConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
except InvalidAuth:
|
||||
errors["base"] = "invalid_auth"
|
||||
except Exception: # pylint: disable=broad-except
|
||||
_LOGGER.exception("Unexpected exception")
|
||||
LOGGER.exception("Unexpected exception")
|
||||
errors["base"] = "unknown"
|
||||
return info, errors
|
||||
|
||||
|
@ -4,7 +4,7 @@ import logging
|
||||
|
||||
from homeassistant.const import Platform
|
||||
|
||||
_LOGGER = logging.getLogger(__package__)
|
||||
LOGGER = logging.getLogger(__package__)
|
||||
|
||||
API_TIMEOUT = 20
|
||||
PLATFORMS = [Platform.VACUUM]
|
||||
|
@ -17,7 +17,7 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
from .const import _LOGGER, API_TIMEOUT, DOMAIN, UPDATE_INTERVAL
|
||||
from .const import API_TIMEOUT, DOMAIN, LOGGER, UPDATE_INTERVAL
|
||||
|
||||
|
||||
class SharkIqUpdateCoordinator(DataUpdateCoordinator):
|
||||
@ -38,7 +38,7 @@ class SharkIqUpdateCoordinator(DataUpdateCoordinator):
|
||||
self._config_entry = config_entry
|
||||
self._online_dsns: set[str] = set()
|
||||
|
||||
super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=UPDATE_INTERVAL)
|
||||
super().__init__(hass, LOGGER, name=DOMAIN, update_interval=UPDATE_INTERVAL)
|
||||
|
||||
@property
|
||||
def online_dsns(self) -> set[str]:
|
||||
@ -53,7 +53,7 @@ class SharkIqUpdateCoordinator(DataUpdateCoordinator):
|
||||
async def _async_update_vacuum(sharkiq: SharkIqVacuum) -> None:
|
||||
"""Asynchronously update the data for a single vacuum."""
|
||||
dsn = sharkiq.serial_number
|
||||
_LOGGER.debug("Updating sharkiq data for device DSN %s", dsn)
|
||||
LOGGER.debug("Updating sharkiq data for device DSN %s", dsn)
|
||||
async with timeout(API_TIMEOUT):
|
||||
await sharkiq.async_update()
|
||||
|
||||
@ -67,7 +67,7 @@ class SharkIqUpdateCoordinator(DataUpdateCoordinator):
|
||||
if v["connection_status"] == "Online" and v["dsn"] in self.shark_vacs
|
||||
}
|
||||
|
||||
_LOGGER.debug("Updating sharkiq data")
|
||||
LOGGER.debug("Updating sharkiq data")
|
||||
online_vacs = (self.shark_vacs[dsn] for dsn in self.online_dsns)
|
||||
await asyncio.gather(*(self._async_update_vacuum(v) for v in online_vacs))
|
||||
except (
|
||||
@ -75,10 +75,10 @@ class SharkIqUpdateCoordinator(DataUpdateCoordinator):
|
||||
SharkIqNotAuthedError,
|
||||
SharkIqAuthExpiringError,
|
||||
) as err:
|
||||
_LOGGER.debug("Bad auth state. Attempting re-auth", exc_info=err)
|
||||
LOGGER.debug("Bad auth state. Attempting re-auth", exc_info=err)
|
||||
raise ConfigEntryAuthFailed from err
|
||||
except Exception as err:
|
||||
_LOGGER.exception("Unexpected error updating SharkIQ")
|
||||
LOGGER.exception("Unexpected error updating SharkIQ")
|
||||
raise UpdateFailed(err) from err
|
||||
|
||||
return True
|
||||
|
@ -2,7 +2,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterable
|
||||
import logging
|
||||
|
||||
from sharkiqpy import OperatingModes, PowerModes, Properties, SharkIqVacuum
|
||||
|
||||
@ -29,11 +28,9 @@ from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import DOMAIN, SHARK
|
||||
from .const import DOMAIN, LOGGER, SHARK
|
||||
from .update_coordinator import SharkIqUpdateCoordinator
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
# Supported features
|
||||
SUPPORT_SHARKIQ = (
|
||||
SUPPORT_BATTERY
|
||||
@ -79,7 +76,7 @@ async def async_setup_entry(
|
||||
coordinator: SharkIqUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
devices: Iterable[SharkIqVacuum] = coordinator.shark_vacs.values()
|
||||
device_names = [d.name for d in devices]
|
||||
_LOGGER.debug(
|
||||
LOGGER.debug(
|
||||
"Found %d Shark IQ device(s): %s",
|
||||
len(device_names),
|
||||
", ".join([d.name for d in devices]),
|
||||
|
Loading…
x
Reference in New Issue
Block a user