Add support for air purifiers to HomeKit Device (#109880)
This commit is contained in:
parent
aea81a180c
commit
1ea9b1a158
6 changed files with 192 additions and 5 deletions
|
@ -3,10 +3,15 @@ from __future__ import annotations
|
|||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from enum import IntEnum
|
||||
|
||||
from aiohomekit.model import Accessory, Transport
|
||||
from aiohomekit.model.characteristics import Characteristic, CharacteristicsTypes
|
||||
from aiohomekit.model.characteristics.const import ThreadNodeCapabilities, ThreadStatus
|
||||
from aiohomekit.model.characteristics.const import (
|
||||
CurrentAirPurifierStateValues,
|
||||
ThreadNodeCapabilities,
|
||||
ThreadStatus,
|
||||
)
|
||||
from aiohomekit.model.services import Service, ServicesTypes
|
||||
|
||||
from homeassistant.components.bluetooth import (
|
||||
|
@ -52,6 +57,7 @@ class HomeKitSensorEntityDescription(SensorEntityDescription):
|
|||
|
||||
probe: Callable[[Characteristic], bool] | None = None
|
||||
format: Callable[[Characteristic], str] | None = None
|
||||
enum: dict[IntEnum, str] | None = None
|
||||
|
||||
|
||||
def thread_node_capability_to_str(char: Characteristic) -> str:
|
||||
|
@ -324,6 +330,18 @@ SIMPLE_SENSOR: dict[str, HomeKitSensorEntityDescription] = {
|
|||
],
|
||||
translation_key="thread_status",
|
||||
),
|
||||
CharacteristicsTypes.AIR_PURIFIER_STATE_CURRENT: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.AIR_PURIFIER_STATE_CURRENT,
|
||||
name="Air Purifier Status",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
device_class=SensorDeviceClass.ENUM,
|
||||
enum={
|
||||
CurrentAirPurifierStateValues.INACTIVE: "inactive",
|
||||
CurrentAirPurifierStateValues.IDLE: "idle",
|
||||
CurrentAirPurifierStateValues.ACTIVE: "purifying",
|
||||
},
|
||||
translation_key="air_purifier_state_current",
|
||||
),
|
||||
CharacteristicsTypes.VENDOR_NETATMO_NOISE: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_NETATMO_NOISE,
|
||||
name="Noise",
|
||||
|
@ -535,6 +553,8 @@ class SimpleSensor(CharacteristicEntity, SensorEntity):
|
|||
) -> None:
|
||||
"""Initialise a secondary HomeKit characteristic sensor."""
|
||||
self.entity_description = description
|
||||
if self.entity_description.enum:
|
||||
self._attr_options = list(self.entity_description.enum.values())
|
||||
super().__init__(conn, info, char)
|
||||
|
||||
def get_characteristic_types(self) -> list[str]:
|
||||
|
@ -551,10 +571,11 @@ class SimpleSensor(CharacteristicEntity, SensorEntity):
|
|||
@property
|
||||
def native_value(self) -> str | int | float:
|
||||
"""Return the current sensor value."""
|
||||
val = self._char.value
|
||||
if self.entity_description.enum:
|
||||
return self.entity_description.enum[self._char.value]
|
||||
if self.entity_description.format:
|
||||
return self.entity_description.format(val)
|
||||
return val
|
||||
return self.entity_description.format(self._char)
|
||||
return self._char.value
|
||||
|
||||
|
||||
ENTITY_TYPES = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue