Cleanup device registration in Onewire (#58101)
* Add checks for device registry * Move registry checks to init.py * Run device registry check on disabled devices * Empty commit for testing * Register devices during initialisation * Adjust tests accordingly * Add via_device to device info * Adjust access to device registry Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
766a693514
commit
c00a5fad8f
11 changed files with 317 additions and 253 deletions
|
@ -3,21 +3,16 @@ from __future__ import annotations
|
|||
|
||||
from dataclasses import dataclass
|
||||
import os
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
BinarySensorEntity,
|
||||
BinarySensorEntityDescription,
|
||||
)
|
||||
from homeassistant.components.onewire.model import OWServerDeviceDescription
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_IDENTIFIERS,
|
||||
ATTR_MANUFACTURER,
|
||||
ATTR_MODEL,
|
||||
ATTR_NAME,
|
||||
CONF_TYPE,
|
||||
)
|
||||
from homeassistant.const import CONF_TYPE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import (
|
||||
|
@ -89,24 +84,17 @@ def get_entities(onewirehub: OneWireHub) -> list[BinarySensorEntity]:
|
|||
return []
|
||||
|
||||
entities: list[BinarySensorEntity] = []
|
||||
|
||||
for device in onewirehub.devices:
|
||||
family = device["family"]
|
||||
device_type = device["type"]
|
||||
device_id = os.path.split(os.path.split(device["path"])[0])[1]
|
||||
if TYPE_CHECKING:
|
||||
assert isinstance(device, OWServerDeviceDescription)
|
||||
family = device.family
|
||||
device_id = device.id
|
||||
device_info = device.device_info
|
||||
|
||||
if family not in DEVICE_BINARY_SENSORS:
|
||||
continue
|
||||
device_info: DeviceInfo = {
|
||||
ATTR_IDENTIFIERS: {(DOMAIN, device_id)},
|
||||
ATTR_MANUFACTURER: "Maxim Integrated",
|
||||
ATTR_MODEL: device_type,
|
||||
ATTR_NAME: device_id,
|
||||
}
|
||||
for description in DEVICE_BINARY_SENSORS[family]:
|
||||
device_file = os.path.join(
|
||||
os.path.split(device["path"])[0], description.key
|
||||
)
|
||||
device_file = os.path.join(os.path.split(device.path)[0], description.key)
|
||||
name = f"{device_id} {description.name}"
|
||||
entities.append(
|
||||
OneWireProxyBinarySensor(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue