2019-02-13 20:21:14 +00:00
|
|
|
"""Support for the Fibaro devices."""
|
2024-03-08 13:15:26 +00:00
|
|
|
|
2021-03-17 22:49:01 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
from collections import defaultdict
|
2023-10-08 20:01:26 +00:00
|
|
|
from collections.abc import Callable, Mapping
|
2019-11-25 13:12:01 +00:00
|
|
|
import logging
|
2022-03-26 19:50:50 +00:00
|
|
|
from typing import Any
|
2019-11-25 13:12:01 +00:00
|
|
|
|
2025-02-28 19:47:03 +00:00
|
|
|
from pyfibaro.fibaro_client import (
|
|
|
|
FibaroAuthenticationFailed,
|
|
|
|
FibaroClient,
|
|
|
|
FibaroConnectFailed,
|
|
|
|
)
|
2025-03-02 13:38:56 +00:00
|
|
|
from pyfibaro.fibaro_data_helper import read_rooms
|
2023-02-11 21:13:12 +00:00
|
|
|
from pyfibaro.fibaro_device import DeviceModel
|
2025-02-28 19:47:03 +00:00
|
|
|
from pyfibaro.fibaro_info import InfoModel
|
2023-09-23 17:13:03 +00:00
|
|
|
from pyfibaro.fibaro_scene import SceneModel
|
2023-10-08 20:01:26 +00:00
|
|
|
from pyfibaro.fibaro_state_resolver import FibaroEvent, FibaroStateResolver
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
|
2023-02-12 20:50:50 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2024-09-16 13:29:29 +00:00
|
|
|
from homeassistant.const import CONF_PASSWORD, CONF_URL, CONF_USERNAME, Platform
|
2022-01-01 21:38:11 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2025-02-28 19:47:03 +00:00
|
|
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
2022-06-30 21:57:35 +00:00
|
|
|
from homeassistant.helpers import device_registry as dr
|
2024-07-07 13:21:38 +00:00
|
|
|
from homeassistant.helpers.device_registry import DeviceEntry, DeviceInfo
|
2022-03-29 04:56:04 +00:00
|
|
|
from homeassistant.util import slugify
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
|
2022-03-26 19:50:50 +00:00
|
|
|
from .const import CONF_IMPORT_PLUGINS, DOMAIN
|
|
|
|
|
2024-12-15 10:49:23 +00:00
|
|
|
type FibaroConfigEntry = ConfigEntry[FibaroController]
|
2019-02-13 20:21:14 +00:00
|
|
|
|
2024-12-15 10:49:23 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
2023-02-12 20:50:50 +00:00
|
|
|
|
2021-03-02 20:43:59 +00:00
|
|
|
PLATFORMS = [
|
2021-12-28 20:13:20 +00:00
|
|
|
Platform.BINARY_SENSOR,
|
|
|
|
Platform.CLIMATE,
|
|
|
|
Platform.COVER,
|
2024-01-16 08:47:53 +00:00
|
|
|
Platform.EVENT,
|
2021-12-28 20:13:20 +00:00
|
|
|
Platform.LIGHT,
|
2024-01-16 08:47:53 +00:00
|
|
|
Platform.LOCK,
|
2021-12-28 20:13:20 +00:00
|
|
|
Platform.SCENE,
|
|
|
|
Platform.SENSOR,
|
|
|
|
Platform.SWITCH,
|
2019-07-31 19:25:30 +00:00
|
|
|
]
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
|
|
|
|
FIBARO_TYPEMAP = {
|
2022-04-26 18:08:41 +00:00
|
|
|
"com.fibaro.multilevelSensor": Platform.SENSOR,
|
|
|
|
"com.fibaro.binarySwitch": Platform.SWITCH,
|
|
|
|
"com.fibaro.multilevelSwitch": Platform.SWITCH,
|
|
|
|
"com.fibaro.FGD212": Platform.LIGHT,
|
|
|
|
"com.fibaro.FGR": Platform.COVER,
|
|
|
|
"com.fibaro.doorSensor": Platform.BINARY_SENSOR,
|
|
|
|
"com.fibaro.doorWindowSensor": Platform.BINARY_SENSOR,
|
|
|
|
"com.fibaro.FGMS001": Platform.BINARY_SENSOR,
|
|
|
|
"com.fibaro.heatDetector": Platform.BINARY_SENSOR,
|
|
|
|
"com.fibaro.lifeDangerSensor": Platform.BINARY_SENSOR,
|
|
|
|
"com.fibaro.smokeSensor": Platform.BINARY_SENSOR,
|
|
|
|
"com.fibaro.remoteSwitch": Platform.SWITCH,
|
|
|
|
"com.fibaro.sensor": Platform.SENSOR,
|
|
|
|
"com.fibaro.colorController": Platform.LIGHT,
|
|
|
|
"com.fibaro.securitySensor": Platform.BINARY_SENSOR,
|
|
|
|
"com.fibaro.hvac": Platform.CLIMATE,
|
2022-11-24 18:16:33 +00:00
|
|
|
"com.fibaro.hvacSystem": Platform.CLIMATE,
|
2022-04-26 18:08:41 +00:00
|
|
|
"com.fibaro.setpoint": Platform.CLIMATE,
|
|
|
|
"com.fibaro.FGT001": Platform.CLIMATE,
|
|
|
|
"com.fibaro.thermostatDanfoss": Platform.CLIMATE,
|
|
|
|
"com.fibaro.doorLock": Platform.LOCK,
|
2022-05-23 10:33:25 +00:00
|
|
|
"com.fibaro.binarySensor": Platform.BINARY_SENSOR,
|
2022-11-12 09:43:11 +00:00
|
|
|
"com.fibaro.accelerometer": Platform.BINARY_SENSOR,
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
|
|
|
|
class FibaroController:
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
"""Initiate Fibaro Controller Class."""
|
|
|
|
|
2025-02-28 19:47:03 +00:00
|
|
|
def __init__(
|
|
|
|
self, fibaro_client: FibaroClient, info: InfoModel, import_plugins: bool
|
|
|
|
) -> None:
|
2023-02-11 21:13:12 +00:00
|
|
|
"""Initialize the Fibaro controller."""
|
2025-02-28 19:47:03 +00:00
|
|
|
self._client = fibaro_client
|
|
|
|
self._fibaro_info = info
|
2022-04-26 16:52:12 +00:00
|
|
|
|
2018-12-14 12:35:12 +00:00
|
|
|
# Whether to import devices from plugins
|
2025-02-28 19:47:03 +00:00
|
|
|
self._import_plugins = import_plugins
|
|
|
|
# Mapping roomId to room object
|
2025-03-02 13:38:56 +00:00
|
|
|
self._room_map = read_rooms(fibaro_client)
|
2023-10-06 08:13:30 +00:00
|
|
|
self._device_map: dict[int, DeviceModel] # Mapping deviceId to device object
|
2023-09-23 17:13:03 +00:00
|
|
|
self.fibaro_devices: dict[Platform, list[DeviceModel]] = defaultdict(
|
2022-04-26 16:52:12 +00:00
|
|
|
list
|
2022-04-26 18:08:41 +00:00
|
|
|
) # List of devices by entity platform
|
2023-09-23 17:13:03 +00:00
|
|
|
# All scenes
|
2025-02-28 19:47:03 +00:00
|
|
|
self._scenes = self._client.read_scenes()
|
2023-10-06 08:13:30 +00:00
|
|
|
self._callbacks: dict[int, list[Any]] = {} # Update value callbacks by deviceId
|
2023-10-08 20:01:26 +00:00
|
|
|
# Event callbacks by device id
|
|
|
|
self._event_callbacks: dict[int, list[Callable[[FibaroEvent], None]]] = {}
|
2025-02-28 19:47:03 +00:00
|
|
|
# Unique serial number of the hub
|
|
|
|
self.hub_serial = info.serial_number
|
2022-06-30 21:57:35 +00:00
|
|
|
# Device infos by fibaro device id
|
|
|
|
self._device_infos: dict[int, DeviceInfo] = {}
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
self._read_devices()
|
2022-03-26 19:50:50 +00:00
|
|
|
|
2023-10-06 08:13:30 +00:00
|
|
|
def enable_state_handler(self) -> None:
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
"""Start StateHandler thread for monitoring updates."""
|
2023-02-11 21:13:12 +00:00
|
|
|
self._client.register_update_handler(self._on_state_change)
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
|
2023-10-06 08:13:30 +00:00
|
|
|
def disable_state_handler(self) -> None:
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
"""Stop StateHandler thread used for monitoring updates."""
|
2023-02-11 21:13:12 +00:00
|
|
|
self._client.unregister_update_handler()
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
|
2023-10-06 08:13:30 +00:00
|
|
|
def _on_state_change(self, state: Any) -> None:
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
"""Handle change report received from the HomeCenter."""
|
|
|
|
callback_set = set()
|
2019-07-31 19:25:30 +00:00
|
|
|
for change in state.get("changes", []):
|
2018-11-29 21:57:05 +00:00
|
|
|
try:
|
2019-07-31 19:25:30 +00:00
|
|
|
dev_id = change.pop("id")
|
2020-10-28 19:43:48 +00:00
|
|
|
if dev_id not in self._device_map:
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
continue
|
2018-11-29 21:57:05 +00:00
|
|
|
device = self._device_map[dev_id]
|
|
|
|
for property_name, value in change.items():
|
2019-07-31 19:25:30 +00:00
|
|
|
if property_name == "log":
|
2018-11-29 21:57:05 +00:00
|
|
|
if value and value != "transfer OK":
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.debug("LOG %s: %s", device.friendly_name, value)
|
2018-11-29 21:57:05 +00:00
|
|
|
continue
|
2019-07-31 19:25:30 +00:00
|
|
|
if property_name == "logTemp":
|
2018-11-29 21:57:05 +00:00
|
|
|
continue
|
|
|
|
if property_name in device.properties:
|
2019-07-31 19:25:30 +00:00
|
|
|
device.properties[property_name] = value
|
|
|
|
_LOGGER.debug(
|
|
|
|
"<- %s.%s = %s", device.ha_id, property_name, str(value)
|
|
|
|
)
|
2018-11-29 21:57:05 +00:00
|
|
|
else:
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.warning("%s.%s not found", device.ha_id, property_name)
|
2018-11-29 21:57:05 +00:00
|
|
|
if dev_id in self._callbacks:
|
|
|
|
callback_set.add(dev_id)
|
|
|
|
except (ValueError, KeyError):
|
|
|
|
pass
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
for item in callback_set:
|
2022-01-19 18:32:44 +00:00
|
|
|
for callback in self._callbacks[item]:
|
|
|
|
callback()
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
|
2023-10-08 20:01:26 +00:00
|
|
|
resolver = FibaroStateResolver(state)
|
|
|
|
for event in resolver.get_events():
|
2023-11-02 17:07:35 +00:00
|
|
|
# event does not always have a fibaro id, therefore it is
|
|
|
|
# essential that we first check for relevant event type
|
2023-10-08 20:01:26 +00:00
|
|
|
if (
|
|
|
|
event.event_type.lower() == "centralsceneevent"
|
2023-11-02 17:07:35 +00:00
|
|
|
and event.fibaro_id in self._event_callbacks
|
2023-10-08 20:01:26 +00:00
|
|
|
):
|
2023-11-02 17:07:35 +00:00
|
|
|
for callback in self._event_callbacks[event.fibaro_id]:
|
2023-10-08 20:01:26 +00:00
|
|
|
callback(event)
|
|
|
|
|
2023-10-06 08:13:30 +00:00
|
|
|
def register(self, device_id: int, callback: Any) -> None:
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
"""Register device with a callback for updates."""
|
2023-10-10 04:07:29 +00:00
|
|
|
device_callbacks = self._callbacks.setdefault(device_id, [])
|
|
|
|
device_callbacks.append(callback)
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
|
2023-10-08 20:01:26 +00:00
|
|
|
def register_event(
|
|
|
|
self, device_id: int, callback: Callable[[FibaroEvent], None]
|
|
|
|
) -> None:
|
|
|
|
"""Register device with a callback for central scene events.
|
|
|
|
|
|
|
|
The callback receives one parameter with the event.
|
|
|
|
"""
|
2023-10-10 04:07:29 +00:00
|
|
|
device_callbacks = self._event_callbacks.setdefault(device_id, [])
|
|
|
|
device_callbacks.append(callback)
|
2023-10-08 20:01:26 +00:00
|
|
|
|
2023-10-06 08:13:30 +00:00
|
|
|
def get_children(self, device_id: int) -> list[DeviceModel]:
|
2019-04-09 04:24:57 +00:00
|
|
|
"""Get a list of child devices."""
|
|
|
|
return [
|
2019-07-31 19:25:30 +00:00
|
|
|
device
|
|
|
|
for device in self._device_map.values()
|
2023-02-11 21:13:12 +00:00
|
|
|
if device.parent_fibaro_id == device_id
|
2019-07-31 19:25:30 +00:00
|
|
|
]
|
2019-04-09 04:24:57 +00:00
|
|
|
|
2023-10-06 08:13:30 +00:00
|
|
|
def get_children2(self, device_id: int, endpoint_id: int) -> list[DeviceModel]:
|
2020-09-07 02:03:03 +00:00
|
|
|
"""Get a list of child devices for the same endpoint."""
|
|
|
|
return [
|
|
|
|
device
|
|
|
|
for device in self._device_map.values()
|
2023-02-11 21:13:12 +00:00
|
|
|
if device.parent_fibaro_id == device_id
|
|
|
|
and (not device.has_endpoint_id or device.endpoint_id == endpoint_id)
|
2020-09-07 02:03:03 +00:00
|
|
|
]
|
|
|
|
|
2023-10-06 08:13:30 +00:00
|
|
|
def get_siblings(self, device: DeviceModel) -> list[DeviceModel]:
|
2019-04-09 04:24:57 +00:00
|
|
|
"""Get the siblings of a device."""
|
2023-02-11 21:13:12 +00:00
|
|
|
if device.has_endpoint_id:
|
2023-10-12 17:51:43 +00:00
|
|
|
return self.get_children2(device.parent_fibaro_id, device.endpoint_id)
|
|
|
|
return self.get_children(device.parent_fibaro_id)
|
2019-04-09 04:24:57 +00:00
|
|
|
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
@staticmethod
|
2023-10-06 08:13:30 +00:00
|
|
|
def _map_device_to_platform(device: DeviceModel) -> Platform | None:
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
"""Map device to HA device type."""
|
|
|
|
# Use our lookup table to identify device type
|
2022-04-26 18:08:41 +00:00
|
|
|
platform: Platform | None = None
|
2023-02-11 21:13:12 +00:00
|
|
|
if device.type:
|
2022-04-26 18:08:41 +00:00
|
|
|
platform = FIBARO_TYPEMAP.get(device.type)
|
2023-02-11 21:13:12 +00:00
|
|
|
if platform is None and device.base_type:
|
|
|
|
platform = FIBARO_TYPEMAP.get(device.base_type)
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
|
|
|
|
# We can also identify device type by its capabilities
|
2022-04-26 18:08:41 +00:00
|
|
|
if platform is None:
|
2019-07-31 19:25:30 +00:00
|
|
|
if "setBrightness" in device.actions:
|
2022-04-26 18:08:41 +00:00
|
|
|
platform = Platform.LIGHT
|
2019-07-31 19:25:30 +00:00
|
|
|
elif "turnOn" in device.actions:
|
2022-04-26 18:08:41 +00:00
|
|
|
platform = Platform.SWITCH
|
2019-07-31 19:25:30 +00:00
|
|
|
elif "open" in device.actions:
|
2022-04-26 18:08:41 +00:00
|
|
|
platform = Platform.COVER
|
2020-08-29 02:16:02 +00:00
|
|
|
elif "secure" in device.actions:
|
2022-04-26 18:08:41 +00:00
|
|
|
platform = Platform.LOCK
|
2023-10-08 20:01:26 +00:00
|
|
|
elif device.has_central_scene_event:
|
|
|
|
platform = Platform.EVENT
|
2024-09-30 10:01:27 +00:00
|
|
|
elif device.value.has_value and device.value.is_bool_value:
|
|
|
|
platform = Platform.BINARY_SENSOR
|
|
|
|
elif (
|
|
|
|
device.value.has_value
|
|
|
|
or "power" in device.properties
|
|
|
|
or "energy" in device.properties
|
|
|
|
):
|
|
|
|
platform = Platform.SENSOR
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
|
|
|
|
# Switches that control lights should show up as lights
|
2022-04-26 18:08:41 +00:00
|
|
|
if platform == Platform.SWITCH and device.properties.get("isLight", False):
|
|
|
|
platform = Platform.LIGHT
|
|
|
|
return platform
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
|
2023-02-11 21:13:12 +00:00
|
|
|
def _create_device_info(
|
|
|
|
self, device: DeviceModel, devices: list[DeviceModel]
|
|
|
|
) -> None:
|
2022-06-30 21:57:35 +00:00
|
|
|
"""Create the device info. Unrooted entities are directly shown below the home center."""
|
|
|
|
|
|
|
|
# The home center is always id 1 (z-wave primary controller)
|
2023-02-11 21:13:12 +00:00
|
|
|
if device.parent_fibaro_id <= 1:
|
2022-06-30 21:57:35 +00:00
|
|
|
return
|
|
|
|
|
2023-10-06 08:13:30 +00:00
|
|
|
master_entity: DeviceModel | None = None
|
2023-02-11 21:13:12 +00:00
|
|
|
if device.parent_fibaro_id == 1:
|
2022-06-30 21:57:35 +00:00
|
|
|
master_entity = device
|
|
|
|
else:
|
|
|
|
for parent in devices:
|
2023-02-11 21:13:12 +00:00
|
|
|
if parent.fibaro_id == device.parent_fibaro_id:
|
2022-06-30 21:57:35 +00:00
|
|
|
master_entity = parent
|
|
|
|
if master_entity is None:
|
2023-02-11 21:13:12 +00:00
|
|
|
_LOGGER.error("Parent with id %s not found", device.parent_fibaro_id)
|
2022-06-30 21:57:35 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
if "zwaveCompany" in master_entity.properties:
|
2023-02-11 21:13:12 +00:00
|
|
|
manufacturer = master_entity.properties.get("zwaveCompany")
|
2022-06-30 21:57:35 +00:00
|
|
|
else:
|
2023-02-12 18:56:02 +00:00
|
|
|
manufacturer = None
|
2022-06-30 21:57:35 +00:00
|
|
|
|
2023-02-11 21:13:12 +00:00
|
|
|
self._device_infos[master_entity.fibaro_id] = DeviceInfo(
|
|
|
|
identifiers={(DOMAIN, master_entity.fibaro_id)},
|
2022-06-30 21:57:35 +00:00
|
|
|
manufacturer=manufacturer,
|
|
|
|
name=master_entity.name,
|
|
|
|
via_device=(DOMAIN, self.hub_serial),
|
|
|
|
)
|
|
|
|
|
2023-10-06 08:13:30 +00:00
|
|
|
def get_device_info(self, device: DeviceModel) -> DeviceInfo:
|
2022-06-30 21:57:35 +00:00
|
|
|
"""Get the device info by fibaro device id."""
|
2023-02-11 21:13:12 +00:00
|
|
|
if device.fibaro_id in self._device_infos:
|
|
|
|
return self._device_infos[device.fibaro_id]
|
|
|
|
if device.parent_fibaro_id in self._device_infos:
|
|
|
|
return self._device_infos[device.parent_fibaro_id]
|
2022-06-30 21:57:35 +00:00
|
|
|
return DeviceInfo(identifiers={(DOMAIN, self.hub_serial)})
|
|
|
|
|
2024-07-07 13:21:38 +00:00
|
|
|
def get_all_device_identifiers(self) -> list[set[tuple[str, str]]]:
|
|
|
|
"""Get all identifiers of fibaro integration."""
|
|
|
|
return [device["identifiers"] for device in self._device_infos.values()]
|
|
|
|
|
2023-05-24 12:57:35 +00:00
|
|
|
def get_room_name(self, room_id: int) -> str | None:
|
|
|
|
"""Get the room name by room id."""
|
2025-03-02 13:38:56 +00:00
|
|
|
return self._room_map.get(room_id)
|
2023-05-24 12:57:35 +00:00
|
|
|
|
2023-09-23 17:13:03 +00:00
|
|
|
def read_scenes(self) -> list[SceneModel]:
|
|
|
|
"""Return list of scenes."""
|
|
|
|
return self._scenes
|
2018-12-03 13:57:55 +00:00
|
|
|
|
2025-02-28 19:47:03 +00:00
|
|
|
def read_fibaro_info(self) -> InfoModel:
|
|
|
|
"""Return the general info about the hub."""
|
|
|
|
return self._fibaro_info
|
|
|
|
|
|
|
|
def get_frontend_url(self) -> str:
|
|
|
|
"""Return the url to the Fibaro hub web UI."""
|
|
|
|
return self._client.frontend_url()
|
|
|
|
|
2023-10-06 08:13:30 +00:00
|
|
|
def _read_devices(self) -> None:
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
"""Read and process the device list."""
|
2023-02-11 21:13:12 +00:00
|
|
|
devices = self._client.read_devices()
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
self._device_map = {}
|
2019-04-09 04:24:57 +00:00
|
|
|
last_climate_parent = None
|
2020-09-07 02:03:03 +00:00
|
|
|
last_endpoint = None
|
2018-11-29 21:57:05 +00:00
|
|
|
for device in devices:
|
|
|
|
try:
|
2019-01-11 23:29:54 +00:00
|
|
|
device.fibaro_controller = self
|
2025-03-02 13:38:56 +00:00
|
|
|
room_name = self.get_room_name(device.room_id)
|
|
|
|
if not room_name:
|
2019-07-31 19:25:30 +00:00
|
|
|
room_name = "Unknown"
|
2018-12-06 08:28:06 +00:00
|
|
|
device.room_name = room_name
|
2020-01-03 13:47:06 +00:00
|
|
|
device.friendly_name = f"{room_name} {device.name}"
|
2020-02-25 01:54:20 +00:00
|
|
|
device.ha_id = (
|
2023-02-11 21:13:12 +00:00
|
|
|
f"{slugify(room_name)}_{slugify(device.name)}_{device.fibaro_id}"
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2023-02-11 21:13:12 +00:00
|
|
|
if device.enabled and (not device.is_plugin or self._import_plugins):
|
2025-03-02 13:38:56 +00:00
|
|
|
platform = self._map_device_to_platform(device)
|
|
|
|
if platform is None:
|
2020-09-07 02:03:03 +00:00
|
|
|
continue
|
2023-02-11 21:13:12 +00:00
|
|
|
device.unique_id_str = f"{slugify(self.hub_serial)}.{device.fibaro_id}"
|
2022-06-30 21:57:35 +00:00
|
|
|
self._create_device_info(device, devices)
|
2023-02-11 21:13:12 +00:00
|
|
|
self._device_map[device.fibaro_id] = device
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.debug(
|
|
|
|
"%s (%s, %s) -> %s %s",
|
|
|
|
device.ha_id,
|
|
|
|
device.type,
|
2023-02-11 21:13:12 +00:00
|
|
|
device.base_type,
|
2022-04-26 18:08:41 +00:00
|
|
|
platform,
|
2019-07-31 19:25:30 +00:00
|
|
|
str(device),
|
|
|
|
)
|
2022-04-26 18:08:41 +00:00
|
|
|
if platform != Platform.CLIMATE:
|
|
|
|
self.fibaro_devices[platform].append(device)
|
2020-09-07 02:03:03 +00:00
|
|
|
continue
|
|
|
|
# We group climate devices into groups with the same
|
|
|
|
# endPointID belonging to the same parent device.
|
2023-02-11 21:13:12 +00:00
|
|
|
if device.has_endpoint_id:
|
2020-09-07 02:03:03 +00:00
|
|
|
_LOGGER.debug(
|
|
|
|
"climate device: %s, endPointId: %s",
|
|
|
|
device.ha_id,
|
2023-02-11 21:13:12 +00:00
|
|
|
device.endpoint_id,
|
2020-09-07 02:03:03 +00:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
_LOGGER.debug("climate device: %s, no endPointId", device.ha_id)
|
|
|
|
# If a sibling of this device has been added, skip this one
|
|
|
|
# otherwise add the first visible device in the group
|
|
|
|
# which is a hack, but solves a problem with FGT having
|
|
|
|
# hidden compatibility devices before the real device
|
2023-02-11 21:13:12 +00:00
|
|
|
if last_climate_parent != device.parent_fibaro_id or (
|
|
|
|
device.has_endpoint_id and last_endpoint != device.endpoint_id
|
2020-09-07 02:03:03 +00:00
|
|
|
):
|
|
|
|
_LOGGER.debug("Handle separately")
|
2022-04-26 18:08:41 +00:00
|
|
|
self.fibaro_devices[platform].append(device)
|
2023-02-11 21:13:12 +00:00
|
|
|
last_climate_parent = device.parent_fibaro_id
|
|
|
|
last_endpoint = device.endpoint_id
|
2020-09-07 02:03:03 +00:00
|
|
|
else:
|
|
|
|
_LOGGER.debug("not handling separately")
|
2018-11-29 21:57:05 +00:00
|
|
|
except (KeyError, ValueError):
|
|
|
|
pass
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
|
|
|
|
|
2025-02-28 19:47:03 +00:00
|
|
|
def connect_fibaro_client(data: Mapping[str, Any]) -> tuple[InfoModel, FibaroClient]:
|
|
|
|
"""Connect to the fibaro hub and read some basic data."""
|
|
|
|
client = FibaroClient(data[CONF_URL])
|
|
|
|
info = client.connect_with_credentials(data[CONF_USERNAME], data[CONF_PASSWORD])
|
|
|
|
return (info, client)
|
|
|
|
|
|
|
|
|
2024-04-22 07:29:58 +00:00
|
|
|
def init_controller(data: Mapping[str, Any]) -> FibaroController:
|
2025-02-28 19:47:03 +00:00
|
|
|
"""Connect to the fibaro hub and init the controller."""
|
|
|
|
info, client = connect_fibaro_client(data)
|
|
|
|
return FibaroController(client, info, data[CONF_IMPORT_PLUGINS])
|
2022-03-26 19:50:50 +00:00
|
|
|
|
|
|
|
|
2024-12-15 10:49:23 +00:00
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: FibaroConfigEntry) -> bool:
|
2022-04-26 16:52:12 +00:00
|
|
|
"""Set up the Fibaro Component.
|
|
|
|
|
|
|
|
The unique id of the config entry is the serial number of the home center.
|
|
|
|
"""
|
2022-03-26 19:50:50 +00:00
|
|
|
try:
|
2024-04-22 07:29:58 +00:00
|
|
|
controller = await hass.async_add_executor_job(init_controller, entry.data)
|
2022-03-26 19:50:50 +00:00
|
|
|
except FibaroConnectFailed as connect_ex:
|
|
|
|
raise ConfigEntryNotReady(
|
|
|
|
f"Could not connect to controller at {entry.data[CONF_URL]}"
|
|
|
|
) from connect_ex
|
2025-02-28 19:47:03 +00:00
|
|
|
except FibaroAuthenticationFailed as auth_ex:
|
2022-09-05 12:55:12 +00:00
|
|
|
raise ConfigEntryAuthFailed from auth_ex
|
2022-03-26 19:50:50 +00:00
|
|
|
|
2024-12-15 10:49:23 +00:00
|
|
|
entry.runtime_data = controller
|
2019-01-11 23:29:54 +00:00
|
|
|
|
2022-06-30 21:57:35 +00:00
|
|
|
# register the hub device info separately as the hub has sometimes no entities
|
2025-02-28 19:47:03 +00:00
|
|
|
fibaro_info = controller.read_fibaro_info()
|
2022-06-30 21:57:35 +00:00
|
|
|
device_registry = dr.async_get(hass)
|
|
|
|
device_registry.async_get_or_create(
|
|
|
|
config_entry_id=entry.entry_id,
|
|
|
|
identifiers={(DOMAIN, controller.hub_serial)},
|
2023-10-22 14:53:29 +00:00
|
|
|
serial_number=controller.hub_serial,
|
2025-02-28 19:47:03 +00:00
|
|
|
manufacturer=fibaro_info.manufacturer_name,
|
|
|
|
name=fibaro_info.hc_name,
|
|
|
|
model=fibaro_info.model_name,
|
|
|
|
sw_version=fibaro_info.current_version,
|
|
|
|
configuration_url=controller.get_frontend_url(),
|
|
|
|
connections={(dr.CONNECTION_NETWORK_MAC, fibaro_info.mac_address)},
|
2022-06-30 21:57:35 +00:00
|
|
|
)
|
|
|
|
|
2022-07-09 15:27:42 +00:00
|
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
2019-01-11 23:29:54 +00:00
|
|
|
|
2022-03-26 19:50:50 +00:00
|
|
|
controller.enable_state_handler()
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2024-12-15 10:49:23 +00:00
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: FibaroConfigEntry) -> bool:
|
2022-03-26 19:50:50 +00:00
|
|
|
"""Unload a config entry."""
|
2022-03-28 15:23:44 +00:00
|
|
|
_LOGGER.debug("Shutting down Fibaro connection")
|
2022-03-26 19:50:50 +00:00
|
|
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
|
|
|
|
2024-12-15 10:49:23 +00:00
|
|
|
entry.runtime_data.disable_state_handler()
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
|
2022-03-26 19:50:50 +00:00
|
|
|
return unload_ok
|
Initial support for Fibaro HomeCenter hubs (#17891)
* Fibaro HC connection, initial commit
Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA.
* Cover, switch, bugfixes
Initial support for covers
Initial support for switches
Bugfixes
* Some cleanup and improved lights
pylint based cleanup
light switches handled properly
light features reported correctly
* Added status updates and actions
Lights, Blinds, Switches are mostly working now
* Code cleanup, fiblary3 req
Fiblary3 is now in pypi, set it as req
Cleanup based on pylint
* Included in .coveragerc and added how to use guide
Included the fibaro component in coveragerc
Added usage instructions to file header
* PyLint inspired fixes
Fixed pylint warnings
* PyLint inspired fixes
PyLint inspired fixes
* updated to fiblary3 0.1.5
* Minor fixes to finally pass pull req
Fixed fiblary3 to work with python 3.5
Updated fiblary3 to 0.1.6
(added energy and batteryLevel dummies)
* module import and flake8 fixes
Finally (hopefully) figured out what lint is complaining about
* Fixed color support for lights, simplified callback
Fixed color support for lights
Simplified callback for updates
Uses updated fiblary3 for color light handling
* Lean and mean refactor
While waiting for a brave reviewer, I've been making the code smaller and easier to understand.
* Minor fixes to please HoundCI
* Removed unused component
Scenes are not implemented yet
* Nicer comments.
* DEVICE_CLASS, ignore plugins, improved mapping
Added support for device class and icons in sensors and binary_sensors
Improved mapping of sensors and added heuristic matching
Added support for hidden devices
Fixed conversion to float in sensors
* Fixed dimming
Fibaro apparently does not need, nor like the extra turnOn commands for dimmers
* flake8
* Cleanup, Light fixes, switch power
Cleanup of the component to separate init from connect, handle connection error better
Improved light handling, especially for RGBW strips and working around Fibaro quirks
Added energy and power reporting to switches
* Missing comment added
Missing comment added to please flake8
* Removed everything but bin.sensors
Stripdown, hoping for a review
* better aligned comments
OMG
* Fixes based on code review
Fixes based on code review
* Implemented stopping
Implemented stopping of StateHandler thread
Cleanup for clarity
* Minor fix
Removed unnecessary list copying
* Nicer wording on shutdown
* Minor changes based on code review
* minor fixes based on code review
* removed extra line break
2018-11-14 19:58:32 +00:00
|
|
|
|
|
|
|
|
2024-07-07 13:21:38 +00:00
|
|
|
async def async_remove_config_entry_device(
|
2024-12-15 10:49:23 +00:00
|
|
|
hass: HomeAssistant, config_entry: FibaroConfigEntry, device_entry: DeviceEntry
|
2024-07-07 13:21:38 +00:00
|
|
|
) -> bool:
|
|
|
|
"""Remove a device entry from fibaro integration.
|
|
|
|
|
|
|
|
Only removing devices which are not present anymore are eligible to be removed.
|
|
|
|
"""
|
2024-12-15 10:49:23 +00:00
|
|
|
controller = config_entry.runtime_data
|
2024-07-07 13:21:38 +00:00
|
|
|
for identifiers in controller.get_all_device_identifiers():
|
|
|
|
if device_entry.identifiers == identifiers:
|
|
|
|
# Fibaro device is still served by the controller,
|
|
|
|
# do not allow to remove the device entry
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|