mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
Use platform enum consistently in fibaro integration (#69035)
This commit is contained in:
parent
853b57e7cf
commit
e894ffecd8
@ -60,26 +60,26 @@ PLATFORMS = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
FIBARO_TYPEMAP = {
|
FIBARO_TYPEMAP = {
|
||||||
"com.fibaro.multilevelSensor": "sensor",
|
"com.fibaro.multilevelSensor": Platform.SENSOR,
|
||||||
"com.fibaro.binarySwitch": "switch",
|
"com.fibaro.binarySwitch": Platform.SWITCH,
|
||||||
"com.fibaro.multilevelSwitch": "switch",
|
"com.fibaro.multilevelSwitch": Platform.SWITCH,
|
||||||
"com.fibaro.FGD212": "light",
|
"com.fibaro.FGD212": Platform.LIGHT,
|
||||||
"com.fibaro.FGR": "cover",
|
"com.fibaro.FGR": Platform.COVER,
|
||||||
"com.fibaro.doorSensor": "binary_sensor",
|
"com.fibaro.doorSensor": Platform.BINARY_SENSOR,
|
||||||
"com.fibaro.doorWindowSensor": "binary_sensor",
|
"com.fibaro.doorWindowSensor": Platform.BINARY_SENSOR,
|
||||||
"com.fibaro.FGMS001": "binary_sensor",
|
"com.fibaro.FGMS001": Platform.BINARY_SENSOR,
|
||||||
"com.fibaro.heatDetector": "binary_sensor",
|
"com.fibaro.heatDetector": Platform.BINARY_SENSOR,
|
||||||
"com.fibaro.lifeDangerSensor": "binary_sensor",
|
"com.fibaro.lifeDangerSensor": Platform.BINARY_SENSOR,
|
||||||
"com.fibaro.smokeSensor": "binary_sensor",
|
"com.fibaro.smokeSensor": Platform.BINARY_SENSOR,
|
||||||
"com.fibaro.remoteSwitch": "switch",
|
"com.fibaro.remoteSwitch": Platform.SWITCH,
|
||||||
"com.fibaro.sensor": "sensor",
|
"com.fibaro.sensor": Platform.SENSOR,
|
||||||
"com.fibaro.colorController": "light",
|
"com.fibaro.colorController": Platform.LIGHT,
|
||||||
"com.fibaro.securitySensor": "binary_sensor",
|
"com.fibaro.securitySensor": Platform.BINARY_SENSOR,
|
||||||
"com.fibaro.hvac": "climate",
|
"com.fibaro.hvac": Platform.CLIMATE,
|
||||||
"com.fibaro.setpoint": "climate",
|
"com.fibaro.setpoint": Platform.CLIMATE,
|
||||||
"com.fibaro.FGT001": "climate",
|
"com.fibaro.FGT001": Platform.CLIMATE,
|
||||||
"com.fibaro.thermostatDanfoss": "climate",
|
"com.fibaro.thermostatDanfoss": Platform.CLIMATE,
|
||||||
"com.fibaro.doorLock": "lock",
|
"com.fibaro.doorLock": Platform.LOCK,
|
||||||
}
|
}
|
||||||
|
|
||||||
DEVICE_CONFIG_SCHEMA_ENTRY = vol.Schema(
|
DEVICE_CONFIG_SCHEMA_ENTRY = vol.Schema(
|
||||||
@ -158,9 +158,9 @@ class FibaroController:
|
|||||||
self._import_plugins = config[CONF_IMPORT_PLUGINS]
|
self._import_plugins = config[CONF_IMPORT_PLUGINS]
|
||||||
self._room_map = None # Mapping roomId to room object
|
self._room_map = None # Mapping roomId to room object
|
||||||
self._device_map = None # Mapping deviceId to device object
|
self._device_map = None # Mapping deviceId to device object
|
||||||
self.fibaro_devices: dict[str, list] = defaultdict(
|
self.fibaro_devices: dict[Platform, list] = defaultdict(
|
||||||
list
|
list
|
||||||
) # List of devices by type
|
) # List of devices by entity platform
|
||||||
self._callbacks: dict[Any, Any] = {} # Update value callbacks by deviceId
|
self._callbacks: dict[Any, Any] = {} # Update value callbacks by deviceId
|
||||||
self._state_handler = None # Fiblary's StateHandler object
|
self._state_handler = None # Fiblary's StateHandler object
|
||||||
self.hub_serial = None # Unique serial number of the hub
|
self.hub_serial = None # Unique serial number of the hub
|
||||||
@ -282,35 +282,35 @@ class FibaroController:
|
|||||||
return self.get_children(self._device_map[device.id].parentId)
|
return self.get_children(self._device_map[device.id].parentId)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _map_device_to_type(device):
|
def _map_device_to_platform(device: Any) -> Platform | None:
|
||||||
"""Map device to HA device type."""
|
"""Map device to HA device type."""
|
||||||
# Use our lookup table to identify device type
|
# Use our lookup table to identify device type
|
||||||
device_type = None
|
platform: Platform | None = None
|
||||||
if "type" in device:
|
if "type" in device:
|
||||||
device_type = FIBARO_TYPEMAP.get(device.type)
|
platform = FIBARO_TYPEMAP.get(device.type)
|
||||||
if device_type is None and "baseType" in device:
|
if platform is None and "baseType" in device:
|
||||||
device_type = FIBARO_TYPEMAP.get(device.baseType)
|
platform = FIBARO_TYPEMAP.get(device.baseType)
|
||||||
|
|
||||||
# We can also identify device type by its capabilities
|
# We can also identify device type by its capabilities
|
||||||
if device_type is None:
|
if platform is None:
|
||||||
if "setBrightness" in device.actions:
|
if "setBrightness" in device.actions:
|
||||||
device_type = "light"
|
platform = Platform.LIGHT
|
||||||
elif "turnOn" in device.actions:
|
elif "turnOn" in device.actions:
|
||||||
device_type = "switch"
|
platform = Platform.SWITCH
|
||||||
elif "open" in device.actions:
|
elif "open" in device.actions:
|
||||||
device_type = "cover"
|
platform = Platform.COVER
|
||||||
elif "secure" in device.actions:
|
elif "secure" in device.actions:
|
||||||
device_type = "lock"
|
platform = Platform.LOCK
|
||||||
elif "value" in device.properties:
|
elif "value" in device.properties:
|
||||||
if device.properties.value in ("true", "false"):
|
if device.properties.value in ("true", "false"):
|
||||||
device_type = "binary_sensor"
|
platform = Platform.BINARY_SENSOR
|
||||||
else:
|
else:
|
||||||
device_type = "sensor"
|
platform = Platform.SENSOR
|
||||||
|
|
||||||
# Switches that control lights should show up as lights
|
# Switches that control lights should show up as lights
|
||||||
if device_type == "switch" and device.properties.get("isLight", False):
|
if platform == Platform.SWITCH and device.properties.get("isLight", False):
|
||||||
device_type = "light"
|
platform = Platform.LIGHT
|
||||||
return device_type
|
return platform
|
||||||
|
|
||||||
def _read_scenes(self):
|
def _read_scenes(self):
|
||||||
scenes = self._client.scenes.list()
|
scenes = self._client.scenes.list()
|
||||||
@ -330,7 +330,7 @@ class FibaroController:
|
|||||||
)
|
)
|
||||||
device.unique_id_str = f"{self.hub_serial}.scene.{device.id}"
|
device.unique_id_str = f"{self.hub_serial}.scene.{device.id}"
|
||||||
self._scene_map[device.id] = device
|
self._scene_map[device.id] = device
|
||||||
self.fibaro_devices["scene"].append(device)
|
self.fibaro_devices[Platform.SCENE].append(device)
|
||||||
_LOGGER.debug("%s scene -> %s", device.ha_id, device)
|
_LOGGER.debug("%s scene -> %s", device.ha_id, device)
|
||||||
|
|
||||||
def _read_devices(self):
|
def _read_devices(self):
|
||||||
@ -357,10 +357,10 @@ class FibaroController:
|
|||||||
"isPlugin" not in device
|
"isPlugin" not in device
|
||||||
or (not device.isPlugin or self._import_plugins)
|
or (not device.isPlugin or self._import_plugins)
|
||||||
):
|
):
|
||||||
device.mapped_type = self._map_device_to_type(device)
|
device.mapped_platform = self._map_device_to_platform(device)
|
||||||
else:
|
else:
|
||||||
device.mapped_type = None
|
device.mapped_platform = None
|
||||||
if (dtype := device.mapped_type) is None:
|
if (platform := device.mapped_platform) is None:
|
||||||
continue
|
continue
|
||||||
device.unique_id_str = f"{self.hub_serial}.{device.id}"
|
device.unique_id_str = f"{self.hub_serial}.{device.id}"
|
||||||
self._device_map[device.id] = device
|
self._device_map[device.id] = device
|
||||||
@ -369,11 +369,11 @@ class FibaroController:
|
|||||||
device.ha_id,
|
device.ha_id,
|
||||||
device.type,
|
device.type,
|
||||||
device.baseType,
|
device.baseType,
|
||||||
dtype,
|
platform,
|
||||||
str(device),
|
str(device),
|
||||||
)
|
)
|
||||||
if dtype != "climate":
|
if platform != Platform.CLIMATE:
|
||||||
self.fibaro_devices[dtype].append(device)
|
self.fibaro_devices[platform].append(device)
|
||||||
continue
|
continue
|
||||||
# We group climate devices into groups with the same
|
# We group climate devices into groups with the same
|
||||||
# endPointID belonging to the same parent device.
|
# endPointID belonging to the same parent device.
|
||||||
@ -394,7 +394,7 @@ class FibaroController:
|
|||||||
and last_endpoint != device.properties.endPointId
|
and last_endpoint != device.properties.endPointId
|
||||||
):
|
):
|
||||||
_LOGGER.debug("Handle separately")
|
_LOGGER.debug("Handle separately")
|
||||||
self.fibaro_devices[dtype].append(device)
|
self.fibaro_devices[platform].append(device)
|
||||||
last_climate_parent = device.parentId
|
last_climate_parent = device.parentId
|
||||||
if "endPointId" in device.properties:
|
if "endPointId" in device.properties:
|
||||||
last_endpoint = device.properties.endPointId
|
last_endpoint = device.properties.endPointId
|
||||||
|
@ -7,6 +7,7 @@ from homeassistant.components.binary_sensor import (
|
|||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
@ -38,7 +39,7 @@ async def async_setup_entry(
|
|||||||
[
|
[
|
||||||
FibaroBinarySensor(device)
|
FibaroBinarySensor(device)
|
||||||
for device in hass.data[DOMAIN][entry.entry_id][FIBARO_DEVICES][
|
for device in hass.data[DOMAIN][entry.entry_id][FIBARO_DEVICES][
|
||||||
"binary_sensor"
|
Platform.BINARY_SENSOR
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
True,
|
True,
|
||||||
|
@ -11,7 +11,12 @@ from homeassistant.components.climate.const import (
|
|||||||
HVACMode,
|
HVACMode,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
from homeassistant.const import (
|
||||||
|
ATTR_TEMPERATURE,
|
||||||
|
TEMP_CELSIUS,
|
||||||
|
TEMP_FAHRENHEIT,
|
||||||
|
Platform,
|
||||||
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
@ -101,7 +106,9 @@ async def async_setup_entry(
|
|||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
FibaroThermostat(device)
|
FibaroThermostat(device)
|
||||||
for device in hass.data[DOMAIN][entry.entry_id][FIBARO_DEVICES]["climate"]
|
for device in hass.data[DOMAIN][entry.entry_id][FIBARO_DEVICES][
|
||||||
|
Platform.CLIMATE
|
||||||
|
]
|
||||||
],
|
],
|
||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
|
@ -8,6 +8,7 @@ from homeassistant.components.cover import (
|
|||||||
CoverEntity,
|
CoverEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
@ -24,7 +25,9 @@ async def async_setup_entry(
|
|||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
FibaroCover(device)
|
FibaroCover(device)
|
||||||
for device in hass.data[DOMAIN][entry.entry_id][FIBARO_DEVICES]["cover"]
|
for device in hass.data[DOMAIN][entry.entry_id][FIBARO_DEVICES][
|
||||||
|
Platform.COVER
|
||||||
|
]
|
||||||
],
|
],
|
||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
|
@ -16,6 +16,7 @@ from homeassistant.components.light import (
|
|||||||
color_supported,
|
color_supported,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
@ -53,7 +54,9 @@ async def async_setup_entry(
|
|||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
FibaroLight(device)
|
FibaroLight(device)
|
||||||
for device in hass.data[DOMAIN][entry.entry_id][FIBARO_DEVICES]["light"]
|
for device in hass.data[DOMAIN][entry.entry_id][FIBARO_DEVICES][
|
||||||
|
Platform.LIGHT
|
||||||
|
]
|
||||||
],
|
],
|
||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from homeassistant.components.lock import ENTITY_ID_FORMAT, LockEntity
|
from homeassistant.components.lock import ENTITY_ID_FORMAT, LockEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
@ -19,7 +20,9 @@ async def async_setup_entry(
|
|||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
FibaroLock(device)
|
FibaroLock(device)
|
||||||
for device in hass.data[DOMAIN][entry.entry_id][FIBARO_DEVICES]["lock"]
|
for device in hass.data[DOMAIN][entry.entry_id][FIBARO_DEVICES][
|
||||||
|
Platform.LOCK
|
||||||
|
]
|
||||||
],
|
],
|
||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
|
@ -5,6 +5,7 @@ from typing import Any
|
|||||||
|
|
||||||
from homeassistant.components.scene import Scene
|
from homeassistant.components.scene import Scene
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
@ -21,7 +22,9 @@ async def async_setup_entry(
|
|||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
FibaroScene(scene)
|
FibaroScene(scene)
|
||||||
for scene in hass.data[DOMAIN][entry.entry_id][FIBARO_DEVICES]["scene"]
|
for scene in hass.data[DOMAIN][entry.entry_id][FIBARO_DEVICES][
|
||||||
|
Platform.SCENE
|
||||||
|
]
|
||||||
],
|
],
|
||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
|
@ -18,6 +18,7 @@ from homeassistant.const import (
|
|||||||
POWER_WATT,
|
POWER_WATT,
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
TEMP_FAHRENHEIT,
|
TEMP_FAHRENHEIT,
|
||||||
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
@ -63,10 +64,10 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Fibaro controller devices."""
|
"""Set up the Fibaro controller devices."""
|
||||||
entities: list[SensorEntity] = []
|
entities: list[SensorEntity] = []
|
||||||
for device in hass.data[DOMAIN][entry.entry_id][FIBARO_DEVICES]["sensor"]:
|
for device in hass.data[DOMAIN][entry.entry_id][FIBARO_DEVICES][Platform.SENSOR]:
|
||||||
entities.append(FibaroSensor(device))
|
entities.append(FibaroSensor(device))
|
||||||
for device_type in ("cover", "light", "switch"):
|
for platform in (Platform.COVER, Platform.LIGHT, Platform.SWITCH):
|
||||||
for device in hass.data[DOMAIN][entry.entry_id][FIBARO_DEVICES][device_type]:
|
for device in hass.data[DOMAIN][entry.entry_id][FIBARO_DEVICES][platform]:
|
||||||
if "energy" in device.interfaces:
|
if "energy" in device.interfaces:
|
||||||
entities.append(FibaroEnergySensor(device))
|
entities.append(FibaroEnergySensor(device))
|
||||||
if "power" in device.interfaces:
|
if "power" in device.interfaces:
|
||||||
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from homeassistant.components.switch import ENTITY_ID_FORMAT, SwitchEntity
|
from homeassistant.components.switch import ENTITY_ID_FORMAT, SwitchEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
@ -19,7 +20,9 @@ async def async_setup_entry(
|
|||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
FibaroSwitch(device)
|
FibaroSwitch(device)
|
||||||
for device in hass.data[DOMAIN][entry.entry_id][FIBARO_DEVICES]["switch"]
|
for device in hass.data[DOMAIN][entry.entry_id][FIBARO_DEVICES][
|
||||||
|
Platform.SWITCH
|
||||||
|
]
|
||||||
],
|
],
|
||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user