Coverage for custom_components/appliance_autonotify/compat.py: 100%
7 statements
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-28 12:19 +0000
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-28 12:19 +0000
1"""Schema validation library, for the range of Home Assistant versions supported
3Home Assistant 2026.10 replaced voluptuous with probatio, aliasing `voluptuous` to it at runtime
4so that `import voluptuous` carries on working. Earlier versions, supported here until they are
5more than 6 months old, only have voluptuous.
7Home Assistant 2026.8 also gave each device a single config entry, with devices of different entries linked by the
8identifiers and connections they share. Before that, the same identifiers would add the entry to the appliance's own
9device, so an appliance's device is only made where devices are linked, and earlier versions go without it.
11So voluptuous is still what is imported at runtime, whichever library that turns out to be, while
12type checking is against probatio, since that is what the current Home Assistant type hints expect.
13"""
15from typing import TYPE_CHECKING
17from homeassistant.helpers import device_registry as dr
19if TYPE_CHECKING:
20 import probatio as vol
21else:
22 import voluptuous as vol
24# only there once a device belongs to a single config entry
25LINKED_DEVICES: bool = hasattr(dr.DeviceRegistry, "async_get_device_by_identifier")
28def all_devices(registry: dr.DeviceRegistry) -> list[dr.DeviceEntry]:
29 """Every device, which iterating the registry's devices gives in later releases, where before it gave their ids, the
30 mapping now deprecated"""
31 return [
32 device if isinstance(device, dr.DeviceEntry) else registry.devices[device] # type: ignore[index,unused-ignore]
33 for device in registry.devices
34 ]
37__all__ = ["LINKED_DEVICES", "all_devices", "vol"]