Skip to content
Merged
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
27 changes: 9 additions & 18 deletions homeassistant/components/nanoleaf/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

from __future__ import annotations

import math
from typing import Any

from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP,
ATTR_COLOR_TEMP_KELVIN,
ATTR_EFFECT,
ATTR_HS_COLOR,
ATTR_TRANSITION,
Expand All @@ -17,10 +16,6 @@
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.util.color import (
color_temperature_kelvin_to_mired as kelvin_to_mired,
color_temperature_mired_to_kelvin as mired_to_kelvin,
)

from . import NanoleafConfigEntry
from .coordinator import NanoleafCoordinator
Expand Down Expand Up @@ -51,20 +46,18 @@ def __init__(self, coordinator: NanoleafCoordinator) -> None:
"""Initialize the Nanoleaf light."""
super().__init__(coordinator)
self._attr_unique_id = self._nanoleaf.serial_no
self._attr_min_mireds = math.ceil(
1000000 / self._nanoleaf.color_temperature_max
)
self._attr_max_mireds = kelvin_to_mired(self._nanoleaf.color_temperature_min)
self._attr_max_color_temp_kelvin = self._nanoleaf.color_temperature_max
self._attr_min_color_temp_kelvin = self._nanoleaf.color_temperature_min

@property
def brightness(self) -> int:
"""Return the brightness of the light."""
return int(self._nanoleaf.brightness * 2.55)

@property
def color_temp(self) -> int:
"""Return the current color temperature."""
return kelvin_to_mired(self._nanoleaf.color_temperature)
def color_temp_kelvin(self) -> int | None:
"""Return the color temperature value in Kelvin."""
return self._nanoleaf.color_temperature

@property
def effect(self) -> str | None:
Expand Down Expand Up @@ -106,7 +99,7 @@ async def async_turn_on(self, **kwargs: Any) -> None:
"""Instruct the light to turn on."""
brightness = kwargs.get(ATTR_BRIGHTNESS)
hs_color = kwargs.get(ATTR_HS_COLOR)
color_temp_mired = kwargs.get(ATTR_COLOR_TEMP)
color_temp_kelvin = kwargs.get(ATTR_COLOR_TEMP_KELVIN)
effect = kwargs.get(ATTR_EFFECT)
transition = kwargs.get(ATTR_TRANSITION)

Expand All @@ -120,10 +113,8 @@ async def async_turn_on(self, **kwargs: Any) -> None:
hue, saturation = hs_color
await self._nanoleaf.set_hue(int(hue))
await self._nanoleaf.set_saturation(int(saturation))
elif color_temp_mired:
await self._nanoleaf.set_color_temperature(
mired_to_kelvin(color_temp_mired)
)
elif color_temp_kelvin:
await self._nanoleaf.set_color_temperature(color_temp_kelvin)
if transition:
if brightness: # tune to the required brightness in n seconds
await self._nanoleaf.set_brightness(
Expand Down