From 7518352a8938aeac239d7a52e53dd1d5c98bc595 Mon Sep 17 00:00:00 2001 From: Yevhenii Vaskivskyi Date: Tue, 26 Dec 2023 13:02:19 +0100 Subject: [PATCH] Minor code improvements --- custom_components/chroma/bridge.py | 10 ++++++---- custom_components/chroma/chroma.py | 4 ++-- custom_components/chroma/light.py | 6 +++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/custom_components/chroma/bridge.py b/custom_components/chroma/bridge.py index ba3ff91..7b9a3a7 100644 --- a/custom_components/chroma/bridge.py +++ b/custom_components/chroma/bridge.py @@ -25,12 +25,14 @@ def __init__( self, hass: HomeAssistant, configs: dict[str, Any], - options: dict[str, Any] = dict(), + options: dict[str, Any] | None = None, ) -> None: """Initialize bridge.""" self._configs = configs.copy() - self._configs.update(options) + + if isinstance(options, dict): + self._configs.update(options) session = async_get_clientsession(hass) self._api = self._get_api(self._configs, session) @@ -72,7 +74,7 @@ async def async_disconnect(self) -> None: try: await self._api.async_disconnect() - except ChromaError as ex: + except ChromaError: pass async def async_get_available_sensors(self) -> dict[str, dict[str, Any]]: @@ -92,7 +94,7 @@ async def _get_light(self) -> dict[str, Any]: try: data = await self._api.async_get_state() - _LOGGER.debug(f"Sensors. Light data: {data}") + _LOGGER.debug("Sensors. Light data: %s", data) except Exception as ex: raise UpdateFailed(ex) from ex diff --git a/custom_components/chroma/chroma.py b/custom_components/chroma/chroma.py index 308602d..858132f 100644 --- a/custom_components/chroma/chroma.py +++ b/custom_components/chroma/chroma.py @@ -127,7 +127,7 @@ async def async_service_send_message(service: ServiceCall): data = service.data - _LOGGER.debug(f"Calling service Send Message with parameters: {data}") + _LOGGER.debug("Calling service Send Message with parameters: %s", data) (r, g, b) = data.get("color") color = Color(r, g, b) @@ -189,7 +189,7 @@ async def close(self) -> None: if self._api is not None and self._api._api.connected: try: await self._api.async_disconnect() - except ChromaError as ex: + except ChromaError: pass self._api = None diff --git a/custom_components/chroma/light.py b/custom_components/chroma/light.py index 6bf7762..1f31f35 100644 --- a/custom_components/chroma/light.py +++ b/custom_components/chroma/light.py @@ -5,13 +5,13 @@ import logging from typing import Any +from aiochroma import Color from homeassistant.components.light import ColorMode, LightEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import DataUpdateCoordinator -from aiochroma import Color from .chroma import Chroma from .compilers import list_lights from .const import CONF_DEVICES @@ -58,7 +58,7 @@ def __init__( async def async_turn_off(self, **kwargs: Any) -> None: """Turn off the light.""" - _LOGGER.debug(f"Command `turn_off` with args: `{kwargs}`") + _LOGGER.debug("Command `turn_off` with args: %s", kwargs) await self.api.async_turn_off(self._target) @@ -67,7 +67,7 @@ async def async_turn_off(self, **kwargs: Any) -> None: async def async_turn_on(self, **kwargs: Any) -> None: """Turn on the light.""" - _LOGGER.debug(f"Command `turn_on` with args: `{kwargs}`") + _LOGGER.debug("Command `turn_on` with args: %s", kwargs) color: int | None = None brightness: float | None = None