Skip to content

Commit

Permalink
fix: light scene improvement (#599)
Browse files Browse the repository at this point in the history
  • Loading branch information
petretiandrea authored Nov 3, 2023
1 parent 25ecf3e commit 6f4876e
Show file tree
Hide file tree
Showing 3 changed files with 322 additions and 94 deletions.
193 changes: 180 additions & 13 deletions .devcontainer/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,201 @@ debugpy:
wait: false

scene:
- id: "1677657730214"
name: L530
- id: "1682456037783"
name: 3 Office pinks
entities:
light.lampadina_smart:
light.striscia_luminosa_smart:
min_color_temp_kelvin: 2500
max_color_temp_kelvin: 6535
max_color_temp_kelvin: 6500
min_mireds: 153
max_mireds: 400
effect_list:
- bubblingcauldron
- aurora
- candycane
- christmas
- flicker
- christmaslight
- hanukkah
- hauntedmansion
- icicle
- lightning
- ocean
- rainbow
- raindrop
- spring
- sunrise
- sunset
- valentines
supported_color_modes:
- brightness
- color_temp
- hs
- onoff
friendly_name: Office kallax
supported_features: 4
color_mode: hs
brightness: 255
hs_color:
- 120
- 85
- 295
- 99
rgb_color:
- 38
- 233
- 2
- 255
- 38
xy_color:
- 0.182
- 0.721
friendly_name: Luce Camera Andrea
supported_features: 0
- 0.357
- 0.142
state: "on"
metadata:
light.lampadina_smart:
light.striscia_luminosa_smart:
entity_only: true
icon: mdi:desktop-classic
- id: "1682456224579"
name: 2 Office White
entities:
light.striscia_luminosa_smart:
min_color_temp_kelvin: 2500
max_color_temp_kelvin: 6500
min_mireds: 153
max_mireds: 400
effect_list:
- bubblingcauldron
- aurora
- candycane
- christmas
- flicker
- christmaslight
- hanukkah
- hauntedmansion
- icicle
- lightning
- ocean
- rainbow
- raindrop
- spring
- sunrise
- sunset
- valentines
supported_color_modes:
- brightness
- color_temp
- hs
- onoff
color_mode: color_temp
brightness: 255
color_temp_kelvin: 6535
color_temp: 153
hs_color:
- 54.768
- 1.6
rgb_color:
- 255
- 254
- 250
xy_color:
- 0.326
- 0.333
friendly_name: Office kallax
supported_features: 4
state: "on"
metadata:
light.striscia_luminosa_smart:
entity_only: true
icon: mdi:desktop-classic
- id: "1697651778268"
name: 1 Office Streamin
entities:
light.striscia_luminosa_smart:
min_color_temp_kelvin: 2500
max_color_temp_kelvin: 6500
min_mireds: 153
max_mireds: 400
effect_list:
- bubblingcauldron
- aurora
- candycane
- christmas
- flicker
- christmaslight
- hanukkah
- hauntedmansion
- icicle
- lightning
- ocean
- rainbow
- raindrop
- spring
- sunrise
- sunset
- valentines
supported_color_modes:
- brightness
- color_temp
- hs
- onoff
friendly_name: Office kallax
supported_features: 4
color_mode: color_temp
brightness: 255
color_temp_kelvin: 2500
color_temp: 400
hs_color:
- 28.874
- 72.522
rgb_color:
- 255
- 159
- 70
xy_color:
- 0.546
- 0.389
effect: Rainbow
state: "on"
icon: mdi:desktop-classic
metadata:
light.striscia_luminosa_smart:
entity_only: true
- id: "1687783375727"
name: Studio Light Warm 100%
entities:
light.striscia_luminosa_smart:
effect_list:
- bubblingcauldron
- aurora
- candycane
- christmas
- flicker
- christmaslight
- hanukkah
- hauntedmansion
- icicle
- lightning
- ocean
- rainbow
- raindrop
- spring
- sunrise
- sunset
- valentines
supported_color_modes:
- brightness
- hs
- onoff
color_mode: hs
brightness: 128
hs_color:
- 30
- 94
rgb_color:
- 255
- 135
- 15
xy_color:
- 0.6
- 0.381
friendly_name: Studio Right Strip
supported_features: 4
state: "on"
icon: mdi:globe-light
metadata: {}
44 changes: 44 additions & 0 deletions custom_components/tapo/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
from typing import TypeVar

from homeassistant.components.network.models import Adapter
from homeassistant.util.color import (
color_temperature_kelvin_to_mired as kelvin_to_mired,
)
from homeassistant.util.color import (
color_temperature_mired_to_kelvin as mired_to_kelvin,
)
from plugp100.common.functional.tri import Try

T = TypeVar("T")
Expand All @@ -20,6 +26,44 @@ def get_short_model(model: str) -> str:
return model.lower().split(maxsplit=1)[0]


def hass_to_tapo_brightness(brightness: float | None) -> float | None:
if brightness is not None:
return round((brightness / 255) * 100)
return brightness


def tapo_to_hass_brightness(brightness: float | None) -> float | None:
if brightness is not None:
return round((brightness * 255) / 100)
return brightness


# Mireds and Kelving are min, max tuple
def hass_to_tapo_color_temperature(
color_temp: int | None, mireds: (int, int), kelvin: (int, int)
) -> int | None:
if color_temp is not None:
constraint_color_temp = clamp(color_temp, mireds[0], mireds[1])
return clamp(
mired_to_kelvin(constraint_color_temp),
min_value=kelvin[0],
max_value=kelvin[1],
)
return color_temp


def tapo_to_hass_color_temperature(
color_temp: int | None, mireds: (int, int)
) -> int | None:
if color_temp is not None and color_temp > 0:
return clamp(
kelvin_to_mired(color_temp),
min_value=mireds[0],
max_value=mireds[1],
)
return None


async def find_adapter_for(
adapters: list[Adapter], ip: Optional[str]
) -> Optional[Adapter]:
Expand Down
Loading

0 comments on commit 6f4876e

Please sign in to comment.