From ccb8d6af44cd561a3a19de85dc3a22ff1acb13a9 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 19 Feb 2026 13:39:55 +0100 Subject: [PATCH] Use shorthand attribute in x10 light (#163444) --- homeassistant/components/x10/light.py | 43 ++++++++------------------- 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/homeassistant/components/x10/light.py b/homeassistant/components/x10/light.py index fbdebe11657..035b306888c 100644 --- a/homeassistant/components/x10/light.py +++ b/homeassistant/components/x10/light.py @@ -63,48 +63,31 @@ def setup_platform( class X10Light(LightEntity): """Representation of an X10 Light.""" + _attr_brightness: int _attr_color_mode = ColorMode.BRIGHTNESS _attr_supported_color_modes = {ColorMode.BRIGHTNESS} def __init__(self, light, is_cm11a): """Initialize an X10 Light.""" - self._name = light["name"] + self._attr_name = light["name"] self._id = light["id"] - self._brightness = 0 - self._state = False + self._attr_brightness = 0 + self._attr_is_on = False self._is_cm11a = is_cm11a - @property - def name(self): - """Return the display name of this light.""" - return self._name - - @property - def brightness(self): - """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 - - def normalize_x10_brightness(self, brightness: float) -> float: + def normalize_x10_brightness(self, brightness: float) -> int: """Return calculated brightness values.""" return int((brightness / 255) * 32) - @property - def is_on(self): - """Return true if light is on.""" - return self._state - def turn_on(self, **kwargs: Any) -> None: """Instruct the light to turn on.""" - old_brightness = self._brightness + old_brightness = self._attr_brightness if old_brightness == 0: # Dim down from max if applicable, also avoids a "dim" command if an "on" is more appropriate old_brightness = 255 - self._brightness = kwargs.get(ATTR_BRIGHTNESS, 255) + self._attr_brightness = kwargs.get(ATTR_BRIGHTNESS, 255) brightness_diff = self.normalize_x10_brightness( - self._brightness + self._attr_brightness ) - self.normalize_x10_brightness(old_brightness) command_suffix = "" # heyu has quite a messy command structure - we'll just deal with it here @@ -121,7 +104,7 @@ class X10Light(LightEntity): command_suffix = f" {brightness_diff}" else: if self._is_cm11a: - if self._state: + if self._attr_is_on: command_prefix = "dim" else: command_prefix = "dimb" @@ -129,7 +112,7 @@ class X10Light(LightEntity): command_prefix = "fdim" command_suffix = f" {-brightness_diff}" x10_command(f"{command_prefix} {self._id}{command_suffix}") - self._state = True + self._attr_is_on = True def turn_off(self, **kwargs: Any) -> None: """Instruct the light to turn off.""" @@ -137,13 +120,13 @@ class X10Light(LightEntity): x10_command(f"off {self._id}") else: x10_command(f"foff {self._id}") - self._brightness = 0 - self._state = False + self._attr_brightness = 0 + self._attr_is_on = False def update(self) -> None: """Fetch update state.""" if self._is_cm11a: - self._state = bool(get_unit_status(self._id)) + self._attr_is_on = bool(get_unit_status(self._id)) else: # Not supported on CM17A pass