Support HomeKit Controller Thread Provisioning (#87809)

This commit is contained in:
Jc2k 2023-02-15 16:41:07 +00:00 committed by GitHub
parent 402170d49e
commit f5a05c1bd2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 220 additions and 4 deletions

View file

@ -6,6 +6,7 @@ characteristics that don't map to a Home Assistant feature.
from __future__ import annotations
from dataclasses import dataclass
import logging
from aiohomekit.model.characteristics import Characteristic, CharacteristicsTypes
@ -24,6 +25,8 @@ from . import KNOWN_DEVICES
from .connection import HKDevice
from .entity import CharacteristicEntity
_LOGGER = logging.getLogger(__name__)
@dataclass
class HomeKitButtonEntityDescription(ButtonEntityDescription):
@ -151,6 +154,29 @@ class HomeKitEcobeeClearHoldButton(CharacteristicEntity, ButtonEntity):
await self.async_put_characteristics({key: val})
class HomeKitProvisionPreferredThreadCredentials(CharacteristicEntity, ButtonEntity):
"""A button users can press to migrate their HomeKit BLE device to Thread."""
_attr_entity_category = EntityCategory.CONFIG
def get_characteristic_types(self) -> list[str]:
"""Define the homekit characteristics the entity is tracking."""
return []
@property
def name(self) -> str:
"""Return the name of the device if any."""
prefix = ""
if name := super().name:
prefix = name
return f"{prefix} Provision Preferred Thread Credentials"
async def async_press(self) -> None:
"""Press the button."""
await self._accessory.async_thread_provision()
BUTTON_ENTITY_CLASSES: dict[str, type] = {
CharacteristicsTypes.VENDOR_ECOBEE_CLEAR_HOLD: HomeKitEcobeeClearHoldButton,
CharacteristicsTypes.THREAD_CONTROL_POINT: HomeKitProvisionPreferredThreadCredentials,
}