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