mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 03:37:07 +00:00
add support for dimming/brightening X10 lamps (#130196)
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
411d14c2ce
commit
6a4160bcc4
@ -81,9 +81,16 @@ class X10Light(LightEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def brightness(self):
|
def brightness(self):
|
||||||
"""Return the brightness of the light."""
|
"""Return the brightness of the light, scaled to base class 0..255.
|
||||||
|
|
||||||
|
This needs to be scaled from 0..x for use with X10 dimmers.
|
||||||
|
"""
|
||||||
return self._brightness
|
return self._brightness
|
||||||
|
|
||||||
|
def normalize_x10_brightness(self, brightness: float) -> float:
|
||||||
|
"""Return calculated brightness values."""
|
||||||
|
return int((brightness / 255) * 32)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if light is on."""
|
"""Return true if light is on."""
|
||||||
@ -91,11 +98,37 @@ class X10Light(LightEntity):
|
|||||||
|
|
||||||
def turn_on(self, **kwargs: Any) -> None:
|
def turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Instruct the light to turn on."""
|
"""Instruct the light to turn on."""
|
||||||
if self._is_cm11a:
|
old_brightness = self._brightness
|
||||||
x10_command(f"on {self._id}")
|
if old_brightness == 0:
|
||||||
else:
|
# Dim down from max if applicable, also avoids a "dim" command if an "on" is more appropriate
|
||||||
x10_command(f"fon {self._id}")
|
old_brightness = 255
|
||||||
self._brightness = kwargs.get(ATTR_BRIGHTNESS, 255)
|
self._brightness = kwargs.get(ATTR_BRIGHTNESS, 255)
|
||||||
|
brightness_diff = self.normalize_x10_brightness(
|
||||||
|
self._brightness
|
||||||
|
) - self.normalize_x10_brightness(old_brightness)
|
||||||
|
command_suffix = ""
|
||||||
|
# heyu has quite a messy command structure - we'll just deal with it here
|
||||||
|
if brightness_diff == 0:
|
||||||
|
if self._is_cm11a:
|
||||||
|
command_prefix = "on"
|
||||||
|
else:
|
||||||
|
command_prefix = "fon"
|
||||||
|
elif brightness_diff > 0:
|
||||||
|
if self._is_cm11a:
|
||||||
|
command_prefix = "bright"
|
||||||
|
else:
|
||||||
|
command_prefix = "fbright"
|
||||||
|
command_suffix = f" {brightness_diff}"
|
||||||
|
else:
|
||||||
|
if self._is_cm11a:
|
||||||
|
if self._state:
|
||||||
|
command_prefix = "dim"
|
||||||
|
else:
|
||||||
|
command_prefix = "dimb"
|
||||||
|
else:
|
||||||
|
command_prefix = "fdim"
|
||||||
|
command_suffix = f" {-brightness_diff}"
|
||||||
|
x10_command(f"{command_prefix} {self._id}{command_suffix}")
|
||||||
self._state = True
|
self._state = True
|
||||||
|
|
||||||
def turn_off(self, **kwargs: Any) -> None:
|
def turn_off(self, **kwargs: Any) -> None:
|
||||||
@ -104,6 +137,7 @@ class X10Light(LightEntity):
|
|||||||
x10_command(f"off {self._id}")
|
x10_command(f"off {self._id}")
|
||||||
else:
|
else:
|
||||||
x10_command(f"foff {self._id}")
|
x10_command(f"foff {self._id}")
|
||||||
|
self._brightness = 0
|
||||||
self._state = False
|
self._state = False
|
||||||
|
|
||||||
def update(self) -> None:
|
def update(self) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user