Improve typing in Zengge (#118547)

This commit is contained in:
Joost Lekkerkerker 2024-05-31 21:35:42 +02:00 committed by GitHub
parent 41e852a01b
commit f6800e6968
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -41,10 +41,7 @@ def setup_platform(
"""Set up the Zengge platform."""
lights = []
for address, device_config in config[CONF_DEVICES].items():
device = {}
device["name"] = device_config[CONF_NAME]
device["address"] = address
light = ZenggeLight(device)
light = ZenggeLight(device_config[CONF_NAME], address)
if light.is_valid:
lights.append(light)
@ -56,22 +53,20 @@ class ZenggeLight(LightEntity):
_attr_supported_color_modes = {ColorMode.HS, ColorMode.WHITE}
def __init__(self, device):
def __init__(self, name: str, address: str) -> None:
"""Initialize the light."""
self._attr_name = device["name"]
self._attr_unique_id = device["address"]
self._attr_name = name
self._attr_unique_id = address
self.is_valid = True
self._bulb = zengge(device["address"])
self._bulb = zengge(address)
self._white = 0
self._attr_brightness = 0
self._attr_hs_color = (0, 0)
self._attr_is_on = False
if self._bulb.connect() is False:
self.is_valid = False
_LOGGER.error(
"Failed to connect to bulb %s, %s", device["address"], device["name"]
)
_LOGGER.error("Failed to connect to bulb %s, %s", address, name)
return
@property