Coverage for custom_components/camera_autonotify/device.py: 88%

16 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-22 21:32 +0000

1"""The device of each camera's entry, linked to the device the Frigate integration has for the camera""" 

2 

3from __future__ import annotations 

4 

5from typing import TYPE_CHECKING 

6 

7from homeassistant.const import CONF_DEVICE_ID 

8from homeassistant.core import HomeAssistant, callback 

9from homeassistant.helpers import area_registry as ar 

10from homeassistant.helpers import device_registry as dr 

11 

12from .compat import LINKED_DEVICES 

13 

14if TYPE_CHECKING: 

15 from homeassistant.config_entries import ConfigEntry 

16 

17 

18@callback 

19def async_register_device(hass: HomeAssistant, entry: ConfigEntry, name: str) -> dr.DeviceEntry | None: 

20 """A device for the entry, so it's listed under the entry on the integration's page, and shown alongside the 

21 camera's own device, linked to it by the identifiers they have in common, and none at all before devices were 

22 linked""" 

23 if not LINKED_DEVICES: 

24 return None 

25 source = dr.async_get(hass).async_get(entry.data.get(CONF_DEVICE_ID, "")) 

26 if not isinstance(source, dr.DeviceEntry): 

27 # gone from Frigate since it was set up 

28 return None 

29 area = ar.async_get(hass).async_get_area(source.area_id) if source.area_id else None 

30 return dr.async_get(hass).async_get_or_create( 

31 config_entry_id=entry.entry_id, 

32 identifiers=set(source.identifiers), 

33 connections=set(source.connections), 

34 name=name, 

35 manufacturer=source.manufacturer, 

36 model=source.model, 

37 suggested_area=area.name if area is not None else None, 

38 )