Refactor homekit_controller to prepare for more typing information (#65329)
This commit is contained in:
parent
a9af29cbe0
commit
0f88790303
28 changed files with 139 additions and 179 deletions
|
@ -51,7 +51,7 @@ async def async_setup_entry(
|
|||
|
||||
@callback
|
||||
def async_add_service(service):
|
||||
if service.short_type != ServicesTypes.SECURITY_SYSTEM:
|
||||
if service.type != ServicesTypes.SECURITY_SYSTEM:
|
||||
return False
|
||||
info = {"aid": service.accessory.aid, "iid": service.iid}
|
||||
async_add_entities([HomeKitAlarmControlPanelEntity(conn, info)], True)
|
||||
|
|
|
@ -124,7 +124,7 @@ async def async_setup_entry(
|
|||
|
||||
@callback
|
||||
def async_add_service(service):
|
||||
if not (entity_class := ENTITY_TYPES.get(service.short_type)):
|
||||
if not (entity_class := ENTITY_TYPES.get(service.type)):
|
||||
return False
|
||||
info = {"aid": service.accessory.aid, "iid": service.iid}
|
||||
async_add_entities([entity_class(conn, info)], True)
|
||||
|
|
|
@ -31,15 +31,15 @@ class HomeKitButtonEntityDescription(ButtonEntityDescription):
|
|||
|
||||
|
||||
BUTTON_ENTITIES: dict[str, HomeKitButtonEntityDescription] = {
|
||||
CharacteristicsTypes.Vendor.HAA_SETUP: HomeKitButtonEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.HAA_SETUP,
|
||||
CharacteristicsTypes.VENDOR_HAA_SETUP: HomeKitButtonEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_HAA_SETUP,
|
||||
name="Setup",
|
||||
icon="mdi:cog",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
write_value="#HAA@trcmd",
|
||||
),
|
||||
CharacteristicsTypes.Vendor.HAA_UPDATE: HomeKitButtonEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.HAA_UPDATE,
|
||||
CharacteristicsTypes.VENDOR_HAA_UPDATE: HomeKitButtonEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_HAA_UPDATE,
|
||||
name="Update",
|
||||
device_class=ButtonDeviceClass.UPDATE,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
|
@ -54,16 +54,6 @@ BUTTON_ENTITIES: dict[str, HomeKitButtonEntityDescription] = {
|
|||
}
|
||||
|
||||
|
||||
# For legacy reasons, "built-in" characteristic types are in their short form
|
||||
# And vendor types don't have a short form
|
||||
# This means long and short forms get mixed up in this dict, and comparisons
|
||||
# don't work!
|
||||
# We call get_uuid on *every* type to normalise them to the long form
|
||||
# Eventually aiohomekit will use the long form exclusively amd this can be removed.
|
||||
for k, v in list(BUTTON_ENTITIES.items()):
|
||||
BUTTON_ENTITIES[CharacteristicsTypes.get_uuid(k)] = BUTTON_ENTITIES.pop(k)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
|
@ -155,5 +145,5 @@ class HomeKitEcobeeClearHoldButton(CharacteristicEntity, ButtonEntity):
|
|||
|
||||
|
||||
BUTTON_ENTITY_CLASSES: dict[str, type] = {
|
||||
CharacteristicsTypes.Vendor.ECOBEE_CLEAR_HOLD: HomeKitEcobeeClearHoldButton,
|
||||
CharacteristicsTypes.VENDOR_ECOBEE_CLEAR_HOLD: HomeKitEcobeeClearHoldButton,
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ async def async_setup_entry(
|
|||
|
||||
@callback
|
||||
def async_add_service(service):
|
||||
if not (entity_class := ENTITY_TYPES.get(service.short_type)):
|
||||
if not (entity_class := ENTITY_TYPES.get(service.type)):
|
||||
return False
|
||||
info = {"aid": service.accessory.aid, "iid": service.iid}
|
||||
async_add_entities([entity_class(conn, info)], True)
|
||||
|
|
|
@ -11,6 +11,7 @@ from aiohomekit.exceptions import (
|
|||
from aiohomekit.model import Accessories, Accessory
|
||||
from aiohomekit.model.characteristics import CharacteristicsTypes
|
||||
from aiohomekit.model.services import ServicesTypes
|
||||
from aiohomekit.uuid import normalize_uuid
|
||||
|
||||
from homeassistant.const import ATTR_VIA_DEVICE
|
||||
from homeassistant.core import callback
|
||||
|
@ -495,7 +496,7 @@ class HKDevice:
|
|||
for accessory in self.accessories:
|
||||
for service in accessory["services"]:
|
||||
try:
|
||||
stype = ServicesTypes.get_short_uuid(service["type"].upper())
|
||||
stype = normalize_uuid(service["type"])
|
||||
except KeyError:
|
||||
stype = service["type"].upper()
|
||||
|
||||
|
|
|
@ -51,33 +51,33 @@ HOMEKIT_ACCESSORY_DISPATCH = {
|
|||
}
|
||||
|
||||
CHARACTERISTIC_PLATFORMS = {
|
||||
CharacteristicsTypes.Vendor.CONNECTSENSE_ENERGY_WATT: "sensor",
|
||||
CharacteristicsTypes.Vendor.CONNECTSENSE_ENERGY_AMPS: "sensor",
|
||||
CharacteristicsTypes.Vendor.CONNECTSENSE_ENERGY_AMPS_20: "sensor",
|
||||
CharacteristicsTypes.Vendor.CONNECTSENSE_ENERGY_KW_HOUR: "sensor",
|
||||
CharacteristicsTypes.Vendor.AQARA_GATEWAY_VOLUME: "number",
|
||||
CharacteristicsTypes.Vendor.AQARA_E1_GATEWAY_VOLUME: "number",
|
||||
CharacteristicsTypes.Vendor.AQARA_PAIRING_MODE: "switch",
|
||||
CharacteristicsTypes.Vendor.AQARA_E1_PAIRING_MODE: "switch",
|
||||
CharacteristicsTypes.Vendor.ECOBEE_HOME_TARGET_COOL: "number",
|
||||
CharacteristicsTypes.Vendor.ECOBEE_HOME_TARGET_HEAT: "number",
|
||||
CharacteristicsTypes.Vendor.ECOBEE_SLEEP_TARGET_COOL: "number",
|
||||
CharacteristicsTypes.Vendor.ECOBEE_SLEEP_TARGET_HEAT: "number",
|
||||
CharacteristicsTypes.Vendor.ECOBEE_AWAY_TARGET_COOL: "number",
|
||||
CharacteristicsTypes.Vendor.ECOBEE_AWAY_TARGET_HEAT: "number",
|
||||
CharacteristicsTypes.Vendor.ECOBEE_CURRENT_MODE: "select",
|
||||
CharacteristicsTypes.Vendor.EVE_ENERGY_WATT: "sensor",
|
||||
CharacteristicsTypes.Vendor.EVE_DEGREE_AIR_PRESSURE: "sensor",
|
||||
CharacteristicsTypes.Vendor.EVE_DEGREE_ELEVATION: "number",
|
||||
CharacteristicsTypes.Vendor.HAA_SETUP: "button",
|
||||
CharacteristicsTypes.Vendor.HAA_UPDATE: "button",
|
||||
CharacteristicsTypes.Vendor.KOOGEEK_REALTIME_ENERGY: "sensor",
|
||||
CharacteristicsTypes.Vendor.KOOGEEK_REALTIME_ENERGY_2: "sensor",
|
||||
CharacteristicsTypes.Vendor.VOCOLINC_HUMIDIFIER_SPRAY_LEVEL: "number",
|
||||
CharacteristicsTypes.Vendor.VOCOLINC_OUTLET_ENERGY: "sensor",
|
||||
CharacteristicsTypes.Vendor.ECOBEE_CLEAR_HOLD: "button",
|
||||
CharacteristicsTypes.Vendor.ECOBEE_FAN_WRITE_SPEED: "number",
|
||||
CharacteristicsTypes.Vendor.ECOBEE_SET_HOLD_SCHEDULE: "number",
|
||||
CharacteristicsTypes.VENDOR_CONNECTSENSE_ENERGY_WATT: "sensor",
|
||||
CharacteristicsTypes.VENDOR_CONNECTSENSE_ENERGY_AMPS: "sensor",
|
||||
CharacteristicsTypes.VENDOR_CONNECTSENSE_ENERGY_AMPS_20: "sensor",
|
||||
CharacteristicsTypes.VENDOR_CONNECTSENSE_ENERGY_KW_HOUR: "sensor",
|
||||
CharacteristicsTypes.VENDOR_AQARA_GATEWAY_VOLUME: "number",
|
||||
CharacteristicsTypes.VENDOR_AQARA_E1_GATEWAY_VOLUME: "number",
|
||||
CharacteristicsTypes.VENDOR_AQARA_PAIRING_MODE: "switch",
|
||||
CharacteristicsTypes.VENDOR_AQARA_E1_PAIRING_MODE: "switch",
|
||||
CharacteristicsTypes.VENDOR_ECOBEE_HOME_TARGET_COOL: "number",
|
||||
CharacteristicsTypes.VENDOR_ECOBEE_HOME_TARGET_HEAT: "number",
|
||||
CharacteristicsTypes.VENDOR_ECOBEE_SLEEP_TARGET_COOL: "number",
|
||||
CharacteristicsTypes.VENDOR_ECOBEE_SLEEP_TARGET_HEAT: "number",
|
||||
CharacteristicsTypes.VENDOR_ECOBEE_AWAY_TARGET_COOL: "number",
|
||||
CharacteristicsTypes.VENDOR_ECOBEE_AWAY_TARGET_HEAT: "number",
|
||||
CharacteristicsTypes.VENDOR_ECOBEE_CURRENT_MODE: "select",
|
||||
CharacteristicsTypes.VENDOR_EVE_ENERGY_WATT: "sensor",
|
||||
CharacteristicsTypes.VENDOR_EVE_DEGREE_AIR_PRESSURE: "sensor",
|
||||
CharacteristicsTypes.VENDOR_EVE_DEGREE_ELEVATION: "number",
|
||||
CharacteristicsTypes.VENDOR_HAA_SETUP: "button",
|
||||
CharacteristicsTypes.VENDOR_HAA_UPDATE: "button",
|
||||
CharacteristicsTypes.VENDOR_KOOGEEK_REALTIME_ENERGY: "sensor",
|
||||
CharacteristicsTypes.VENDOR_KOOGEEK_REALTIME_ENERGY_2: "sensor",
|
||||
CharacteristicsTypes.VENDOR_VOCOLINC_HUMIDIFIER_SPRAY_LEVEL: "number",
|
||||
CharacteristicsTypes.VENDOR_VOCOLINC_OUTLET_ENERGY: "sensor",
|
||||
CharacteristicsTypes.VENDOR_ECOBEE_CLEAR_HOLD: "button",
|
||||
CharacteristicsTypes.VENDOR_ECOBEE_FAN_WRITE_SPEED: "number",
|
||||
CharacteristicsTypes.VENDOR_ECOBEE_SET_HOLD_SCHEDULE: "number",
|
||||
CharacteristicsTypes.TEMPERATURE_CURRENT: "sensor",
|
||||
CharacteristicsTypes.RELATIVE_HUMIDITY_CURRENT: "sensor",
|
||||
CharacteristicsTypes.AIR_QUALITY: "sensor",
|
||||
|
@ -90,16 +90,6 @@ CHARACTERISTIC_PLATFORMS = {
|
|||
CharacteristicsTypes.IDENTIFY: "button",
|
||||
}
|
||||
|
||||
# For legacy reasons, "built-in" characteristic types are in their short form
|
||||
# And vendor types don't have a short form
|
||||
# This means long and short forms get mixed up in this dict, and comparisons
|
||||
# don't work!
|
||||
# We call get_uuid on *every* type to normalise them to the long form
|
||||
# Eventually aiohomekit will use the long form exclusively amd this can be removed.
|
||||
for k, v in list(CHARACTERISTIC_PLATFORMS.items()):
|
||||
value = CHARACTERISTIC_PLATFORMS.pop(k)
|
||||
CHARACTERISTIC_PLATFORMS[CharacteristicsTypes.get_uuid(k)] = value
|
||||
|
||||
|
||||
# Device classes
|
||||
DEVICE_CLASS_ECOBEE_MODE: Final = "homekit_controller__ecobee_mode"
|
||||
|
|
|
@ -47,7 +47,7 @@ async def async_setup_entry(
|
|||
|
||||
@callback
|
||||
def async_add_service(service):
|
||||
if not (entity_class := ENTITY_TYPES.get(service.short_type)):
|
||||
if not (entity_class := ENTITY_TYPES.get(service.type)):
|
||||
return False
|
||||
info = {"aid": service.accessory.aid, "iid": service.iid}
|
||||
async_add_entities([entity_class(conn, info)], True)
|
||||
|
|
|
@ -197,7 +197,7 @@ async def async_setup_triggers_for_entry(hass: HomeAssistant, config_entry):
|
|||
@callback
|
||||
def async_add_service(service):
|
||||
aid = service.accessory.aid
|
||||
service_type = service.short_type
|
||||
service_type = service.type
|
||||
|
||||
# If not a known service type then we can't handle any stateless events for it
|
||||
if service_type not in TRIGGER_FINDERS:
|
||||
|
|
|
@ -15,7 +15,7 @@ from .connection import HKDevice
|
|||
from .const import KNOWN_DEVICES
|
||||
|
||||
REDACTED_CHARACTERISTICS = [
|
||||
CharacteristicsTypes.get_uuid(CharacteristicsTypes.SERIAL_NUMBER),
|
||||
CharacteristicsTypes.SERIAL_NUMBER,
|
||||
]
|
||||
|
||||
REDACTED_CONFIG_ENTRY_KEYS = [
|
||||
|
@ -112,12 +112,7 @@ def _async_get_diagnostics(
|
|||
for accessory in accessories:
|
||||
for service in accessory.get("services", []):
|
||||
for char in service.get("characteristics", []):
|
||||
try:
|
||||
normalized = CharacteristicsTypes.get_uuid(char["type"])
|
||||
except KeyError:
|
||||
normalized = char["type"]
|
||||
|
||||
if normalized in REDACTED_CHARACTERISTICS:
|
||||
if char["type"] in REDACTED_CHARACTERISTICS:
|
||||
char["value"] = REDACTED
|
||||
|
||||
if device:
|
||||
|
|
|
@ -160,7 +160,7 @@ async def async_setup_entry(
|
|||
|
||||
@callback
|
||||
def async_add_service(service):
|
||||
if not (entity_class := ENTITY_TYPES.get(service.short_type)):
|
||||
if not (entity_class := ENTITY_TYPES.get(service.type)):
|
||||
return False
|
||||
info = {"aid": service.accessory.aid, "iid": service.iid}
|
||||
async_add_entities([entity_class(conn, info)], True)
|
||||
|
|
|
@ -252,7 +252,7 @@ async def async_setup_entry(
|
|||
|
||||
@callback
|
||||
def async_add_service(service):
|
||||
if service.short_type != ServicesTypes.HUMIDIFIER_DEHUMIDIFIER:
|
||||
if service.type != ServicesTypes.HUMIDIFIER_DEHUMIDIFIER:
|
||||
return False
|
||||
|
||||
info = {"aid": service.accessory.aid, "iid": service.iid}
|
||||
|
|
|
@ -29,7 +29,7 @@ async def async_setup_entry(
|
|||
|
||||
@callback
|
||||
def async_add_service(service):
|
||||
if service.short_type != ServicesTypes.LIGHTBULB:
|
||||
if service.type != ServicesTypes.LIGHTBULB:
|
||||
return False
|
||||
info = {"aid": service.accessory.aid, "iid": service.iid}
|
||||
async_add_entities([HomeKitLight(conn, info)], True)
|
||||
|
|
|
@ -38,7 +38,7 @@ async def async_setup_entry(
|
|||
|
||||
@callback
|
||||
def async_add_service(service):
|
||||
if service.short_type != ServicesTypes.LOCK_MECHANISM:
|
||||
if service.type != ServicesTypes.LOCK_MECHANISM:
|
||||
return False
|
||||
info = {"aid": service.accessory.aid, "iid": service.iid}
|
||||
async_add_entities([HomeKitLock(conn, info)], True)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"name": "HomeKit Controller",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/homekit_controller",
|
||||
"requirements": ["aiohomekit==0.6.11"],
|
||||
"requirements": ["aiohomekit==0.7.0"],
|
||||
"zeroconf": ["_hap._tcp.local."],
|
||||
"after_dependencies": ["zeroconf"],
|
||||
"codeowners": ["@Jc2k", "@bdraco"],
|
||||
|
|
|
@ -54,7 +54,7 @@ async def async_setup_entry(
|
|||
|
||||
@callback
|
||||
def async_add_service(service):
|
||||
if service.short_type != ServicesTypes.TELEVISION:
|
||||
if service.type != ServicesTypes.TELEVISION:
|
||||
return False
|
||||
info = {"aid": service.accessory.aid, "iid": service.iid}
|
||||
async_add_entities([HomeKitTelevision(conn, info)], True)
|
||||
|
|
|
@ -17,62 +17,62 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||
from . import KNOWN_DEVICES, CharacteristicEntity
|
||||
|
||||
NUMBER_ENTITIES: dict[str, NumberEntityDescription] = {
|
||||
CharacteristicsTypes.Vendor.VOCOLINC_HUMIDIFIER_SPRAY_LEVEL: NumberEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.VOCOLINC_HUMIDIFIER_SPRAY_LEVEL,
|
||||
CharacteristicsTypes.VENDOR_VOCOLINC_HUMIDIFIER_SPRAY_LEVEL: NumberEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_VOCOLINC_HUMIDIFIER_SPRAY_LEVEL,
|
||||
name="Spray Quantity",
|
||||
icon="mdi:water",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
CharacteristicsTypes.Vendor.EVE_DEGREE_ELEVATION: NumberEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.EVE_DEGREE_ELEVATION,
|
||||
CharacteristicsTypes.VENDOR_EVE_DEGREE_ELEVATION: NumberEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_EVE_DEGREE_ELEVATION,
|
||||
name="Elevation",
|
||||
icon="mdi:elevation-rise",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
CharacteristicsTypes.Vendor.AQARA_GATEWAY_VOLUME: NumberEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.AQARA_GATEWAY_VOLUME,
|
||||
CharacteristicsTypes.VENDOR_AQARA_GATEWAY_VOLUME: NumberEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_AQARA_GATEWAY_VOLUME,
|
||||
name="Volume",
|
||||
icon="mdi:volume-high",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
CharacteristicsTypes.Vendor.AQARA_E1_GATEWAY_VOLUME: NumberEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.AQARA_E1_GATEWAY_VOLUME,
|
||||
CharacteristicsTypes.VENDOR_AQARA_E1_GATEWAY_VOLUME: NumberEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_AQARA_E1_GATEWAY_VOLUME,
|
||||
name="Volume",
|
||||
icon="mdi:volume-high",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
CharacteristicsTypes.Vendor.ECOBEE_HOME_TARGET_COOL: NumberEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.ECOBEE_HOME_TARGET_COOL,
|
||||
CharacteristicsTypes.VENDOR_ECOBEE_HOME_TARGET_COOL: NumberEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_ECOBEE_HOME_TARGET_COOL,
|
||||
name="Home Cool Target",
|
||||
icon="mdi:thermometer-minus",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
CharacteristicsTypes.Vendor.ECOBEE_HOME_TARGET_HEAT: NumberEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.ECOBEE_HOME_TARGET_HEAT,
|
||||
CharacteristicsTypes.VENDOR_ECOBEE_HOME_TARGET_HEAT: NumberEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_ECOBEE_HOME_TARGET_HEAT,
|
||||
name="Home Heat Target",
|
||||
icon="mdi:thermometer-plus",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
CharacteristicsTypes.Vendor.ECOBEE_SLEEP_TARGET_COOL: NumberEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.ECOBEE_SLEEP_TARGET_COOL,
|
||||
CharacteristicsTypes.VENDOR_ECOBEE_SLEEP_TARGET_COOL: NumberEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_ECOBEE_SLEEP_TARGET_COOL,
|
||||
name="Sleep Cool Target",
|
||||
icon="mdi:thermometer-minus",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
CharacteristicsTypes.Vendor.ECOBEE_SLEEP_TARGET_HEAT: NumberEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.ECOBEE_SLEEP_TARGET_HEAT,
|
||||
CharacteristicsTypes.VENDOR_ECOBEE_SLEEP_TARGET_HEAT: NumberEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_ECOBEE_SLEEP_TARGET_HEAT,
|
||||
name="Sleep Heat Target",
|
||||
icon="mdi:thermometer-plus",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
CharacteristicsTypes.Vendor.ECOBEE_AWAY_TARGET_COOL: NumberEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.ECOBEE_AWAY_TARGET_COOL,
|
||||
CharacteristicsTypes.VENDOR_ECOBEE_AWAY_TARGET_COOL: NumberEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_ECOBEE_AWAY_TARGET_COOL,
|
||||
name="Away Cool Target",
|
||||
icon="mdi:thermometer-minus",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
CharacteristicsTypes.Vendor.ECOBEE_AWAY_TARGET_HEAT: NumberEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.ECOBEE_AWAY_TARGET_HEAT,
|
||||
CharacteristicsTypes.VENDOR_ECOBEE_AWAY_TARGET_HEAT: NumberEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_ECOBEE_AWAY_TARGET_HEAT,
|
||||
name="Away Heat Target",
|
||||
icon="mdi:thermometer-plus",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
|
@ -226,5 +226,5 @@ class HomeKitEcobeeFanModeNumber(CharacteristicEntity, NumberEntity):
|
|||
|
||||
|
||||
NUMBER_ENTITY_CLASSES: dict[str, type] = {
|
||||
CharacteristicsTypes.Vendor.ECOBEE_FAN_WRITE_SPEED: HomeKitEcobeeFanModeNumber,
|
||||
CharacteristicsTypes.VENDOR_ECOBEE_FAN_WRITE_SPEED: HomeKitEcobeeFanModeNumber,
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ class EcobeeModeSelect(CharacteristicEntity, SelectEntity):
|
|||
def get_characteristic_types(self):
|
||||
"""Define the homekit characteristics the entity cares about."""
|
||||
return [
|
||||
CharacteristicsTypes.Vendor.ECOBEE_CURRENT_MODE,
|
||||
CharacteristicsTypes.VENDOR_ECOBEE_CURRENT_MODE,
|
||||
]
|
||||
|
||||
@property
|
||||
|
@ -47,7 +47,7 @@ class EcobeeModeSelect(CharacteristicEntity, SelectEntity):
|
|||
"""Set the current mode."""
|
||||
option_int = _ECOBEE_MODE_TO_NUMBERS[option]
|
||||
await self.async_put_characteristics(
|
||||
{CharacteristicsTypes.Vendor.ECOBEE_SET_HOLD_SCHEDULE: option_int}
|
||||
{CharacteristicsTypes.VENDOR_ECOBEE_SET_HOLD_SCHEDULE: option_int}
|
||||
)
|
||||
|
||||
|
||||
|
@ -62,7 +62,7 @@ async def async_setup_entry(
|
|||
|
||||
@callback
|
||||
def async_add_characteristic(char: Characteristic):
|
||||
if char.type == CharacteristicsTypes.Vendor.ECOBEE_CURRENT_MODE:
|
||||
if char.type == CharacteristicsTypes.VENDOR_ECOBEE_CURRENT_MODE:
|
||||
info = {"aid": char.service.accessory.aid, "iid": char.service.iid}
|
||||
async_add_entities([EcobeeModeSelect(conn, info, char)])
|
||||
return True
|
||||
|
|
|
@ -42,85 +42,85 @@ class HomeKitSensorEntityDescription(SensorEntityDescription):
|
|||
|
||||
|
||||
SIMPLE_SENSOR: dict[str, HomeKitSensorEntityDescription] = {
|
||||
CharacteristicsTypes.Vendor.CONNECTSENSE_ENERGY_WATT: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.CONNECTSENSE_ENERGY_WATT,
|
||||
CharacteristicsTypes.VENDOR_CONNECTSENSE_ENERGY_WATT: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_CONNECTSENSE_ENERGY_WATT,
|
||||
name="Power",
|
||||
device_class=SensorDeviceClass.POWER,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=POWER_WATT,
|
||||
),
|
||||
CharacteristicsTypes.Vendor.CONNECTSENSE_ENERGY_AMPS: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.CONNECTSENSE_ENERGY_AMPS,
|
||||
CharacteristicsTypes.VENDOR_CONNECTSENSE_ENERGY_AMPS: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_CONNECTSENSE_ENERGY_AMPS,
|
||||
name="Current",
|
||||
device_class=SensorDeviceClass.CURRENT,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
),
|
||||
CharacteristicsTypes.Vendor.CONNECTSENSE_ENERGY_AMPS_20: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.CONNECTSENSE_ENERGY_AMPS_20,
|
||||
CharacteristicsTypes.VENDOR_CONNECTSENSE_ENERGY_AMPS_20: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_CONNECTSENSE_ENERGY_AMPS_20,
|
||||
name="Current",
|
||||
device_class=SensorDeviceClass.CURRENT,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
),
|
||||
CharacteristicsTypes.Vendor.CONNECTSENSE_ENERGY_KW_HOUR: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.CONNECTSENSE_ENERGY_KW_HOUR,
|
||||
CharacteristicsTypes.VENDOR_CONNECTSENSE_ENERGY_KW_HOUR: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_CONNECTSENSE_ENERGY_KW_HOUR,
|
||||
name="Energy kWh",
|
||||
device_class=SensorDeviceClass.ENERGY,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
),
|
||||
CharacteristicsTypes.Vendor.EVE_ENERGY_WATT: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.EVE_ENERGY_WATT,
|
||||
CharacteristicsTypes.VENDOR_EVE_ENERGY_WATT: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_EVE_ENERGY_WATT,
|
||||
name="Power",
|
||||
device_class=SensorDeviceClass.POWER,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=POWER_WATT,
|
||||
),
|
||||
CharacteristicsTypes.Vendor.EVE_ENERGY_KW_HOUR: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.EVE_ENERGY_KW_HOUR,
|
||||
CharacteristicsTypes.VENDOR_EVE_ENERGY_KW_HOUR: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_EVE_ENERGY_KW_HOUR,
|
||||
name="Energy kWh",
|
||||
device_class=SensorDeviceClass.ENERGY,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
),
|
||||
CharacteristicsTypes.Vendor.EVE_ENERGY_VOLTAGE: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.EVE_ENERGY_VOLTAGE,
|
||||
CharacteristicsTypes.VENDOR_EVE_ENERGY_VOLTAGE: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_EVE_ENERGY_VOLTAGE,
|
||||
name="Volts",
|
||||
device_class=SensorDeviceClass.VOLTAGE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||
),
|
||||
CharacteristicsTypes.Vendor.EVE_ENERGY_AMPERE: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.EVE_ENERGY_AMPERE,
|
||||
CharacteristicsTypes.VENDOR_EVE_ENERGY_AMPERE: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_EVE_ENERGY_AMPERE,
|
||||
name="Amps",
|
||||
device_class=SensorDeviceClass.CURRENT,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
),
|
||||
CharacteristicsTypes.Vendor.KOOGEEK_REALTIME_ENERGY: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.KOOGEEK_REALTIME_ENERGY,
|
||||
CharacteristicsTypes.VENDOR_KOOGEEK_REALTIME_ENERGY: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_KOOGEEK_REALTIME_ENERGY,
|
||||
name="Power",
|
||||
device_class=SensorDeviceClass.POWER,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=POWER_WATT,
|
||||
),
|
||||
CharacteristicsTypes.Vendor.KOOGEEK_REALTIME_ENERGY_2: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.KOOGEEK_REALTIME_ENERGY_2,
|
||||
CharacteristicsTypes.VENDOR_KOOGEEK_REALTIME_ENERGY_2: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_KOOGEEK_REALTIME_ENERGY_2,
|
||||
name="Power",
|
||||
device_class=SensorDeviceClass.POWER,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=POWER_WATT,
|
||||
),
|
||||
CharacteristicsTypes.Vendor.EVE_DEGREE_AIR_PRESSURE: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.EVE_DEGREE_AIR_PRESSURE,
|
||||
CharacteristicsTypes.VENDOR_EVE_DEGREE_AIR_PRESSURE: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_EVE_DEGREE_AIR_PRESSURE,
|
||||
name="Air Pressure",
|
||||
device_class=SensorDeviceClass.PRESSURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=PRESSURE_HPA,
|
||||
),
|
||||
CharacteristicsTypes.Vendor.VOCOLINC_OUTLET_ENERGY: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.VOCOLINC_OUTLET_ENERGY,
|
||||
CharacteristicsTypes.VENDOR_VOCOLINC_OUTLET_ENERGY: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_VOCOLINC_OUTLET_ENERGY,
|
||||
name="Power",
|
||||
device_class=SensorDeviceClass.POWER,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
|
@ -134,10 +134,7 @@ SIMPLE_SENSOR: dict[str, HomeKitSensorEntityDescription] = {
|
|||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
# This sensor is only for temperature characteristics that are not part
|
||||
# of a temperature sensor service.
|
||||
probe=(
|
||||
lambda char: char.service.type
|
||||
!= ServicesTypes.get_uuid(ServicesTypes.TEMPERATURE_SENSOR)
|
||||
),
|
||||
probe=(lambda char: char.service.type != ServicesTypes.TEMPERATURE_SENSOR),
|
||||
),
|
||||
CharacteristicsTypes.RELATIVE_HUMIDITY_CURRENT: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.RELATIVE_HUMIDITY_CURRENT,
|
||||
|
@ -147,10 +144,7 @@ SIMPLE_SENSOR: dict[str, HomeKitSensorEntityDescription] = {
|
|||
native_unit_of_measurement=PERCENTAGE,
|
||||
# This sensor is only for humidity characteristics that are not part
|
||||
# of a humidity sensor service.
|
||||
probe=(
|
||||
lambda char: char.service.type
|
||||
!= ServicesTypes.get_uuid(ServicesTypes.HUMIDITY_SENSOR)
|
||||
),
|
||||
probe=(lambda char: char.service.type != ServicesTypes.HUMIDITY_SENSOR),
|
||||
),
|
||||
CharacteristicsTypes.AIR_QUALITY: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.AIR_QUALITY,
|
||||
|
@ -202,15 +196,6 @@ SIMPLE_SENSOR: dict[str, HomeKitSensorEntityDescription] = {
|
|||
),
|
||||
}
|
||||
|
||||
# For legacy reasons, "built-in" characteristic types are in their short form
|
||||
# And vendor types don't have a short form
|
||||
# This means long and short forms get mixed up in this dict, and comparisons
|
||||
# don't work!
|
||||
# We call get_uuid on *every* type to normalise them to the long form
|
||||
# Eventually aiohomekit will use the long form exclusively amd this can be removed.
|
||||
for k, v in list(SIMPLE_SENSOR.items()):
|
||||
SIMPLE_SENSOR[CharacteristicsTypes.get_uuid(k)] = SIMPLE_SENSOR.pop(k)
|
||||
|
||||
|
||||
class HomeKitHumiditySensor(HomeKitEntity, SensorEntity):
|
||||
"""Representation of a Homekit humidity sensor."""
|
||||
|
@ -415,7 +400,7 @@ async def async_setup_entry(
|
|||
|
||||
@callback
|
||||
def async_add_service(service):
|
||||
if not (entity_class := ENTITY_TYPES.get(service.short_type)):
|
||||
if not (entity_class := ENTITY_TYPES.get(service.type)):
|
||||
return False
|
||||
info = {"aid": service.accessory.aid, "iid": service.iid}
|
||||
async_add_entities([entity_class(conn, info)], True)
|
||||
|
|
|
@ -35,14 +35,14 @@ class DeclarativeSwitchEntityDescription(SwitchEntityDescription):
|
|||
|
||||
|
||||
SWITCH_ENTITIES: dict[str, DeclarativeSwitchEntityDescription] = {
|
||||
CharacteristicsTypes.Vendor.AQARA_PAIRING_MODE: DeclarativeSwitchEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.AQARA_PAIRING_MODE,
|
||||
CharacteristicsTypes.VENDOR_AQARA_PAIRING_MODE: DeclarativeSwitchEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_AQARA_PAIRING_MODE,
|
||||
name="Pairing Mode",
|
||||
icon="mdi:lock-open",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
CharacteristicsTypes.Vendor.AQARA_E1_PAIRING_MODE: DeclarativeSwitchEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.AQARA_E1_PAIRING_MODE,
|
||||
CharacteristicsTypes.VENDOR_AQARA_E1_PAIRING_MODE: DeclarativeSwitchEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_AQARA_E1_PAIRING_MODE,
|
||||
name="Pairing Mode",
|
||||
icon="mdi:lock-open",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
|
@ -189,7 +189,7 @@ async def async_setup_entry(
|
|||
|
||||
@callback
|
||||
def async_add_service(service):
|
||||
if not (entity_class := ENTITY_TYPES.get(service.short_type)):
|
||||
if not (entity_class := ENTITY_TYPES.get(service.type)):
|
||||
return False
|
||||
info = {"aid": service.accessory.aid, "iid": service.iid}
|
||||
async_add_entities([entity_class(conn, info)], True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue