HAP-python
HAP-python copied to clipboard
Need to remove bridge from iPhone after adding/removing devices?
I'm creating a bridge and adding two accessories,
- a light (on/off)
- a light that can be dimmed and has a brightness parameter. When adding the bridge on my iPhone, both lights work fine.
Then I'm shutting down the bridge and change the accessories to
- a light that can be dimmed and has a brightness parameter
- a motion sensor.
I did not touch the accessory.state file that was created the first time when adding the bridge. Now the accessories on my iPhone are corrupt. The lights are not working correctly and the motion sensor is missing. I need to remove the bridge from my iPhone and re-add it, then everything is working fine.
When just adding extra lights, or switches, or removing these, the bridge and accessories seem to be updated automatically and correct on my iPhone.
Is it normal/expected to have to remove and re-add the bridge after changing the configuration of accessories?
We handle this in Home Assistant with a reset accessory service
https://github.com/home-assistant/core/blob/dev/homeassistant/components/homekit/init.py#L484
I'm creating a bridge and adding two accessories,
- a light (on/off)
- a light that can be dimmed and has a brightness parameter. When adding the bridge on my iPhone, both lights work fine.
Then I'm shutting down the bridge and change the accessories to
- a light that can be dimmed and has a brightness parameter
- a motion sensor.
I did not touch the accessory.state file that was created the first time when adding the bridge. Now the accessories on my iPhone are corrupt. The lights are not working correctly and the motion sensor is missing. I need to remove the bridge from my iPhone and re-add it, then everything is working fine.
When just adding extra lights, or switches, or removing these, the bridge and accessories seem to be updated automatically and correct on my iPhone.
Is it normal/expected to have to remove and re-add the bridge after changing the configuration of accessories?
My understanding is, if you want a full refresh you need to delete the state file , delete the bridge on your phone, then restart/re-pair the bridge and load all definitions (classes/accessories) again.
All config_changed
All
config_changed
@bdraco sounds great. Is where an example, how to use config_changed() ?
def reset_accessories(self, entity_ids):
"""Reset the accessory to load the latest configuration."""
if not self.bridge:
self.driver.config_changed()
return
aid_storage = self.hass.data[DOMAIN][self._entry_id][AID_STORAGE]
removed = []
for entity_id in entity_ids:
aid = aid_storage.get_or_allocate_aid_for_entity_id(entity_id)
if aid not in self.bridge.accessories:
continue
_LOGGER.info(
"HomeKit Bridge %s will reset accessory with linked entity_id %s",
self._name,
entity_id,
)
acc = self.remove_bridge_accessory(aid)
removed.append(acc)
if not removed:
# No matched accessories, probably on another bridge
return
self.driver.config_changed()
for acc in removed:
self.bridge.add_accessory(acc)
self.driver.config_changed()
def reset_accessories(self, entity_ids): """Reset the accessory to load the latest configuration.""" if not self.bridge: self.driver.config_changed() return
aid_storage = self.hass.data[DOMAIN][self._entry_id][AID_STORAGE] removed = [] for entity_id in entity_ids: aid = aid_storage.get_or_allocate_aid_for_entity_id(entity_id) if aid not in self.bridge.accessories: continue _LOGGER.info( "HomeKit Bridge %s will reset accessory with linked entity_id %s", self._name, entity_id, ) acc = self.remove_bridge_accessory(aid) removed.append(acc) if not removed: # No matched accessories, probably on another bridge return self.driver.config_changed() for acc in removed: self.bridge.add_accessory(acc) self.driver.config_changed()
Trying to adopt that to the "normal" HAP-Python scripts (without HASS). Do i have to access the *.state file and read a python list in the same way as the self.hass.data?