mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Fix device creation in fibaro integration (#142957)
* Fix device creation in fibaro integration * Better naming
This commit is contained in:
parent
7b3e7b7aea
commit
998b33c207
@ -12,7 +12,7 @@ from pyfibaro.fibaro_client import (
|
||||
FibaroClient,
|
||||
FibaroConnectFailed,
|
||||
)
|
||||
from pyfibaro.fibaro_data_helper import read_rooms
|
||||
from pyfibaro.fibaro_data_helper import find_master_devices, read_rooms
|
||||
from pyfibaro.fibaro_device import DeviceModel
|
||||
from pyfibaro.fibaro_device_manager import FibaroDeviceManager
|
||||
from pyfibaro.fibaro_info import InfoModel
|
||||
@ -176,35 +176,18 @@ class FibaroController:
|
||||
platform = Platform.LIGHT
|
||||
return platform
|
||||
|
||||
def _create_device_info(
|
||||
self, device: DeviceModel, devices: list[DeviceModel]
|
||||
) -> None:
|
||||
"""Create the device info. Unrooted entities are directly shown below the home center."""
|
||||
def _create_device_info(self, main_device: DeviceModel) -> None:
|
||||
"""Create the device info for a main device."""
|
||||
|
||||
# The home center is always id 1 (z-wave primary controller)
|
||||
if device.parent_fibaro_id <= 1:
|
||||
return
|
||||
|
||||
master_entity: DeviceModel | None = None
|
||||
if device.parent_fibaro_id == 1:
|
||||
master_entity = device
|
||||
else:
|
||||
for parent in devices:
|
||||
if parent.fibaro_id == device.parent_fibaro_id:
|
||||
master_entity = parent
|
||||
if master_entity is None:
|
||||
_LOGGER.error("Parent with id %s not found", device.parent_fibaro_id)
|
||||
return
|
||||
|
||||
if "zwaveCompany" in master_entity.properties:
|
||||
manufacturer = master_entity.properties.get("zwaveCompany")
|
||||
if "zwaveCompany" in main_device.properties:
|
||||
manufacturer = main_device.properties.get("zwaveCompany")
|
||||
else:
|
||||
manufacturer = None
|
||||
|
||||
self._device_infos[master_entity.fibaro_id] = DeviceInfo(
|
||||
identifiers={(DOMAIN, master_entity.fibaro_id)},
|
||||
self._device_infos[main_device.fibaro_id] = DeviceInfo(
|
||||
identifiers={(DOMAIN, main_device.fibaro_id)},
|
||||
manufacturer=manufacturer,
|
||||
name=master_entity.name,
|
||||
name=main_device.name,
|
||||
via_device=(DOMAIN, self.hub_serial),
|
||||
)
|
||||
|
||||
@ -239,6 +222,10 @@ class FibaroController:
|
||||
def _read_devices(self) -> None:
|
||||
"""Read and process the device list."""
|
||||
devices = self._fibaro_device_manager.get_devices()
|
||||
|
||||
for main_device in find_master_devices(devices):
|
||||
self._create_device_info(main_device)
|
||||
|
||||
self._device_map = {}
|
||||
last_climate_parent = None
|
||||
last_endpoint = None
|
||||
@ -258,7 +245,6 @@ class FibaroController:
|
||||
if platform is None:
|
||||
continue
|
||||
device.unique_id_str = f"{slugify(self.hub_serial)}.{device.fibaro_id}"
|
||||
self._create_device_info(device, devices)
|
||||
self._device_map[device.fibaro_id] = device
|
||||
_LOGGER.debug(
|
||||
"%s (%s, %s) -> %s %s",
|
||||
|
Loading…
x
Reference in New Issue
Block a user