1 """Support for Homekit number ranges.
3 These are mostly used where a HomeKit accessory exposes additional non-standard
4 characteristics that don't map to a Home Assistant feature.
7 from __future__
import annotations
9 from aiohomekit.model.characteristics
import Characteristic, CharacteristicsTypes
16 NumberEntityDescription,
24 from .
import KNOWN_DEVICES
25 from .connection
import HKDevice
26 from .entity
import CharacteristicEntity
28 NUMBER_ENTITIES: dict[str, NumberEntityDescription] = {
30 key=CharacteristicsTypes.VENDOR_VOCOLINC_HUMIDIFIER_SPRAY_LEVEL,
31 name=
"Spray Quantity",
32 translation_key=
"spray_quantity",
33 entity_category=EntityCategory.CONFIG,
36 key=CharacteristicsTypes.VENDOR_EVE_DEGREE_ELEVATION,
38 translation_key=
"elevation",
39 entity_category=EntityCategory.CONFIG,
42 key=CharacteristicsTypes.VENDOR_AQARA_GATEWAY_VOLUME,
44 translation_key=
"volume",
45 entity_category=EntityCategory.CONFIG,
48 key=CharacteristicsTypes.VENDOR_AQARA_E1_GATEWAY_VOLUME,
50 translation_key=
"volume",
51 entity_category=EntityCategory.CONFIG,
54 key=CharacteristicsTypes.VENDOR_EVE_MOTION_DURATION,
56 translation_key=
"duration",
57 entity_category=EntityCategory.CONFIG,
60 key=CharacteristicsTypes.VENDOR_EVE_MOTION_SENSITIVITY,
62 translation_key=
"sensitivity",
63 entity_category=EntityCategory.CONFIG,
70 config_entry: ConfigEntry,
71 async_add_entities: AddEntitiesCallback,
73 """Set up Homekit numbers."""
74 hkid: str = config_entry.data[
"AccessoryPairingID"]
75 conn: HKDevice = hass.data[KNOWN_DEVICES][hkid]
79 entities: list[HomeKitNumber] = []
80 info = {
"aid": char.service.accessory.aid,
"iid": char.service.iid}
82 if description := NUMBER_ENTITIES.get(char.type):
87 for entity
in entities:
88 conn.async_migrate_unique_id(
89 entity.old_unique_id, entity.unique_id, Platform.NUMBER
95 conn.add_char_factory(async_add_characteristic)
99 """Representation of a Number control on a homekit accessory."""
105 char: Characteristic,
106 description: NumberEntityDescription,
108 """Initialise a HomeKit number control."""
114 """Return the name of the device if any."""
116 return f
"{name} {self.entity_description.name}"
117 return f
"{self.entity_description.name}"
120 """Define the homekit characteristics the entity is tracking."""
121 return [self.
_char_char.type]
125 """Return the minimum value."""
126 return self.
_char_char.minValue
or DEFAULT_MIN_VALUE
130 """Return the maximum value."""
131 return self.
_char_char.maxValue
or DEFAULT_MAX_VALUE
135 """Return the increment/decrement step."""
136 return self.
_char_char.minStep
or DEFAULT_STEP
140 """Return the current characteristic value."""
141 return self.
_char_char.value
144 """Set the characteristic to this value."""
147 self.
_char_char.type: value,
None async_put_characteristics(self, dict[str, Any] characteristics)
float native_max_value(self)
None async_set_native_value(self, float value)
float native_min_value(self)
list[str] get_characteristic_types(self)
None __init__(self, HKDevice conn, ConfigType info, Characteristic char, NumberEntityDescription description)
bool async_add_characteristic(Characteristic char)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)