Use enum sensor device class in HomeKit Controller (#83109)
This commit is contained in:
parent
46500beefc
commit
a4a80f367b
5 changed files with 92 additions and 26 deletions
|
@ -3,7 +3,6 @@ from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import logging
|
|
||||||
|
|
||||||
from aiohomekit.model import Accessory, Transport
|
from aiohomekit.model import Accessory, Transport
|
||||||
from aiohomekit.model.characteristics import Characteristic, CharacteristicsTypes
|
from aiohomekit.model.characteristics import Characteristic, CharacteristicsTypes
|
||||||
|
@ -46,8 +45,6 @@ from .connection import HKDevice
|
||||||
from .entity import CharacteristicEntity, HomeKitEntity
|
from .entity import CharacteristicEntity, HomeKitEntity
|
||||||
from .utils import folded_name
|
from .utils import folded_name
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class HomeKitSensorEntityDescription(SensorEntityDescription):
|
class HomeKitSensorEntityDescription(SensorEntityDescription):
|
||||||
|
@ -299,16 +296,35 @@ SIMPLE_SENSOR: dict[str, HomeKitSensorEntityDescription] = {
|
||||||
CharacteristicsTypes.THREAD_NODE_CAPABILITIES: HomeKitSensorEntityDescription(
|
CharacteristicsTypes.THREAD_NODE_CAPABILITIES: HomeKitSensorEntityDescription(
|
||||||
key=CharacteristicsTypes.THREAD_NODE_CAPABILITIES,
|
key=CharacteristicsTypes.THREAD_NODE_CAPABILITIES,
|
||||||
name="Thread Capabilities",
|
name="Thread Capabilities",
|
||||||
device_class="homekit_controller__thread_node_capabilities",
|
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
format=thread_node_capability_to_str,
|
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(
|
CharacteristicsTypes.THREAD_STATUS: HomeKitSensorEntityDescription(
|
||||||
key=CharacteristicsTypes.THREAD_STATUS,
|
key=CharacteristicsTypes.THREAD_STATUS,
|
||||||
name="Thread Status",
|
name="Thread Status",
|
||||||
device_class="homekit_controller__thread_status",
|
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
format=thread_status_to_str,
|
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(
|
CharacteristicsTypes.VENDOR_NETATMO_NOISE: HomeKitSensorEntityDescription(
|
||||||
key=CharacteristicsTypes.VENDOR_NETATMO_NOISE,
|
key=CharacteristicsTypes.VENDOR_NETATMO_NOISE,
|
||||||
|
|
|
@ -69,5 +69,30 @@
|
||||||
"button9": "Button 9",
|
"button9": "Button 9",
|
||||||
"button10": "Button 10"
|
"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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -69,5 +69,30 @@
|
||||||
"single_press": "\"{subtype}\" pressed"
|
"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"
|
"title": "HomeKit Controller"
|
||||||
}
|
}
|
|
@ -57,6 +57,16 @@ async def test_nanoleaf_nl55_setup(hass):
|
||||||
friendly_name="Nanoleaf Strip 3B32 Thread Capabilities",
|
friendly_name="Nanoleaf Strip 3B32 Thread Capabilities",
|
||||||
unique_id="00:00:00:00:00:00_1_31_115",
|
unique_id="00:00:00:00:00:00_1_31_115",
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
capabilities={
|
||||||
|
"options": [
|
||||||
|
"border_router_capable",
|
||||||
|
"full",
|
||||||
|
"minimal",
|
||||||
|
"none",
|
||||||
|
"router_eligible",
|
||||||
|
"sleepy",
|
||||||
|
]
|
||||||
|
},
|
||||||
state="border_router_capable",
|
state="border_router_capable",
|
||||||
),
|
),
|
||||||
EntityTestInfo(
|
EntityTestInfo(
|
||||||
|
@ -64,6 +74,17 @@ async def test_nanoleaf_nl55_setup(hass):
|
||||||
friendly_name="Nanoleaf Strip 3B32 Thread Status",
|
friendly_name="Nanoleaf Strip 3B32 Thread Status",
|
||||||
unique_id="00:00:00:00:00:00_1_31_117",
|
unique_id="00:00:00:00:00:00_1_31_117",
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
capabilities={
|
||||||
|
"options": [
|
||||||
|
"border_router",
|
||||||
|
"child",
|
||||||
|
"detached",
|
||||||
|
"disabled",
|
||||||
|
"joining",
|
||||||
|
"leader",
|
||||||
|
"router",
|
||||||
|
]
|
||||||
|
},
|
||||||
state="border_router",
|
state="border_router",
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
Loading…
Add table
Reference in a new issue