mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Implemented unique ID support for Fibaro hub integration (#19055)
* Unique ID support New unique ID support, based on hub's serial number and device's permanent ID * Fixes, showing attributes Minor fixes Showing room, hub, fibaro_id for easier mapping and finding of devices * Update fibaro.py
This commit is contained in:
parent
47320adcc6
commit
f0d534cebc
@ -7,6 +7,7 @@ https://home-assistant.io/components/fibaro/
|
||||
|
||||
import logging
|
||||
from collections import defaultdict
|
||||
from typing import Optional
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import (ATTR_ARMED, ATTR_BATTERY_LEVEL,
|
||||
@ -65,8 +66,8 @@ class FibaroController():
|
||||
_device_map = None # Dict for mapping deviceId to device object
|
||||
fibaro_devices = None # List of devices by type
|
||||
_callbacks = {} # Dict of update value callbacks by deviceId
|
||||
_client = None # Fiblary's Client object for communication
|
||||
_state_handler = None # Fiblary's StateHandler object
|
||||
_client = None # Fiblary's Client object for communication
|
||||
_state_handler = None # Fiblary's StateHandler object
|
||||
_import_plugins = None # Whether to import devices from plugins
|
||||
|
||||
def __init__(self, username, password, url, import_plugins):
|
||||
@ -74,11 +75,14 @@ class FibaroController():
|
||||
from fiblary3.client.v4.client import Client as FibaroClient
|
||||
self._client = FibaroClient(url, username, password)
|
||||
self._scene_map = None
|
||||
self.hub_serial = None # Unique serial number of the hub
|
||||
|
||||
def connect(self):
|
||||
"""Start the communication with the Fibaro controller."""
|
||||
try:
|
||||
login = self._client.login.get()
|
||||
info = self._client.info.get()
|
||||
self.hub_serial = slugify(info.serialNumber)
|
||||
except AssertionError:
|
||||
_LOGGER.error("Can't connect to Fibaro HC. "
|
||||
"Please check URL.")
|
||||
@ -180,9 +184,12 @@ class FibaroController():
|
||||
room_name = 'Unknown'
|
||||
else:
|
||||
room_name = self._room_map[device.roomID].name
|
||||
device.room_name = room_name
|
||||
device.friendly_name = '{} {}'.format(room_name, device.name)
|
||||
device.ha_id = '{}_{}_{}'.format(
|
||||
slugify(room_name), slugify(device.name), device.id)
|
||||
device.unique_id_str = "{}.{}".format(
|
||||
self.hub_serial, device.id)
|
||||
self._scene_map[device.id] = device
|
||||
self.fibaro_devices['scene'].append(device)
|
||||
|
||||
@ -197,6 +204,7 @@ class FibaroController():
|
||||
room_name = 'Unknown'
|
||||
else:
|
||||
room_name = self._room_map[device.roomID].name
|
||||
device.room_name = room_name
|
||||
device.friendly_name = room_name + ' ' + device.name
|
||||
device.ha_id = '{}_{}_{}'.format(
|
||||
slugify(room_name), slugify(device.name), device.id)
|
||||
@ -207,6 +215,8 @@ class FibaroController():
|
||||
else:
|
||||
device.mapped_type = None
|
||||
if device.mapped_type:
|
||||
device.unique_id_str = "{}.{}".format(
|
||||
self.hub_serial, device.id)
|
||||
self._device_map[device.id] = device
|
||||
self.fibaro_devices[device.mapped_type].append(device)
|
||||
else:
|
||||
@ -347,7 +357,12 @@ class FibaroDevice(Entity):
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique ID."""
|
||||
return self.fibaro_device.unique_id_str
|
||||
|
||||
@property
|
||||
def name(self) -> Optional[str]:
|
||||
"""Return the name of the device."""
|
||||
return self._name
|
||||
|
||||
@ -380,5 +395,5 @@ class FibaroDevice(Entity):
|
||||
except (ValueError, KeyError):
|
||||
pass
|
||||
|
||||
attr['id'] = self.ha_id
|
||||
attr['fibaro_id'] = self.fibaro_device.id
|
||||
return attr
|
||||
|
Loading…
x
Reference in New Issue
Block a user