Make adding new device in unifiprotect callback functions (#111054)
This commit is contained in:
parent
7eb6614818
commit
b1cbf9840a
11 changed files with 22 additions and 11 deletions
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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]
|
||||
|
||||
|
|
|
@ -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
|
||||
):
|
||||
|
|
|
@ -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)])
|
||||
|
||||
|
|
|
@ -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
|
||||
):
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue