diff --git a/homeassistant/components/homekit_controller/button.py b/homeassistant/components/homekit_controller/button.py index ff61c632be9..876ac43590d 100644 --- a/homeassistant/components/homekit_controller/button.py +++ b/homeassistant/components/homekit_controller/button.py @@ -32,6 +32,10 @@ _LOGGER = logging.getLogger(__name__) class HomeKitButtonEntityDescription(ButtonEntityDescription): """Describes Homekit button.""" + # HomeKitButton does not support UNDEFINED or None, + # restrict the type to str. + name: str = "" + write_value: int | str | None = None @@ -116,7 +120,7 @@ class HomeKitButton(CharacteristicEntity, ButtonEntity): """Return the name of the device if any.""" if name := self.accessory.name: return f"{name} {self.entity_description.name}" - return f"{self.entity_description.name}" + return self.entity_description.name async def async_press(self) -> None: """Press the button.""" diff --git a/homeassistant/components/homekit_controller/number.py b/homeassistant/components/homekit_controller/number.py index b44aed16143..71f6d00287a 100644 --- a/homeassistant/components/homekit_controller/number.py +++ b/homeassistant/components/homekit_controller/number.py @@ -5,6 +5,8 @@ characteristics that don't map to a Home Assistant feature. """ from __future__ import annotations +from dataclasses import dataclass + from aiohomekit.model.characteristics import Characteristic, CharacteristicsTypes from homeassistant.components.number import ( @@ -24,26 +26,36 @@ from . import KNOWN_DEVICES from .connection import HKDevice from .entity import CharacteristicEntity -NUMBER_ENTITIES: dict[str, NumberEntityDescription] = { - CharacteristicsTypes.VENDOR_VOCOLINC_HUMIDIFIER_SPRAY_LEVEL: NumberEntityDescription( + +@dataclass +class HomeKitNumberEntityDescription(NumberEntityDescription): + """Describes Homekit number.""" + + # HomeKitNumber does not support UNDEFINED or None, + # restrict the type to str. + name: str = "" + + +NUMBER_ENTITIES: dict[str, HomeKitNumberEntityDescription] = { + CharacteristicsTypes.VENDOR_VOCOLINC_HUMIDIFIER_SPRAY_LEVEL: HomeKitNumberEntityDescription( key=CharacteristicsTypes.VENDOR_VOCOLINC_HUMIDIFIER_SPRAY_LEVEL, name="Spray Quantity", icon="mdi:water", entity_category=EntityCategory.CONFIG, ), - CharacteristicsTypes.VENDOR_EVE_DEGREE_ELEVATION: NumberEntityDescription( + CharacteristicsTypes.VENDOR_EVE_DEGREE_ELEVATION: HomeKitNumberEntityDescription( key=CharacteristicsTypes.VENDOR_EVE_DEGREE_ELEVATION, name="Elevation", icon="mdi:elevation-rise", entity_category=EntityCategory.CONFIG, ), - CharacteristicsTypes.VENDOR_AQARA_GATEWAY_VOLUME: NumberEntityDescription( + CharacteristicsTypes.VENDOR_AQARA_GATEWAY_VOLUME: HomeKitNumberEntityDescription( key=CharacteristicsTypes.VENDOR_AQARA_GATEWAY_VOLUME, name="Volume", icon="mdi:volume-high", entity_category=EntityCategory.CONFIG, ), - CharacteristicsTypes.VENDOR_AQARA_E1_GATEWAY_VOLUME: NumberEntityDescription( + CharacteristicsTypes.VENDOR_AQARA_E1_GATEWAY_VOLUME: HomeKitNumberEntityDescription( key=CharacteristicsTypes.VENDOR_AQARA_E1_GATEWAY_VOLUME, name="Volume", icon="mdi:volume-high", @@ -85,12 +97,14 @@ async def async_setup_entry( class HomeKitNumber(CharacteristicEntity, NumberEntity): """Representation of a Number control on a homekit accessory.""" + entity_description: HomeKitNumberEntityDescription + def __init__( self, conn: HKDevice, info: ConfigType, char: Characteristic, - description: NumberEntityDescription, + description: HomeKitNumberEntityDescription, ) -> None: """Initialise a HomeKit number control.""" self.entity_description = description @@ -101,7 +115,7 @@ class HomeKitNumber(CharacteristicEntity, NumberEntity): """Return the name of the device if any.""" if name := self.accessory.name: return f"{name} {self.entity_description.name}" - return f"{self.entity_description.name}" + return self.entity_description.name def get_characteristic_types(self) -> list[str]: """Define the homekit characteristics the entity is tracking.""" diff --git a/homeassistant/components/homekit_controller/sensor.py b/homeassistant/components/homekit_controller/sensor.py index 4d6ad7148d2..6cb166a5dcc 100644 --- a/homeassistant/components/homekit_controller/sensor.py +++ b/homeassistant/components/homekit_controller/sensor.py @@ -50,6 +50,10 @@ from .utils import folded_name class HomeKitSensorEntityDescription(SensorEntityDescription): """Describes Homekit sensor.""" + # SimpleSensor does not support UNDEFINED or None, + # restrict the type to str. + name: str = "" + probe: Callable[[Characteristic], bool] | None = None format: Callable[[Characteristic], str] | None = None @@ -536,7 +540,7 @@ class SimpleSensor(CharacteristicEntity, SensorEntity): """Return the name of the device if any.""" if name := self.accessory.name: return f"{name} {self.entity_description.name}" - return f"{self.entity_description.name}" + return self.entity_description.name @property def native_value(self) -> str | int | float: diff --git a/homeassistant/components/homekit_controller/switch.py b/homeassistant/components/homekit_controller/switch.py index 15a7aca4a5d..9df8471b31b 100644 --- a/homeassistant/components/homekit_controller/switch.py +++ b/homeassistant/components/homekit_controller/switch.py @@ -34,6 +34,10 @@ ATTR_REMAINING_DURATION = "remaining_duration" class DeclarativeSwitchEntityDescription(SwitchEntityDescription): """Describes Homekit button.""" + # DeclarativeCharacteristicSwitch does not support UNDEFINED or None, + # restrict the type to str. + name: str = "" + true_value: bool = True false_value: bool = False @@ -170,7 +174,7 @@ class DeclarativeCharacteristicSwitch(CharacteristicEntity, SwitchEntity): """Return the name of the device if any.""" if name := self.accessory.name: return f"{name} {self.entity_description.name}" - return f"{self.entity_description.name}" + return self.entity_description.name def get_characteristic_types(self) -> list[str]: """Define the homekit characteristics the entity cares about."""