From b1cbf9840a3006895755e810b85f327922718a9a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 20 Feb 2024 23:47:31 -0600 Subject: [PATCH] Make adding new device in unifiprotect callback functions (#111054) --- homeassistant/components/unifiprotect/binary_sensor.py | 3 ++- homeassistant/components/unifiprotect/button.py | 3 ++- homeassistant/components/unifiprotect/camera.py | 3 ++- homeassistant/components/unifiprotect/light.py | 3 ++- homeassistant/components/unifiprotect/lock.py | 3 ++- homeassistant/components/unifiprotect/media_player.py | 3 ++- homeassistant/components/unifiprotect/number.py | 3 ++- homeassistant/components/unifiprotect/select.py | 3 ++- homeassistant/components/unifiprotect/sensor.py | 3 ++- homeassistant/components/unifiprotect/switch.py | 3 ++- homeassistant/components/unifiprotect/text.py | 3 ++- 11 files changed, 22 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/unifiprotect/binary_sensor.py b/homeassistant/components/unifiprotect/binary_sensor.py index 66767224de2..4408075468f 100644 --- a/homeassistant/components/unifiprotect/binary_sensor.py +++ b/homeassistant/components/unifiprotect/binary_sensor.py @@ -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, diff --git a/homeassistant/components/unifiprotect/button.py b/homeassistant/components/unifiprotect/button.py index cee4280507d..2046c12ddbd 100644 --- a/homeassistant/components/unifiprotect/button.py +++ b/homeassistant/components/unifiprotect/button.py @@ -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, diff --git a/homeassistant/components/unifiprotect/camera.py b/homeassistant/components/unifiprotect/camera.py index 6d82e2fc989..ca7abaac3c4 100644 --- a/homeassistant/components/unifiprotect/camera.py +++ b/homeassistant/components/unifiprotect/camera.py @@ -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] diff --git a/homeassistant/components/unifiprotect/light.py b/homeassistant/components/unifiprotect/light.py index 485e715ea39..27b7157bf2b 100644 --- a/homeassistant/components/unifiprotect/light.py +++ b/homeassistant/components/unifiprotect/light.py @@ -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 ): diff --git a/homeassistant/components/unifiprotect/lock.py b/homeassistant/components/unifiprotect/lock.py index 57ade8ad220..5bfa65fccf9 100644 --- a/homeassistant/components/unifiprotect/lock.py +++ b/homeassistant/components/unifiprotect/lock.py @@ -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)]) diff --git a/homeassistant/components/unifiprotect/media_player.py b/homeassistant/components/unifiprotect/media_player.py index e0f247eef72..82e2ccd0be0 100644 --- a/homeassistant/components/unifiprotect/media_player.py +++ b/homeassistant/components/unifiprotect/media_player.py @@ -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 ): diff --git a/homeassistant/components/unifiprotect/number.py b/homeassistant/components/unifiprotect/number.py index 90201da98d8..68ae3a66d10 100644 --- a/homeassistant/components/unifiprotect/number.py +++ b/homeassistant/components/unifiprotect/number.py @@ -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, diff --git a/homeassistant/components/unifiprotect/select.py b/homeassistant/components/unifiprotect/select.py index eed49ac87e7..5611ba79eca 100644 --- a/homeassistant/components/unifiprotect/select.py +++ b/homeassistant/components/unifiprotect/select.py @@ -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, diff --git a/homeassistant/components/unifiprotect/sensor.py b/homeassistant/components/unifiprotect/sensor.py index 5a52b45b62d..c4d1f8a530d 100644 --- a/homeassistant/components/unifiprotect/sensor.py +++ b/homeassistant/components/unifiprotect/sensor.py @@ -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, diff --git a/homeassistant/components/unifiprotect/switch.py b/homeassistant/components/unifiprotect/switch.py index ace769d7c43..64890e17d4d 100644 --- a/homeassistant/components/unifiprotect/switch.py +++ b/homeassistant/components/unifiprotect/switch.py @@ -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, diff --git a/homeassistant/components/unifiprotect/text.py b/homeassistant/components/unifiprotect/text.py index cfc4ad5702f..2aebcfa1da9 100644 --- a/homeassistant/components/unifiprotect/text.py +++ b/homeassistant/components/unifiprotect/text.py @@ -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,