mirror of
https://github.com/home-assistant/core.git
synced 2026-05-08 17:49:37 +01:00
Improve type hints in lights (#163792)
This commit is contained in:
@@ -74,7 +74,7 @@ class BleBoxLightEntity(BleBoxEntity[blebox_uniapi.light.Light], LightEntity):
|
||||
return self._feature.is_on
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
def brightness(self) -> int | None:
|
||||
"""Return the name."""
|
||||
return self._feature.brightness
|
||||
|
||||
|
||||
@@ -199,7 +199,7 @@ class Control4Light(Control4Entity, LightEntity):
|
||||
return self.coordinator.data[self._idx][CONTROL4_NON_DIMMER_VAR] > 0
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
def brightness(self) -> int | None:
|
||||
"""Return the brightness of this light between 0..255."""
|
||||
if self._is_dimmer:
|
||||
for var in CONTROL4_DIMMER_VARS:
|
||||
|
||||
@@ -132,7 +132,7 @@ class DecoraWifiLight(LightEntity):
|
||||
return self._switch.serial
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
def brightness(self) -> int:
|
||||
"""Return the brightness of the dimmer switch."""
|
||||
return int(self._switch.brightness * 255 / 100)
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ class EufyHomeLight(LightEntity):
|
||||
self._attr_is_on = self._bulb.power
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
def brightness(self) -> int:
|
||||
"""Return the brightness of this light between 0..255."""
|
||||
return int(self._brightness * 255 / 100)
|
||||
|
||||
@@ -88,7 +88,7 @@ class EufyHomeLight(LightEntity):
|
||||
)
|
||||
|
||||
@property
|
||||
def hs_color(self):
|
||||
def hs_color(self) -> tuple[float, float] | None:
|
||||
"""Return the color of this light."""
|
||||
return self._hs
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ class IGloLamp(LightEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
def brightness(self) -> int:
|
||||
"""Return the brightness of this light between 0..255."""
|
||||
return int((self._lamp.state()["brightness"] / 200.0) * 255)
|
||||
|
||||
@@ -97,17 +97,17 @@ class IGloLamp(LightEntity):
|
||||
return self._lamp.min_kelvin
|
||||
|
||||
@property
|
||||
def hs_color(self):
|
||||
def hs_color(self) -> tuple[float, float]:
|
||||
"""Return the hs value."""
|
||||
return color_util.color_RGB_to_hs(*self._lamp.state()["rgb"])
|
||||
|
||||
@property
|
||||
def effect(self):
|
||||
def effect(self) -> str:
|
||||
"""Return the current effect."""
|
||||
return self._lamp.state()["effect"]
|
||||
|
||||
@property
|
||||
def effect_list(self):
|
||||
def effect_list(self) -> list[str]:
|
||||
"""Return the list of supported effects."""
|
||||
return self._lamp.effect_list()
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class InsteonDimmerEntity(InsteonEntity, LightEntity):
|
||||
self._attr_supported_color_modes = {ColorMode.ONOFF}
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
def brightness(self) -> int:
|
||||
"""Return the brightness of this light between 0..255."""
|
||||
return self._insteon_device_group.value
|
||||
|
||||
|
||||
@@ -244,7 +244,7 @@ class Luminary(LightEntity):
|
||||
return self._luminary.name()
|
||||
|
||||
@property
|
||||
def hs_color(self):
|
||||
def hs_color(self) -> tuple[float, float]:
|
||||
"""Return last hs color value set."""
|
||||
return color_util.color_RGB_to_hs(*self._rgb_color)
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ class PilightLight(PilightBaseDevice, LightEntity):
|
||||
self._dimlevel_max = config.get(CONF_DIMLEVEL_MAX)
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
def brightness(self) -> int | None:
|
||||
"""Return the brightness."""
|
||||
return self._brightness
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ class QSLight(QSToggleEntity, LightEntity):
|
||||
"""Light based on a Qwikswitch relay/dimmer module."""
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
def brightness(self) -> int | None:
|
||||
"""Return the brightness of this light (0-255)."""
|
||||
return self.device.value if self.device.is_dimmer else None
|
||||
|
||||
|
||||
@@ -226,7 +226,7 @@ class DimmableRflinkLight(SwitchableRflinkDevice, LightEntity):
|
||||
self._state = True
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
def brightness(self) -> int:
|
||||
"""Return the brightness of this light between 0..255."""
|
||||
return self._brightness
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ class SisyphusLight(LightEntity):
|
||||
return not self._table.is_sleeping
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
def brightness(self) -> int:
|
||||
"""Return the current brightness of the table's ring light."""
|
||||
return self._table.brightness * 255
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ class SmartTubLight(SmartTubEntity, LightEntity):
|
||||
return self.coordinator.data[self.spa.id][ATTR_LIGHTS][self.light_zone]
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
def brightness(self) -> int:
|
||||
"""Return the brightness of this light between 0..255."""
|
||||
|
||||
# SmartTub intensity is 0..100
|
||||
@@ -87,7 +87,7 @@ class SmartTubLight(SmartTubEntity, LightEntity):
|
||||
return self.light.mode != SpaLight.LightMode.OFF
|
||||
|
||||
@property
|
||||
def effect(self):
|
||||
def effect(self) -> str | None:
|
||||
"""Return the current effect."""
|
||||
mode = self.light.mode.name.lower()
|
||||
if mode in self.effect_list:
|
||||
@@ -95,7 +95,7 @@ class SmartTubLight(SmartTubEntity, LightEntity):
|
||||
return None
|
||||
|
||||
@property
|
||||
def effect_list(self):
|
||||
def effect_list(self) -> list[str]:
|
||||
"""Return the list of supported effects."""
|
||||
return [
|
||||
effect
|
||||
|
||||
@@ -53,7 +53,7 @@ class TelldusLiveLight(TelldusLiveEntity, LightEntity):
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
def brightness(self) -> int:
|
||||
"""Return the brightness of this light between 0..255."""
|
||||
return self.device.dim_level
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ class TellstickLight(TellstickDevice, LightEntity):
|
||||
self._brightness = 255
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
def brightness(self) -> int:
|
||||
"""Return the brightness of this light between 0..255."""
|
||||
return self._brightness
|
||||
|
||||
|
||||
@@ -91,12 +91,12 @@ class XiaomiGatewayLight(XiaomiDevice, LightEntity):
|
||||
return True
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
def brightness(self) -> int:
|
||||
"""Return the brightness of this light between 0..255."""
|
||||
return int(255 * self._brightness / 100)
|
||||
|
||||
@property
|
||||
def hs_color(self):
|
||||
def hs_color(self) -> tuple[float, float]:
|
||||
"""Return the hs color value."""
|
||||
return self._hs
|
||||
|
||||
|
||||
@@ -1041,12 +1041,12 @@ class XiaomiGatewayLight(LightEntity):
|
||||
)
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
def brightness(self) -> int:
|
||||
"""Return the brightness of this light between 0..255."""
|
||||
return int(255 * self._brightness_pct / 100)
|
||||
|
||||
@property
|
||||
def hs_color(self):
|
||||
def hs_color(self) -> tuple[float, float]:
|
||||
"""Return the hs color value."""
|
||||
return self._hs
|
||||
|
||||
@@ -1102,7 +1102,7 @@ class XiaomiGatewayBulb(XiaomiGatewayDevice, LightEntity):
|
||||
_sub_device: LightBulb
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
def brightness(self) -> int:
|
||||
"""Return the brightness of the light."""
|
||||
return round((self._sub_device.status["brightness"] * 255) / 100)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user