diff --git a/homeassistant/components/hassio/__init__.py b/homeassistant/components/hassio/__init__.py index 82797874445..4e9a78e75a8 100644 --- a/homeassistant/components/hassio/__init__.py +++ b/homeassistant/components/hassio/__init__.py @@ -522,15 +522,17 @@ def async_register_addons_in_dev_reg( ) -> None: """Register addons in the device registry.""" for addon in addons: - dev_reg.async_get_or_create( - config_entry_id=entry_id, - identifiers={(DOMAIN, addon[ATTR_SLUG])}, - manufacturer=addon.get(ATTR_REPOSITORY) or addon.get(ATTR_URL) or "unknown", - model="Home Assistant Add-on", - sw_version=addon[ATTR_VERSION], - name=addon[ATTR_NAME], - entry_type=ATTR_SERVICE, - ) + params = { + "config_entry_id": entry_id, + "identifiers": {(DOMAIN, addon[ATTR_SLUG])}, + "model": "Home Assistant Add-on", + "sw_version": addon[ATTR_VERSION], + "name": addon[ATTR_NAME], + "entry_type": ATTR_SERVICE, + } + if manufacturer := addon.get(ATTR_REPOSITORY) or addon.get(ATTR_URL): + params["manufacturer"] = manufacturer + dev_reg.async_get_or_create(**params) @callback @@ -538,15 +540,16 @@ def async_register_os_in_dev_reg( entry_id: str, dev_reg: DeviceRegistry, os_dict: Dict[str, Any] ) -> None: """Register OS in the device registry.""" - dev_reg.async_get_or_create( - config_entry_id=entry_id, - identifiers={(DOMAIN, "OS")}, - manufacturer="Home Assistant", - model="Home Assistant Operating System", - sw_version=os_dict[ATTR_VERSION], - name="Home Assistant Operating System", - entry_type=ATTR_SERVICE, - ) + params = { + "config_entry_id": entry_id, + "identifiers": {(DOMAIN, "OS")}, + "manufacturer": "Home Assistant", + "model": "Home Assistant Operating System", + "sw_version": os_dict[ATTR_VERSION], + "name": "Home Assistant Operating System", + "entry_type": ATTR_SERVICE, + } + dev_reg.async_get_or_create(**params) @callback @@ -600,15 +603,13 @@ class HassioDataUpdateCoordinator(DataUpdateCoordinator): return new_data # Remove add-ons that are no longer installed from device registry - if removed_addons := list( - set(self.data["addons"].keys()) - set(new_data["addons"].keys()) - ): + if removed_addons := list(set(self.data["addons"]) - set(new_data["addons"])): async_remove_addons_from_dev_reg(self.dev_reg, removed_addons) # If there are new add-ons, we should reload the config entry so we can # create new devices and entities. We can return an empty dict because # coordinator will be recreated. - if list(set(new_data["addons"].keys()) - set(self.data["addons"].keys())): + if list(set(new_data["addons"]) - set(self.data["addons"])): self.hass.async_create_task( self.hass.config_entries.async_reload(self.entry_id) ) diff --git a/tests/components/hassio/test_init.py b/tests/components/hassio/test_init.py index bd9eb30be5c..5bf8a45ab52 100644 --- a/tests/components/hassio/test_init.py +++ b/tests/components/hassio/test_init.py @@ -393,7 +393,7 @@ async def test_entry_load_and_unload(hass): assert BINARY_SENSOR_DOMAIN in hass.config.components assert ADDONS_COORDINATOR in hass.data - assert await config_entry.async_unload(hass) + assert await hass.config_entries.async_unload(config_entry.entry_id) await hass.async_block_till_done() assert ADDONS_COORDINATOR not in hass.data