Skip to content

Commit

Permalink
Minor code improvements (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaskivskyi authored Dec 26, 2023
1 parent 797c3a6 commit 085930e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
10 changes: 6 additions & 4 deletions custom_components/chroma/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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]]:
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions custom_components/chroma/chroma.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions custom_components/chroma/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down

0 comments on commit 085930e

Please sign in to comment.