mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Reolink auto add new cameras/chimes (#126268)
This commit is contained in:
parent
e15ae6bea3
commit
85ae66d276
@ -9,6 +9,7 @@ import logging
|
|||||||
from reolink_aio.api import RETRY_ATTEMPTS
|
from reolink_aio.api import RETRY_ATTEMPTS
|
||||||
from reolink_aio.exceptions import CredentialsInvalidError, ReolinkError
|
from reolink_aio.exceptions import CredentialsInvalidError, ReolinkError
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, Platform
|
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
@ -102,6 +103,12 @@ async def async_setup_entry(
|
|||||||
async with asyncio.timeout(host.api.timeout * (RETRY_ATTEMPTS + 2)):
|
async with asyncio.timeout(host.api.timeout * (RETRY_ATTEMPTS + 2)):
|
||||||
await host.renew()
|
await host.renew()
|
||||||
|
|
||||||
|
if host.api.new_devices and config_entry.state == ConfigEntryState.LOADED:
|
||||||
|
# Their are new cameras/chimes connected, reload to add them.
|
||||||
|
hass.async_create_task(
|
||||||
|
hass.config_entries.async_reload(config_entry.entry_id)
|
||||||
|
)
|
||||||
|
|
||||||
async def async_check_firmware_update() -> None:
|
async def async_check_firmware_update() -> None:
|
||||||
"""Check for firmware updates."""
|
"""Check for firmware updates."""
|
||||||
async with asyncio.timeout(host.api.timeout * (RETRY_ATTEMPTS + 2)):
|
async with asyncio.timeout(host.api.timeout * (RETRY_ATTEMPTS + 2)):
|
||||||
|
@ -80,6 +80,7 @@ def reolink_connect_class() -> Generator[MagicMock]:
|
|||||||
host_mock.protocol = "rtsp"
|
host_mock.protocol = "rtsp"
|
||||||
host_mock.channels = [0]
|
host_mock.channels = [0]
|
||||||
host_mock.stream_channels = [0]
|
host_mock.stream_channels = [0]
|
||||||
|
host_mock.new_devices = False
|
||||||
host_mock.sw_version_update_required = False
|
host_mock.sw_version_update_required = False
|
||||||
host_mock.hardware_version = "IPC_00000"
|
host_mock.hardware_version = "IPC_00000"
|
||||||
host_mock.sw_version = "v1.0.0.0.0.0000"
|
host_mock.sw_version = "v1.0.0.0.0.0000"
|
||||||
|
@ -600,3 +600,24 @@ async def test_firmware_repair_issue(
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert (DOMAIN, "firmware_update_host") in issue_registry.issues
|
assert (DOMAIN, "firmware_update_host") in issue_registry.issues
|
||||||
|
|
||||||
|
|
||||||
|
async def test_new_device_discovered(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
freezer: FrozenDateTimeFactory,
|
||||||
|
reolink_connect: MagicMock,
|
||||||
|
config_entry: MockConfigEntry,
|
||||||
|
) -> None:
|
||||||
|
"""Test the entry is reloaded when a new camera or chime is detected."""
|
||||||
|
with patch("homeassistant.components.reolink.PLATFORMS", [Platform.SWITCH]):
|
||||||
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert reolink_connect.logout.call_count == 0
|
||||||
|
reolink_connect.new_devices = True
|
||||||
|
|
||||||
|
freezer.tick(DEVICE_UPDATE_INTERVAL)
|
||||||
|
async_fire_time_changed(hass)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert reolink_connect.logout.call_count == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user