Refactor Freebox Home categories (#99224)

This commit is contained in:
Quentame 2023-08-29 12:43:22 +02:00 committed by GitHub
parent 62b1211dee
commit 750cfeb76a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 17 deletions

View file

@ -12,13 +12,13 @@ from homeassistant.components.ffmpeg.camera import (
FFmpegCamera,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_NAME, Platform
from homeassistant.const import CONF_NAME
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import entity_platform
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import ATTR_DETECTION, DOMAIN
from .const import ATTR_DETECTION, DOMAIN, FreeboxHomeCategory
from .home_base import FreeboxHomeEntity
from .router import FreeboxRouter
@ -50,7 +50,7 @@ def add_entities(hass: HomeAssistant, router, async_add_entities, tracked):
new_tracked = []
for nodeid, node in router.home_devices.items():
if (node["category"] != Platform.CAMERA) or (nodeid in tracked):
if (node["category"] != FreeboxHomeCategory.CAMERA) or (nodeid in tracked):
continue
new_tracked.append(FreeboxCamera(hass, router, node))
tracked.add(nodeid)

View file

@ -1,6 +1,7 @@
"""Freebox component constants."""
from __future__ import annotations
import enum
import socket
from homeassistant.const import Platform
@ -58,16 +59,30 @@ DEVICE_ICONS = {
ATTR_DETECTION = "detection"
# Home
class FreeboxHomeCategory(enum.StrEnum):
"""Freebox Home categories."""
ALARM = "alarm"
CAMERA = "camera"
DWS = "dws"
IOHOME = "iohome"
KFB = "kfb"
OPENER = "opener"
PIR = "pir"
RTS = "rts"
CATEGORY_TO_MODEL = {
"pir": "F-HAPIR01A",
"camera": "F-HACAM01A",
"dws": "F-HADWS01A",
"kfb": "F-HAKFB01A",
"alarm": "F-MSEC07A",
"rts": "RTS",
"iohome": "IOHome",
FreeboxHomeCategory.PIR: "F-HAPIR01A",
FreeboxHomeCategory.CAMERA: "F-HACAM01A",
FreeboxHomeCategory.DWS: "F-HADWS01A",
FreeboxHomeCategory.KFB: "F-HAKFB01A",
FreeboxHomeCategory.ALARM: "F-MSEC07A",
FreeboxHomeCategory.RTS: "RTS",
FreeboxHomeCategory.IOHOME: "IOHome",
}
HOME_COMPATIBLE_PLATFORMS = [
Platform.CAMERA,
HOME_COMPATIBLE_CATEGORIES = [
FreeboxHomeCategory.CAMERA,
]

View file

@ -9,7 +9,7 @@ from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import Entity
from .const import CATEGORY_TO_MODEL, DOMAIN
from .const import CATEGORY_TO_MODEL, DOMAIN, FreeboxHomeCategory
from .router import FreeboxRouter
_LOGGER = logging.getLogger(__name__)
@ -48,10 +48,10 @@ class FreeboxHomeEntity(Entity):
if self._model is None:
if node["type"].get("inherit") == "node::rts":
self._manufacturer = "Somfy"
self._model = CATEGORY_TO_MODEL.get("rts")
self._model = CATEGORY_TO_MODEL[FreeboxHomeCategory.RTS]
elif node["type"].get("inherit") == "node::ios":
self._manufacturer = "Somfy"
self._model = CATEGORY_TO_MODEL.get("iohome")
self._model = CATEGORY_TO_MODEL[FreeboxHomeCategory.IOHOME]
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self._id)},

View file

@ -28,7 +28,7 @@ from .const import (
APP_DESC,
CONNECTION_SENSORS_KEYS,
DOMAIN,
HOME_COMPATIBLE_PLATFORMS,
HOME_COMPATIBLE_CATEGORIES,
STORAGE_KEY,
STORAGE_VERSION,
)
@ -190,7 +190,7 @@ class FreeboxRouter:
new_device = False
for home_node in home_nodes:
if home_node["category"] in HOME_COMPATIBLE_PLATFORMS:
if home_node["category"] in HOME_COMPATIBLE_CATEGORIES:
if self.home_devices.get(home_node["id"]) is None:
new_device = True
self.home_devices[home_node["id"]] = home_node