Use shorthand attributes in UPB (#99892)

This commit is contained in:
Joost Lekkerkerker 2023-09-08 11:33:59 +02:00 committed by GitHub
parent b2b57c5f87
commit b2c3d95911
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -57,7 +57,7 @@ class UpbLight(UpbAttachedEntity, LightEntity):
def __init__(self, element, unique_id, upb):
"""Initialize an UpbLight."""
super().__init__(element, unique_id, upb)
self._brightness = self._element.status
self._attr_brightness: int = self._element.status
@property
def color_mode(self) -> ColorMode:
@ -78,15 +78,10 @@ class UpbLight(UpbAttachedEntity, LightEntity):
return LightEntityFeature.TRANSITION | LightEntityFeature.FLASH
return LightEntityFeature.FLASH
@property
def brightness(self):
"""Get the brightness."""
return self._brightness
@property
def is_on(self) -> bool:
"""Get the current brightness."""
return self._brightness != 0
return self._attr_brightness != 0
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn on the light."""
@ -123,4 +118,4 @@ class UpbLight(UpbAttachedEntity, LightEntity):
def _element_changed(self, element, changeset):
status = self._element.status
self._brightness = round(status * 2.55) if status else 0
self._attr_brightness = round(status * 2.55) if status else 0