From a4a80f367b08befba857f83fb45c43cdb890c298 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Fri, 2 Dec 2022 14:50:01 +0100 Subject: [PATCH] Use enum sensor device class in HomeKit Controller (#83109) --- .../components/homekit_controller/sensor.py | 26 +++++++++++++++---- .../homekit_controller/strings.json | 25 ++++++++++++++++++ .../homekit_controller/strings.sensor.json | 21 --------------- .../homekit_controller/translations/en.json | 25 ++++++++++++++++++ .../test_nanoleaf_strip_nl55.py | 21 +++++++++++++++ 5 files changed, 92 insertions(+), 26 deletions(-) delete mode 100644 homeassistant/components/homekit_controller/strings.sensor.json diff --git a/homeassistant/components/homekit_controller/sensor.py b/homeassistant/components/homekit_controller/sensor.py index 49047b28eae..de59a70ddaf 100644 --- a/homeassistant/components/homekit_controller/sensor.py +++ b/homeassistant/components/homekit_controller/sensor.py @@ -3,7 +3,6 @@ from __future__ import annotations from collections.abc import Callable from dataclasses import dataclass -import logging from aiohomekit.model import Accessory, Transport from aiohomekit.model.characteristics import Characteristic, CharacteristicsTypes @@ -46,8 +45,6 @@ from .connection import HKDevice from .entity import CharacteristicEntity, HomeKitEntity from .utils import folded_name -_LOGGER = logging.getLogger(__name__) - @dataclass class HomeKitSensorEntityDescription(SensorEntityDescription): @@ -299,16 +296,35 @@ SIMPLE_SENSOR: dict[str, HomeKitSensorEntityDescription] = { CharacteristicsTypes.THREAD_NODE_CAPABILITIES: HomeKitSensorEntityDescription( key=CharacteristicsTypes.THREAD_NODE_CAPABILITIES, name="Thread Capabilities", - device_class="homekit_controller__thread_node_capabilities", entity_category=EntityCategory.DIAGNOSTIC, format=thread_node_capability_to_str, + device_class=SensorDeviceClass.ENUM, + options=[ + "border_router_capable", + "full", + "minimal", + "none", + "router_eligible", + "sleepy", + ], + translation_key="thread_node_capabilities", ), CharacteristicsTypes.THREAD_STATUS: HomeKitSensorEntityDescription( key=CharacteristicsTypes.THREAD_STATUS, name="Thread Status", - device_class="homekit_controller__thread_status", entity_category=EntityCategory.DIAGNOSTIC, format=thread_status_to_str, + device_class=SensorDeviceClass.ENUM, + options=[ + "border_router", + "child", + "detached", + "disabled", + "joining", + "leader", + "router", + ], + translation_key="thread_status", ), CharacteristicsTypes.VENDOR_NETATMO_NOISE: HomeKitSensorEntityDescription( key=CharacteristicsTypes.VENDOR_NETATMO_NOISE, diff --git a/homeassistant/components/homekit_controller/strings.json b/homeassistant/components/homekit_controller/strings.json index 201e0a9b3c2..8b651309bdf 100644 --- a/homeassistant/components/homekit_controller/strings.json +++ b/homeassistant/components/homekit_controller/strings.json @@ -69,5 +69,30 @@ "button9": "Button 9", "button10": "Button 10" } + }, + "entity": { + "sensor": { + "thread_node_capabilities": { + "state": { + "border_router_capable": "Border Router Capable", + "full": "Full End Device", + "minimal": "Minimal End Device", + "none": "None", + "router_eligible": "Router Eligible End Device", + "sleepy": "Sleepy End Device" + } + }, + "thread_status": { + "state": { + "border_router": "Border Router", + "child": "Child", + "detached": "Detached", + "disabled": "Disabled", + "joining": "Joining", + "leader": "Leader", + "router": "Router" + } + } + } } } diff --git a/homeassistant/components/homekit_controller/strings.sensor.json b/homeassistant/components/homekit_controller/strings.sensor.json deleted file mode 100644 index ceede708572..00000000000 --- a/homeassistant/components/homekit_controller/strings.sensor.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "state": { - "homekit_controller__thread_node_capabilities": { - "border_router_capable": "Border Router Capable", - "router_eligible": "Router Eligible End Device", - "full": "Full End Device", - "minimal": "Minimal End Device", - "sleepy": "Sleepy End Device", - "none": "None" - }, - "homekit_controller__thread_status": { - "border_router": "Border Router", - "leader": "Leader", - "router": "Router", - "child": "Child", - "joining": "Joining", - "detached": "Detached", - "disabled": "Disabled" - } - } -} diff --git a/homeassistant/components/homekit_controller/translations/en.json b/homeassistant/components/homekit_controller/translations/en.json index c5b5178a58b..991177dbdf3 100644 --- a/homeassistant/components/homekit_controller/translations/en.json +++ b/homeassistant/components/homekit_controller/translations/en.json @@ -69,5 +69,30 @@ "single_press": "\"{subtype}\" pressed" } }, + "entity": { + "sensor": { + "thread_node_capabilities": { + "state": { + "border_router_capable": "Border Router Capable", + "full": "Full End Device", + "minimal": "Minimal End Device", + "none": "None", + "router_eligible": "Router Eligible End Device", + "sleepy": "Sleepy End Device" + } + }, + "thread_status": { + "state": { + "border_router": "Border Router", + "child": "Child", + "detached": "Detached", + "disabled": "Disabled", + "joining": "Joining", + "leader": "Leader", + "router": "Router" + } + } + } + }, "title": "HomeKit Controller" } \ No newline at end of file diff --git a/tests/components/homekit_controller/specific_devices/test_nanoleaf_strip_nl55.py b/tests/components/homekit_controller/specific_devices/test_nanoleaf_strip_nl55.py index 4afb61b19f3..2bbd6bf3a10 100644 --- a/tests/components/homekit_controller/specific_devices/test_nanoleaf_strip_nl55.py +++ b/tests/components/homekit_controller/specific_devices/test_nanoleaf_strip_nl55.py @@ -57,6 +57,16 @@ async def test_nanoleaf_nl55_setup(hass): friendly_name="Nanoleaf Strip 3B32 Thread Capabilities", unique_id="00:00:00:00:00:00_1_31_115", entity_category=EntityCategory.DIAGNOSTIC, + capabilities={ + "options": [ + "border_router_capable", + "full", + "minimal", + "none", + "router_eligible", + "sleepy", + ] + }, state="border_router_capable", ), EntityTestInfo( @@ -64,6 +74,17 @@ async def test_nanoleaf_nl55_setup(hass): friendly_name="Nanoleaf Strip 3B32 Thread Status", unique_id="00:00:00:00:00:00_1_31_117", entity_category=EntityCategory.DIAGNOSTIC, + capabilities={ + "options": [ + "border_router", + "child", + "detached", + "disabled", + "joining", + "leader", + "router", + ] + }, state="border_router", ), ],