Make adding new device in unifiprotect callback functions (#111054)

This commit is contained in:
J. Nick Koston 2024-02-20 23:47:31 -06:00 committed by GitHub
parent 7eb6614818
commit b1cbf9840a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 22 additions and 11 deletions

View file

@ -591,7 +591,8 @@ async def async_setup_entry(
"""Set up binary sensors for UniFi Protect integration."""
data: ProtectData = hass.data[DOMAIN][entry.entry_id]
async def _add_new_device(device: ProtectAdoptableDeviceModel) -> None:
@callback
def _add_new_device(device: ProtectAdoptableDeviceModel) -> None:
entities: list[ProtectDeviceEntity] = async_all_device_entities(
data,
ProtectDeviceBinarySensor,

View file

@ -113,7 +113,8 @@ async def async_setup_entry(
"""Discover devices on a UniFi Protect NVR."""
data: ProtectData = hass.data[DOMAIN][entry.entry_id]
async def _add_new_device(device: ProtectAdoptableDeviceModel) -> None:
@callback
def _add_new_device(device: ProtectAdoptableDeviceModel) -> None:
entities = async_all_device_entities(
data,
ProtectButton,

View file

@ -113,7 +113,8 @@ async def async_setup_entry(
"""Discover cameras on a UniFi Protect NVR."""
data: ProtectData = hass.data[DOMAIN][entry.entry_id]
async def _add_new_device(device: ProtectAdoptableDeviceModel) -> None:
@callback
def _add_new_device(device: ProtectAdoptableDeviceModel) -> None:
if not isinstance(device, UFPCamera):
return # type: ignore[unreachable]

View file

@ -33,7 +33,8 @@ async def async_setup_entry(
"""Set up lights for UniFi Protect integration."""
data: ProtectData = hass.data[DOMAIN][entry.entry_id]
async def _add_new_device(device: ProtectAdoptableDeviceModel) -> None:
@callback
def _add_new_device(device: ProtectAdoptableDeviceModel) -> None:
if device.model is ModelType.LIGHT and device.can_write(
data.api.bootstrap.auth_user
):

View file

@ -34,7 +34,8 @@ async def async_setup_entry(
"""Set up locks on a UniFi Protect NVR."""
data: ProtectData = hass.data[DOMAIN][entry.entry_id]
async def _add_new_device(device: ProtectAdoptableDeviceModel) -> None:
@callback
def _add_new_device(device: ProtectAdoptableDeviceModel) -> None:
if isinstance(device, Doorlock):
async_add_entities([ProtectLock(data, device)])

View file

@ -46,7 +46,8 @@ async def async_setup_entry(
"""Discover cameras with speakers on a UniFi Protect NVR."""
data: ProtectData = hass.data[DOMAIN][entry.entry_id]
async def _add_new_device(device: ProtectAdoptableDeviceModel) -> None:
@callback
def _add_new_device(device: ProtectAdoptableDeviceModel) -> None:
if isinstance(device, Camera) and (
device.has_speaker or device.has_removable_speaker
):

View file

@ -211,7 +211,8 @@ async def async_setup_entry(
"""Set up number entities for UniFi Protect integration."""
data: ProtectData = hass.data[DOMAIN][entry.entry_id]
async def _add_new_device(device: ProtectAdoptableDeviceModel) -> None:
@callback
def _add_new_device(device: ProtectAdoptableDeviceModel) -> None:
entities = async_all_device_entities(
data,
ProtectNumbers,

View file

@ -306,7 +306,8 @@ async def async_setup_entry(
"""Set up number entities for UniFi Protect integration."""
data: ProtectData = hass.data[DOMAIN][entry.entry_id]
async def _add_new_device(device: ProtectAdoptableDeviceModel) -> None:
@callback
def _add_new_device(device: ProtectAdoptableDeviceModel) -> None:
entities = async_all_device_entities(
data,
ProtectSelects,

View file

@ -617,7 +617,8 @@ async def async_setup_entry(
"""Set up sensors for UniFi Protect integration."""
data: ProtectData = hass.data[DOMAIN][entry.entry_id]
async def _add_new_device(device: ProtectAdoptableDeviceModel) -> None:
@callback
def _add_new_device(device: ProtectAdoptableDeviceModel) -> None:
entities = async_all_device_entities(
data,
ProtectDeviceSensor,

View file

@ -442,7 +442,8 @@ async def async_setup_entry(
"""Set up sensors for UniFi Protect integration."""
data: ProtectData = hass.data[DOMAIN][entry.entry_id]
async def _add_new_device(device: ProtectAdoptableDeviceModel) -> None:
@callback
def _add_new_device(device: ProtectAdoptableDeviceModel) -> None:
entities = async_all_device_entities(
data,
ProtectSwitch,

View file

@ -61,7 +61,8 @@ async def async_setup_entry(
"""Set up sensors for UniFi Protect integration."""
data: ProtectData = hass.data[DOMAIN][entry.entry_id]
async def _add_new_device(device: ProtectAdoptableDeviceModel) -> None:
@callback
def _add_new_device(device: ProtectAdoptableDeviceModel) -> None:
entities = async_all_device_entities(
data,
ProtectDeviceText,