Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor code improvements #66

Merged
merged 1 commit into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading