Streamline naming in deCONZ integration (#111977)
This commit is contained in:
parent
e20cc4f8b9
commit
506240be10
24 changed files with 325 additions and 342 deletions
|
@ -36,7 +36,7 @@ from homeassistant.util.color import color_hs_to_xy
|
|||
|
||||
from .const import DOMAIN as DECONZ_DOMAIN, POWER_PLUGS
|
||||
from .deconz_device import DeconzDevice
|
||||
from .hub import DeconzHub, get_gateway_from_config_entry
|
||||
from .hub import DeconzHub
|
||||
|
||||
DECONZ_GROUP = "is_deconz_group"
|
||||
EFFECT_TO_DECONZ = {
|
||||
|
@ -111,13 +111,13 @@ async def async_setup_entry(
|
|||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the deCONZ lights and groups from a config entry."""
|
||||
gateway = get_gateway_from_config_entry(hass, config_entry)
|
||||
gateway.entities[DOMAIN] = set()
|
||||
hub = DeconzHub.get_hub(hass, config_entry)
|
||||
hub.entities[DOMAIN] = set()
|
||||
|
||||
entity_registry = er.async_get(hass)
|
||||
|
||||
# On/Off Output should be switch not light 2022.5
|
||||
for light in gateway.api.lights.lights.values():
|
||||
for light in hub.api.lights.lights.values():
|
||||
if light.type == ResourceType.ON_OFF_OUTPUT.value and (
|
||||
entity_id := entity_registry.async_get_entity_id(
|
||||
DOMAIN, DECONZ_DOMAIN, light.unique_id
|
||||
|
@ -128,15 +128,15 @@ async def async_setup_entry(
|
|||
@callback
|
||||
def async_add_light(_: EventType, light_id: str) -> None:
|
||||
"""Add light from deCONZ."""
|
||||
light = gateway.api.lights.lights[light_id]
|
||||
light = hub.api.lights.lights[light_id]
|
||||
if light.type in POWER_PLUGS:
|
||||
return
|
||||
|
||||
async_add_entities([DeconzLight(light, gateway)])
|
||||
async_add_entities([DeconzLight(light, hub)])
|
||||
|
||||
gateway.register_platform_add_device_callback(
|
||||
hub.register_platform_add_device_callback(
|
||||
async_add_light,
|
||||
gateway.api.lights.lights,
|
||||
hub.api.lights.lights,
|
||||
)
|
||||
|
||||
@callback
|
||||
|
@ -145,20 +145,20 @@ async def async_setup_entry(
|
|||
|
||||
Update group states based on its sum of related lights.
|
||||
"""
|
||||
if (group := gateway.api.groups[group_id]) and not group.lights:
|
||||
if (group := hub.api.groups[group_id]) and not group.lights:
|
||||
return
|
||||
|
||||
first = True
|
||||
for light_id in group.lights:
|
||||
if (light := gateway.api.lights.lights.get(light_id)) and light.reachable:
|
||||
if (light := hub.api.lights.lights.get(light_id)) and light.reachable:
|
||||
group.update_color_state(light, update_all_attributes=first)
|
||||
first = False
|
||||
|
||||
async_add_entities([DeconzGroup(group, gateway)])
|
||||
async_add_entities([DeconzGroup(group, hub)])
|
||||
|
||||
gateway.register_platform_add_device_callback(
|
||||
hub.register_platform_add_device_callback(
|
||||
async_add_group,
|
||||
gateway.api.groups,
|
||||
hub.api.groups,
|
||||
)
|
||||
|
||||
|
||||
|
@ -168,15 +168,15 @@ class DeconzBaseLight(DeconzDevice[_LightDeviceT], LightEntity):
|
|||
TYPE = DOMAIN
|
||||
_attr_color_mode = ColorMode.UNKNOWN
|
||||
|
||||
def __init__(self, device: _LightDeviceT, gateway: DeconzHub) -> None:
|
||||
def __init__(self, device: _LightDeviceT, hub: DeconzHub) -> None:
|
||||
"""Set up light."""
|
||||
super().__init__(device, gateway)
|
||||
super().__init__(device, hub)
|
||||
|
||||
self.api: GroupHandler | LightHandler
|
||||
if isinstance(self._device, Light):
|
||||
self.api = self.gateway.api.lights.lights
|
||||
self.api = self.hub.api.lights.lights
|
||||
elif isinstance(self._device, Group):
|
||||
self.api = self.gateway.api.groups
|
||||
self.api = self.hub.api.groups
|
||||
|
||||
self._attr_supported_color_modes: set[ColorMode] = set()
|
||||
|
||||
|
@ -324,7 +324,7 @@ class DeconzLight(DeconzBaseLight[Light]):
|
|||
super().async_update_callback()
|
||||
|
||||
if self._device.reachable and "attr" not in self._device.changed_keys:
|
||||
for group in self.gateway.api.groups.values():
|
||||
for group in self.hub.api.groups.values():
|
||||
if self._device.resource_id in group.lights:
|
||||
group.update_color_state(self._device)
|
||||
|
||||
|
@ -334,10 +334,10 @@ class DeconzGroup(DeconzBaseLight[Group]):
|
|||
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(self, device: Group, gateway: DeconzHub) -> None:
|
||||
def __init__(self, device: Group, hub: DeconzHub) -> None:
|
||||
"""Set up group and create an unique id."""
|
||||
self._unique_id = f"{gateway.bridgeid}-{device.deconz_id}"
|
||||
super().__init__(device, gateway)
|
||||
self._unique_id = f"{hub.bridgeid}-{device.deconz_id}"
|
||||
super().__init__(device, hub)
|
||||
|
||||
self._attr_name = None
|
||||
|
||||
|
@ -354,7 +354,7 @@ class DeconzGroup(DeconzBaseLight[Group]):
|
|||
manufacturer="Dresden Elektronik",
|
||||
model="deCONZ group",
|
||||
name=self._device.name,
|
||||
via_device=(DECONZ_DOMAIN, self.gateway.api.config.bridge_id),
|
||||
via_device=(DECONZ_DOMAIN, self.hub.api.config.bridge_id),
|
||||
)
|
||||
|
||||
@property
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue