Use DeviceInfo on hassio (#58397)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-10-25 13:15:00 +02:00 committed by GitHub
parent f3ca61ffe0
commit 4d7c55ff0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,6 +17,7 @@ from homeassistant.components.homeassistant import (
import homeassistant.config as conf_util import homeassistant.config as conf_util
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
ATTR_MANUFACTURER,
ATTR_NAME, ATTR_NAME,
ATTR_SERVICE, ATTR_SERVICE,
EVENT_CORE_CONFIG_UPDATE, EVENT_CORE_CONFIG_UPDATE,
@ -27,6 +28,7 @@ from homeassistant.core import DOMAIN as HASS_DOMAIN, HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_validation as cv, recorder from homeassistant.helpers import config_validation as cv, recorder
from homeassistant.helpers.device_registry import DeviceRegistry, async_get_registry from homeassistant.helpers.device_registry import DeviceRegistry, async_get_registry
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from homeassistant.loader import bind_hass from homeassistant.loader import bind_hass
@ -653,17 +655,16 @@ def async_register_addons_in_dev_reg(
) -> None: ) -> None:
"""Register addons in the device registry.""" """Register addons in the device registry."""
for addon in addons: for addon in addons:
params = { params = DeviceInfo(
"config_entry_id": entry_id, identifiers={(DOMAIN, addon[ATTR_SLUG])},
"identifiers": {(DOMAIN, addon[ATTR_SLUG])}, model=SupervisorEntityModel.ADDON,
"model": SupervisorEntityModel.ADDON, sw_version=addon[ATTR_VERSION],
"sw_version": addon[ATTR_VERSION], name=addon[ATTR_NAME],
"name": addon[ATTR_NAME], entry_type=ATTR_SERVICE,
"entry_type": ATTR_SERVICE, )
}
if manufacturer := addon.get(ATTR_REPOSITORY) or addon.get(ATTR_URL): if manufacturer := addon.get(ATTR_REPOSITORY) or addon.get(ATTR_URL):
params["manufacturer"] = manufacturer params[ATTR_MANUFACTURER] = manufacturer
dev_reg.async_get_or_create(**params) dev_reg.async_get_or_create(config_entry_id=entry_id, **params)
@callback @callback
@ -671,16 +672,15 @@ def async_register_os_in_dev_reg(
entry_id: str, dev_reg: DeviceRegistry, os_dict: dict[str, Any] entry_id: str, dev_reg: DeviceRegistry, os_dict: dict[str, Any]
) -> None: ) -> None:
"""Register OS in the device registry.""" """Register OS in the device registry."""
params = { params = DeviceInfo(
"config_entry_id": entry_id, identifiers={(DOMAIN, "OS")},
"identifiers": {(DOMAIN, "OS")}, manufacturer="Home Assistant",
"manufacturer": "Home Assistant", model=SupervisorEntityModel.OS,
"model": SupervisorEntityModel.OS, sw_version=os_dict[ATTR_VERSION],
"sw_version": os_dict[ATTR_VERSION], name="Home Assistant Operating System",
"name": "Home Assistant Operating System", entry_type=ATTR_SERVICE,
"entry_type": ATTR_SERVICE, )
} dev_reg.async_get_or_create(config_entry_id=entry_id, **params)
dev_reg.async_get_or_create(**params)
@callback @callback