mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Update Reolink config entry port info if needed (#128589)
This commit is contained in:
parent
5580c3fda0
commit
2d90ffcbf0
@ -10,7 +10,7 @@ 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.config_entries import ConfigEntryState
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, Platform
|
from homeassistant.const import CONF_PORT, 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
|
||||||
from homeassistant.helpers import (
|
from homeassistant.helpers import (
|
||||||
@ -22,7 +22,7 @@ from homeassistant.helpers.device_registry import format_mac
|
|||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import CONF_USE_HTTPS, DOMAIN
|
||||||
from .exceptions import PasswordIncompatible, ReolinkException, UserNotAdmin
|
from .exceptions import PasswordIncompatible, ReolinkException, UserNotAdmin
|
||||||
from .host import ReolinkHost
|
from .host import ReolinkHost
|
||||||
from .services import async_setup_services
|
from .services import async_setup_services
|
||||||
@ -83,6 +83,24 @@ async def async_setup_entry(
|
|||||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, host.stop)
|
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, host.stop)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# update the port info if needed for the next time
|
||||||
|
if (
|
||||||
|
host.api.port != config_entry.data[CONF_PORT]
|
||||||
|
or host.api.use_https != config_entry.data[CONF_USE_HTTPS]
|
||||||
|
):
|
||||||
|
_LOGGER.warning(
|
||||||
|
"HTTP(s) port of Reolink %s, changed from %s to %s",
|
||||||
|
host.api.nvr_name,
|
||||||
|
config_entry.data[CONF_PORT],
|
||||||
|
host.api.port,
|
||||||
|
)
|
||||||
|
data = {
|
||||||
|
**config_entry.data,
|
||||||
|
CONF_PORT: host.api.port,
|
||||||
|
CONF_USE_HTTPS: host.api.use_https,
|
||||||
|
}
|
||||||
|
hass.config_entries.async_update_entry(config_entry, data=data)
|
||||||
|
|
||||||
async def async_device_config_update() -> None:
|
async def async_device_config_update() -> None:
|
||||||
"""Update the host state cache and renew the ONVIF-subscription."""
|
"""Update the host state cache and renew the ONVIF-subscription."""
|
||||||
async with asyncio.timeout(host.api.timeout * (RETRY_ATTEMPTS + 2)):
|
async with asyncio.timeout(host.api.timeout * (RETRY_ATTEMPTS + 2)):
|
||||||
|
@ -17,7 +17,7 @@ from homeassistant.components.reolink import (
|
|||||||
from homeassistant.components.reolink.const import DOMAIN
|
from homeassistant.components.reolink.const import DOMAIN
|
||||||
from homeassistant.config import async_process_ha_core_config
|
from homeassistant.config import async_process_ha_core_config
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
from homeassistant.const import STATE_OFF, STATE_UNAVAILABLE, Platform
|
from homeassistant.const import CONF_PORT, STATE_OFF, STATE_UNAVAILABLE, Platform
|
||||||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
|
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
|
||||||
from homeassistant.helpers import (
|
from homeassistant.helpers import (
|
||||||
device_registry as dr,
|
device_registry as dr,
|
||||||
@ -31,6 +31,7 @@ from .conftest import (
|
|||||||
TEST_HOST_MODEL,
|
TEST_HOST_MODEL,
|
||||||
TEST_MAC,
|
TEST_MAC,
|
||||||
TEST_NVR_NAME,
|
TEST_NVR_NAME,
|
||||||
|
TEST_PORT,
|
||||||
TEST_UID,
|
TEST_UID,
|
||||||
TEST_UID_CAM,
|
TEST_UID_CAM,
|
||||||
)
|
)
|
||||||
@ -623,3 +624,18 @@ async def test_new_device_discovered(
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert reolink_connect.logout.call_count == 1
|
assert reolink_connect.logout.call_count == 1
|
||||||
|
|
||||||
|
|
||||||
|
async def test_port_changed(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
reolink_connect: MagicMock,
|
||||||
|
config_entry: MockConfigEntry,
|
||||||
|
) -> None:
|
||||||
|
"""Test config_entry port update when it has changed during initial login."""
|
||||||
|
assert config_entry.data[CONF_PORT] == TEST_PORT
|
||||||
|
reolink_connect.port = 4567
|
||||||
|
|
||||||
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert config_entry.data[CONF_PORT] == 4567
|
||||||
|
Loading…
x
Reference in New Issue
Block a user