Provide a better model for HomeKit service entries (#100848)

pull/100861/head
J. Nick Koston 2023-09-25 09:34:53 -05:00 committed by GitHub
parent fb174f8063
commit c1b9400833
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -856,8 +856,7 @@ class HomeKit:
connection = (dr.CONNECTION_NETWORK_MAC, formatted_mac)
identifier = (DOMAIN, self._entry_id, BRIDGE_SERIAL_NUMBER)
self._async_purge_old_bridges(dev_reg, identifier, connection)
is_accessory_mode = self._homekit_mode == HOMEKIT_MODE_ACCESSORY
hk_mode_name = "Accessory" if is_accessory_mode else "Bridge"
accessory_type = type(self.driver.accessory).__name__
dev_reg.async_get_or_create(
config_entry_id=self._entry_id,
identifiers={
@ -866,7 +865,7 @@ class HomeKit:
connections={connection},
manufacturer=MANUFACTURER,
name=accessory_friendly_name(self._entry_title, self.driver.accessory),
model=f"HomeKit {hk_mode_name}",
model=accessory_type,
entry_type=dr.DeviceEntryType.SERVICE,
)

View File

@ -765,6 +765,7 @@ async def test_homekit_start(
assert device
formatted_mac = dr.format_mac(homekit.driver.state.mac)
assert (dr.CONNECTION_NETWORK_MAC, formatted_mac) in device.connections
assert device.model == "HomeBridge"
assert len(device_registry.devices) == 1
assert homekit.driver.state.config_version == 1
@ -2010,6 +2011,16 @@ async def test_homekit_start_in_accessory_mode(
assert hk_driver_start.called
assert homekit.status == STATUS_RUNNING
device = device_registry.async_get_device(
identifiers={(DOMAIN, entry.entry_id, BRIDGE_SERIAL_NUMBER)}
)
assert device
formatted_mac = dr.format_mac(homekit.driver.state.mac)
assert (dr.CONNECTION_NETWORK_MAC, formatted_mac) in device.connections
assert device.model == "Light"
assert len(device_registry.devices) == 1
async def test_homekit_start_in_accessory_mode_unsupported_entity(
hass: HomeAssistant,