Home Assistant Unofficial Reference 2024.12.1
homeassistant.components.homekit_controller.connection.HKDevice Class Reference

Public Member Functions

None __init__ (self, HomeAssistant hass, ConfigEntry config_entry, MappingProxyType[str, Any] pairing_data)
 
None add_accessory_factory (self, AddAccessoryCb add_entities_cb)
 
None add_char_factory (self, AddCharacteristicCb add_entities_cb)
 
None add_entities (self)
 
None add_listener (self, AddServiceCb add_entities_cb)
 
None add_pollable_characteristics (self, list[tuple[int, int]] characteristics)
 
None add_trigger_factory (self, AddServiceCb add_triggers_cb)
 
None add_watchable_characteristics (self, list[tuple[int, int]] characteristics)
 
None async_add_new_entities (self)
 
None async_create_devices (self)
 
None async_detect_workarounds (self)
 
None async_entity_key_removed (self, tuple[int, int|None, int|None] entity_key)
 
None async_load_platforms (self)
 
None async_migrate_ble_unique_id (self)
 
None async_migrate_devices (self)
 
None async_migrate_unique_id (self, str old_unique_id, str|None new_unique_id, str platform)
 
None async_process_entity_map (self)
 
None async_reap_stale_entity_registry_entries (self)
 
None async_remove_legacy_device_serial_numbers (self)
 
None async_request_update (self, datetime|None now=None)
 
None async_set_available_state (self, bool available)
 
None async_setup (self)
 
CALLBACK_TYPE async_subscribe (self, set[tuple[int, int]] characteristics, CALLBACK_TYPE callback_)
 
CALLBACK_TYPE async_subscribe_availability (self, CALLBACK_TYPE callback_)
 
CALLBACK_TYPE async_subscribe_config_changed (self, CALLBACK_TYPE callback_)
 
None async_thread_provision (self)
 
None async_unload (self)
 
None async_update (self, datetime|None now=None)
 
None async_update_available_state (self, *Any _)
 
None async_update_new_accessories_state (self)
 
int config_num (self)
 
DeviceInfo device_info_for_accessory (self, Accessory accessory)
 
Accessories entity_map (self)
 
dict[tuple[int, int], dict[str, Any]] get_characteristics (self, *Any args, **Any kwargs)
 
bool is_unprovisioned_thread_device (self)
 
None process_config_changed (self, int config_num)
 
None process_new_events (self, dict[tuple[int, int], dict[str, Any]] new_values_dict)
 
None put_characteristics (self, Iterable[tuple[int, int, Any]] characteristics)
 
None remove_pollable_characteristics (self, list[tuple[int, int]] characteristics)
 
None remove_watchable_characteristics (self, list[tuple[int, int]] characteristics)
 
str unique_id (self)
 

Public Attributes

 available
 
 config_entry
 
 devices
 
 hass
 
 pairing
 
 pairing_data
 
 unreliable_serial_numbers
 

Private Member Functions

None _add_new_entities (self, list[AddServiceCb] callbacks)
 
None _add_new_entities_for_accessory (self, list[AddAccessoryCb] handlers)
 
None _add_new_entities_for_char (self, list[AddCharacteristicCb] handlers)
 
None _add_new_triggers (self, list[AddServiceCb] callbacks)
 
None _async_cancel_subscription_timer (self)
 
None _async_load_platforms (self, set[str] platforms)
 
None _async_populate_ble_accessory_state (self, Event event)
 
None _async_schedule_update (self, datetime now)
 
None _async_start_polling (self)
 
None _async_subscribe (self, datetime _now)
 
None _remove_availability_callback (self, CALLBACK_TYPE callback_)
 
None _remove_characteristics_callback (self, set[tuple[int, int]] characteristics, CALLBACK_TYPE callback_)
 
None _remove_config_changed_callback (self, CALLBACK_TYPE callback_)
 

Private Attributes

 _debounced_update
 
 _full_update_requested
 
 _load_platforms_lock
 
 _poll_failures
 
 _polling_lock
 
 _polling_lock_warned
 
 _subscribe_timer
 

Detailed Description

HomeKit device.

Definition at line 75 of file connection.py.

Constructor & Destructor Documentation

◆ __init__()

None homeassistant.components.homekit_controller.connection.HKDevice.__init__ (   self,
HomeAssistant  hass,
ConfigEntry  config_entry,
MappingProxyType[str, Any]  pairing_data 
)
Initialise a generic HomeKit device.

Definition at line 78 of file connection.py.

Member Function Documentation

◆ _add_new_entities()

None homeassistant.components.homekit_controller.connection.HKDevice._add_new_entities (   self,
list[AddServiceCb callbacks 
)
private

Definition at line 793 of file connection.py.

◆ _add_new_entities_for_accessory()

None homeassistant.components.homekit_controller.connection.HKDevice._add_new_entities_for_accessory (   self,
list[AddAccessoryCb handlers 
)
private

Definition at line 737 of file connection.py.

◆ _add_new_entities_for_char()

None homeassistant.components.homekit_controller.connection.HKDevice._add_new_entities_for_char (   self,
list[AddCharacteristicCb handlers 
)
private

Definition at line 750 of file connection.py.

◆ _add_new_triggers()

None homeassistant.components.homekit_controller.connection.HKDevice._add_new_triggers (   self,
list[AddServiceCb callbacks 
)
private

Definition at line 770 of file connection.py.

◆ _async_cancel_subscription_timer()

None homeassistant.components.homekit_controller.connection.HKDevice._async_cancel_subscription_timer (   self)
private
Cancel the subscribe timer.

Definition at line 197 of file connection.py.

◆ _async_load_platforms()

None homeassistant.components.homekit_controller.connection.HKDevice._async_load_platforms (   self,
set[str]  platforms 
)
private
Load a group of platforms.

Definition at line 808 of file connection.py.

◆ _async_populate_ble_accessory_state()

None homeassistant.components.homekit_controller.connection.HKDevice._async_populate_ble_accessory_state (   self,
Event  event 
)
private
Populate the BLE accessory state without blocking startup.

If the accessory was asleep at startup we need to retry
since we continued on to allow startup to proceed.

If this fails the state may be inconsistent, but will
get corrected as soon as the accessory advertises again.

Definition at line 237 of file connection.py.

◆ _async_schedule_update()

None homeassistant.components.homekit_controller.connection.HKDevice._async_schedule_update (   self,
datetime  now 
)
private
Schedule an update.

Definition at line 351 of file connection.py.

◆ _async_start_polling()

None homeassistant.components.homekit_controller.connection.HKDevice._async_start_polling (   self)
private
Start polling for updates.

Definition at line 336 of file connection.py.

◆ _async_subscribe()

None homeassistant.components.homekit_controller.connection.HKDevice._async_subscribe (   self,
datetime  _now 
)
private
Subscribe to characteristics.

Definition at line 204 of file connection.py.

◆ _remove_availability_callback()

None homeassistant.components.homekit_controller.connection.HKDevice._remove_availability_callback (   self,
CALLBACK_TYPE  callback_ 
)
private
Remove an availability callback.

Definition at line 978 of file connection.py.

◆ _remove_characteristics_callback()

None homeassistant.components.homekit_controller.connection.HKDevice._remove_characteristics_callback (   self,
set[tuple[int, int]]  characteristics,
CALLBACK_TYPE   callback_ 
)
private
Remove a characteristics callback.

Definition at line 957 of file connection.py.

◆ _remove_config_changed_callback()

None homeassistant.components.homekit_controller.connection.HKDevice._remove_config_changed_callback (   self,
CALLBACK_TYPE  callback_ 
)
private
Remove an availability callback.

Definition at line 989 of file connection.py.

◆ add_accessory_factory()

None homeassistant.components.homekit_controller.connection.HKDevice.add_accessory_factory (   self,
AddAccessoryCb  add_entities_cb 
)
Add a callback to run when discovering new entities for accessories.

Definition at line 732 of file connection.py.

◆ add_char_factory()

None homeassistant.components.homekit_controller.connection.HKDevice.add_char_factory (   self,
AddCharacteristicCb  add_entities_cb 
)
Add a callback to run when discovering new entities for accessories.

Definition at line 745 of file connection.py.

◆ add_entities()

None homeassistant.components.homekit_controller.connection.HKDevice.add_entities (   self)
Process the entity map and create HA entities.

Definition at line 786 of file connection.py.

◆ add_listener()

None homeassistant.components.homekit_controller.connection.HKDevice.add_listener (   self,
AddServiceCb  add_entities_cb 
)
Add a callback to run when discovering new entities for services.

Definition at line 760 of file connection.py.

◆ add_pollable_characteristics()

None homeassistant.components.homekit_controller.connection.HKDevice.add_pollable_characteristics (   self,
list[tuple[int, int]]   characteristics 
)
Add (aid, iid) pairs that we need to poll.

Definition at line 169 of file connection.py.

◆ add_trigger_factory()

None homeassistant.components.homekit_controller.connection.HKDevice.add_trigger_factory (   self,
AddServiceCb  add_triggers_cb 
)
Add a callback to run when discovering new triggers for services.

Definition at line 765 of file connection.py.

◆ add_watchable_characteristics()

None homeassistant.components.homekit_controller.connection.HKDevice.add_watchable_characteristics (   self,
list[tuple[int, int]]   characteristics 
)
Add (aid, iid) pairs that we need to poll.

Definition at line 182 of file connection.py.

◆ async_add_new_entities()

None homeassistant.components.homekit_controller.connection.HKDevice.async_add_new_entities (   self)
Add new entities to Home Assistant.

Definition at line 360 of file connection.py.

◆ async_create_devices()

None homeassistant.components.homekit_controller.connection.HKDevice.async_create_devices (   self)
Build device registry entries for all accessories paired with the bridge.

This is done as well as by the entities for 2 reasons. First, the bridge
might not have any entities attached to it. Secondly there are stateless
entities like doorbells and remote controls.

Definition at line 606 of file connection.py.

◆ async_detect_workarounds()

None homeassistant.components.homekit_controller.connection.HKDevice.async_detect_workarounds (   self)
Detect any workarounds that are needed for this pairing.

Definition at line 632 of file connection.py.

◆ async_entity_key_removed()

None homeassistant.components.homekit_controller.connection.HKDevice.async_entity_key_removed (   self,
tuple[int, int | None, int | None]   entity_key 
)
Handle an entity being removed.

Releases the entity from self.entities so it can be added again.

Definition at line 723 of file connection.py.

◆ async_load_platforms()

None homeassistant.components.homekit_controller.connection.HKDevice.async_load_platforms (   self)
Load any platforms needed by this HomeKit device.

Definition at line 818 of file connection.py.

◆ async_migrate_ble_unique_id()

None homeassistant.components.homekit_controller.connection.HKDevice.async_migrate_ble_unique_id (   self)
Config entries from step_bluetooth used incorrect identifier for unique_id.

Definition at line 592 of file connection.py.

◆ async_migrate_devices()

None homeassistant.components.homekit_controller.connection.HKDevice.async_migrate_devices (   self)
Migrate legacy device entries from 3-tuples to 2-tuples.

Definition at line 404 of file connection.py.

◆ async_migrate_unique_id()

None homeassistant.components.homekit_controller.connection.HKDevice.async_migrate_unique_id (   self,
str  old_unique_id,
str | None  new_unique_id,
str   platform 
)
Migrate legacy unique IDs to new format.

Definition at line 462 of file connection.py.

◆ async_process_entity_map()

None homeassistant.components.homekit_controller.connection.HKDevice.async_process_entity_map (   self)
Process the entity map and load any platforms or entities that need adding.

This is idempotent and will be called at startup and when we detect metadata changes
via the c# counter on the zeroconf record.

Definition at line 674 of file connection.py.

◆ async_reap_stale_entity_registry_entries()

None homeassistant.components.homekit_controller.connection.HKDevice.async_reap_stale_entity_registry_entries (   self)
Delete entity registry entities for removed characteristics, services and accessories.

Definition at line 540 of file connection.py.

◆ async_remove_legacy_device_serial_numbers()

None homeassistant.components.homekit_controller.connection.HKDevice.async_remove_legacy_device_serial_numbers (   self)
Migrate remove legacy serial numbers from devices.

We no longer use serial numbers as device identifiers
since they are not reliable, and the HomeKit spec
does not require them to be stable.

Definition at line 505 of file connection.py.

◆ async_request_update()

None homeassistant.components.homekit_controller.connection.HKDevice.async_request_update (   self,
datetime | None   now = None 
)
Request an debounced update from the accessory.

Definition at line 843 of file connection.py.

◆ async_set_available_state()

None homeassistant.components.homekit_controller.connection.HKDevice.async_set_available_state (   self,
bool  available 
)
Mark state of all entities on this connection when it becomes available or unavailable.

Definition at line 226 of file connection.py.

◆ async_setup()

None homeassistant.components.homekit_controller.connection.HKDevice.async_setup (   self)
Prepare to use a paired HomeKit device in Home Assistant.

Definition at line 259 of file connection.py.

◆ async_subscribe()

CALLBACK_TYPE homeassistant.components.homekit_controller.connection.HKDevice.async_subscribe (   self,
set[tuple[int, int]]  characteristics,
CALLBACK_TYPE   callback_ 
)
Add characteristics to the watch list.

Definition at line 967 of file connection.py.

◆ async_subscribe_availability()

CALLBACK_TYPE homeassistant.components.homekit_controller.connection.HKDevice.async_subscribe_availability (   self,
CALLBACK_TYPE  callback_ 
)
Add characteristics to the watch list.

Definition at line 983 of file connection.py.

◆ async_subscribe_config_changed()

CALLBACK_TYPE homeassistant.components.homekit_controller.connection.HKDevice.async_subscribe_config_changed (   self,
CALLBACK_TYPE  callback_ 
)
Subscribe to config of the accessory being changed aka c# changes.

Definition at line 994 of file connection.py.

◆ async_thread_provision()

None homeassistant.components.homekit_controller.connection.HKDevice.async_thread_provision (   self)
Migrate a HomeKit pairing to CoAP (Thread).

Definition at line 1024 of file connection.py.

◆ async_unload()

None homeassistant.components.homekit_controller.connection.HKDevice.async_unload (   self)
Stop interacting with device and prepare for removal from hass.

Definition at line 700 of file connection.py.

◆ async_update()

None homeassistant.components.homekit_controller.connection.HKDevice.async_update (   self,
datetime | None   now = None 
)
Poll state of all entities attached to this bridge/accessory.

Definition at line 848 of file connection.py.

◆ async_update_available_state()

None homeassistant.components.homekit_controller.connection.HKDevice.async_update_available_state (   self,
*Any  _ 
)
Update the available state of the device.

Definition at line 839 of file connection.py.

◆ async_update_new_accessories_state()

None homeassistant.components.homekit_controller.connection.HKDevice.async_update_new_accessories_state (   self)
Process a change in the pairings accessories state.

Definition at line 714 of file connection.py.

◆ config_num()

int homeassistant.components.homekit_controller.connection.HKDevice.config_num (   self)
Return the config num from the pairing.

Definition at line 165 of file connection.py.

◆ device_info_for_accessory()

DeviceInfo homeassistant.components.homekit_controller.connection.HKDevice.device_info_for_accessory (   self,
Accessory  accessory 
)
Build a DeviceInfo for a given accessory.

Definition at line 365 of file connection.py.

◆ entity_map()

Accessories homeassistant.components.homekit_controller.connection.HKDevice.entity_map (   self)
Return the accessories from the pairing.

Definition at line 160 of file connection.py.

◆ get_characteristics()

dict[tuple[int, int], dict[str, Any]] homeassistant.components.homekit_controller.connection.HKDevice.get_characteristics (   self,
*Any  args,
**Any   kwargs 
)
Read latest state from homekit accessory.

Definition at line 999 of file connection.py.

◆ is_unprovisioned_thread_device()

bool homeassistant.components.homekit_controller.connection.HKDevice.is_unprovisioned_thread_device (   self)
Is this a thread capable device not connected by CoAP.

Definition at line 1012 of file connection.py.

◆ process_config_changed()

None homeassistant.components.homekit_controller.connection.HKDevice.process_config_changed (   self,
int  config_num 
)
Handle a config change notification from the pairing.

Definition at line 708 of file connection.py.

◆ process_new_events()

None homeassistant.components.homekit_controller.connection.HKDevice.process_new_events (   self,
dict[tuple[int, int], dict[str, Any]]   new_values_dict 
)
Process events from accessory into HA state.

Definition at line 939 of file connection.py.

◆ put_characteristics()

None homeassistant.components.homekit_controller.connection.HKDevice.put_characteristics (   self,
Iterable[tuple[int, int, Any]]   characteristics 
)
Control a HomeKit device state from Home Assistant.

Definition at line 1005 of file connection.py.

◆ remove_pollable_characteristics()

None homeassistant.components.homekit_controller.connection.HKDevice.remove_pollable_characteristics (   self,
list[tuple[int, int]]   characteristics 
)
Remove all pollable characteristics by accessory id.

Definition at line 175 of file connection.py.

◆ remove_watchable_characteristics()

None homeassistant.components.homekit_controller.connection.HKDevice.remove_watchable_characteristics (   self,
list[tuple[int, int]]   characteristics 
)
Remove all pollable characteristics by accessory id.

Definition at line 217 of file connection.py.

◆ unique_id()

str homeassistant.components.homekit_controller.connection.HKDevice.unique_id (   self)
Return a unique id for this accessory or bridge.

This id is random and will change if a device undergoes a hard reset.

Definition at line 1065 of file connection.py.

Member Data Documentation

◆ _debounced_update

homeassistant.components.homekit_controller.connection.HKDevice._debounced_update
private

Definition at line 142 of file connection.py.

◆ _full_update_requested

homeassistant.components.homekit_controller.connection.HKDevice._full_update_requested
private

Definition at line 845 of file connection.py.

◆ _load_platforms_lock

homeassistant.components.homekit_controller.connection.HKDevice._load_platforms_lock
private

Definition at line 156 of file connection.py.

◆ _poll_failures

homeassistant.components.homekit_controller.connection.HKDevice._poll_failures
private

Definition at line 135 of file connection.py.

◆ _polling_lock

homeassistant.components.homekit_controller.connection.HKDevice._polling_lock
private

Definition at line 133 of file connection.py.

◆ _polling_lock_warned

homeassistant.components.homekit_controller.connection.HKDevice._polling_lock_warned
private

Definition at line 134 of file connection.py.

◆ _subscribe_timer

homeassistant.components.homekit_controller.connection.HKDevice._subscribe_timer
private

Definition at line 190 of file connection.py.

◆ available

homeassistant.components.homekit_controller.connection.HKDevice.available

Definition at line 128 of file connection.py.

◆ config_entry

homeassistant.components.homekit_controller.connection.HKDevice.config_entry

Definition at line 87 of file connection.py.

◆ devices

homeassistant.components.homekit_controller.connection.HKDevice.devices

Definition at line 629 of file connection.py.

◆ hass

homeassistant.components.homekit_controller.connection.HKDevice.hass

Definition at line 86 of file connection.py.

◆ pairing

homeassistant.components.homekit_controller.connection.HKDevice.pairing

Definition at line 95 of file connection.py.

◆ pairing_data

homeassistant.components.homekit_controller.connection.HKDevice.pairing_data

Definition at line 91 of file connection.py.

◆ unreliable_serial_numbers

homeassistant.components.homekit_controller.connection.HKDevice.unreliable_serial_numbers

Definition at line 138 of file connection.py.


The documentation for this class was generated from the following file: