Add 100% coverage of Reolink button platform (#124380)
* Add 100% button coverage * review comments * fix * Use SERVICE_PRESS constant * Use DOMAIN instead of const.DOMAIN * styling * User entity_registry_enabled_by_default fixture * fixes * Split out ptz_move test * use SERVICE_PTZ_MOVE constant
This commit is contained in:
parent
fb5afff9d5
commit
4b111008df
7 changed files with 164 additions and 57 deletions
|
@ -10,8 +10,9 @@ from reolink_aio.exceptions import ApiError, CredentialsInvalidError, ReolinkErr
|
|||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import dhcp
|
||||
from homeassistant.components.reolink import DEVICE_UPDATE_INTERVAL, const
|
||||
from homeassistant.components.reolink import DEVICE_UPDATE_INTERVAL
|
||||
from homeassistant.components.reolink.config_flow import DEFAULT_PROTOCOL
|
||||
from homeassistant.components.reolink.const import CONF_USE_HTTPS, DOMAIN
|
||||
from homeassistant.components.reolink.exceptions import ReolinkWebhookException
|
||||
from homeassistant.components.reolink.host import DEFAULT_TIMEOUT
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
|
@ -50,7 +51,7 @@ async def test_config_flow_manual_success(
|
|||
) -> None:
|
||||
"""Successful flow manually initialized by the user."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
const.DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
|
@ -73,7 +74,7 @@ async def test_config_flow_manual_success(
|
|||
CONF_USERNAME: TEST_USERNAME,
|
||||
CONF_PASSWORD: TEST_PASSWORD,
|
||||
CONF_PORT: TEST_PORT,
|
||||
const.CONF_USE_HTTPS: TEST_USE_HTTPS,
|
||||
CONF_USE_HTTPS: TEST_USE_HTTPS,
|
||||
}
|
||||
assert result["options"] == {
|
||||
CONF_PROTOCOL: DEFAULT_PROTOCOL,
|
||||
|
@ -85,7 +86,7 @@ async def test_config_flow_errors(
|
|||
) -> None:
|
||||
"""Successful flow manually initialized by the user after some errors."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
const.DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
|
@ -206,7 +207,7 @@ async def test_config_flow_errors(
|
|||
CONF_PASSWORD: TEST_PASSWORD,
|
||||
CONF_HOST: TEST_HOST,
|
||||
CONF_PORT: TEST_PORT,
|
||||
const.CONF_USE_HTTPS: TEST_USE_HTTPS,
|
||||
CONF_USE_HTTPS: TEST_USE_HTTPS,
|
||||
},
|
||||
)
|
||||
|
||||
|
@ -217,7 +218,7 @@ async def test_config_flow_errors(
|
|||
CONF_USERNAME: TEST_USERNAME,
|
||||
CONF_PASSWORD: TEST_PASSWORD,
|
||||
CONF_PORT: TEST_PORT,
|
||||
const.CONF_USE_HTTPS: TEST_USE_HTTPS,
|
||||
CONF_USE_HTTPS: TEST_USE_HTTPS,
|
||||
}
|
||||
assert result["options"] == {
|
||||
CONF_PROTOCOL: DEFAULT_PROTOCOL,
|
||||
|
@ -227,14 +228,14 @@ async def test_config_flow_errors(
|
|||
async def test_options_flow(hass: HomeAssistant, mock_setup_entry: MagicMock) -> None:
|
||||
"""Test specifying non default settings using options flow."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=const.DOMAIN,
|
||||
domain=DOMAIN,
|
||||
unique_id=format_mac(TEST_MAC),
|
||||
data={
|
||||
CONF_HOST: TEST_HOST,
|
||||
CONF_USERNAME: TEST_USERNAME,
|
||||
CONF_PASSWORD: TEST_PASSWORD,
|
||||
CONF_PORT: TEST_PORT,
|
||||
const.CONF_USE_HTTPS: TEST_USE_HTTPS,
|
||||
CONF_USE_HTTPS: TEST_USE_HTTPS,
|
||||
},
|
||||
options={
|
||||
CONF_PROTOCOL: "rtsp",
|
||||
|
@ -267,14 +268,14 @@ async def test_change_connection_settings(
|
|||
) -> None:
|
||||
"""Test changing connection settings by issuing a second user config flow."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=const.DOMAIN,
|
||||
domain=DOMAIN,
|
||||
unique_id=format_mac(TEST_MAC),
|
||||
data={
|
||||
CONF_HOST: TEST_HOST,
|
||||
CONF_USERNAME: TEST_USERNAME,
|
||||
CONF_PASSWORD: TEST_PASSWORD,
|
||||
CONF_PORT: TEST_PORT,
|
||||
const.CONF_USE_HTTPS: TEST_USE_HTTPS,
|
||||
CONF_USE_HTTPS: TEST_USE_HTTPS,
|
||||
},
|
||||
options={
|
||||
CONF_PROTOCOL: DEFAULT_PROTOCOL,
|
||||
|
@ -284,7 +285,7 @@ async def test_change_connection_settings(
|
|||
config_entry.add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
const.DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
|
@ -310,14 +311,14 @@ async def test_change_connection_settings(
|
|||
async def test_reauth(hass: HomeAssistant, mock_setup_entry: MagicMock) -> None:
|
||||
"""Test a reauth flow."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=const.DOMAIN,
|
||||
domain=DOMAIN,
|
||||
unique_id=format_mac(TEST_MAC),
|
||||
data={
|
||||
CONF_HOST: TEST_HOST,
|
||||
CONF_USERNAME: TEST_USERNAME,
|
||||
CONF_PASSWORD: TEST_PASSWORD,
|
||||
CONF_PORT: TEST_PORT,
|
||||
const.CONF_USE_HTTPS: TEST_USE_HTTPS,
|
||||
CONF_USE_HTTPS: TEST_USE_HTTPS,
|
||||
},
|
||||
options={
|
||||
CONF_PROTOCOL: DEFAULT_PROTOCOL,
|
||||
|
@ -367,7 +368,7 @@ async def test_dhcp_flow(hass: HomeAssistant, mock_setup_entry: MagicMock) -> No
|
|||
)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
const.DOMAIN, context={"source": config_entries.SOURCE_DHCP}, data=dhcp_data
|
||||
DOMAIN, context={"source": config_entries.SOURCE_DHCP}, data=dhcp_data
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
|
@ -389,7 +390,7 @@ async def test_dhcp_flow(hass: HomeAssistant, mock_setup_entry: MagicMock) -> No
|
|||
CONF_USERNAME: TEST_USERNAME,
|
||||
CONF_PASSWORD: TEST_PASSWORD,
|
||||
CONF_PORT: TEST_PORT,
|
||||
const.CONF_USE_HTTPS: TEST_USE_HTTPS,
|
||||
CONF_USE_HTTPS: TEST_USE_HTTPS,
|
||||
}
|
||||
assert result["options"] == {
|
||||
CONF_PROTOCOL: DEFAULT_PROTOCOL,
|
||||
|
@ -442,14 +443,14 @@ async def test_dhcp_ip_update(
|
|||
) -> None:
|
||||
"""Test dhcp discovery aborts if already configured where the IP is updated if appropriate."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=const.DOMAIN,
|
||||
domain=DOMAIN,
|
||||
unique_id=format_mac(TEST_MAC),
|
||||
data={
|
||||
CONF_HOST: TEST_HOST,
|
||||
CONF_USERNAME: TEST_USERNAME,
|
||||
CONF_PASSWORD: TEST_PASSWORD,
|
||||
CONF_PORT: TEST_PORT,
|
||||
const.CONF_USE_HTTPS: TEST_USE_HTTPS,
|
||||
CONF_USE_HTTPS: TEST_USE_HTTPS,
|
||||
},
|
||||
options={
|
||||
CONF_PROTOCOL: DEFAULT_PROTOCOL,
|
||||
|
@ -479,7 +480,7 @@ async def test_dhcp_ip_update(
|
|||
setattr(reolink_connect, attr, value)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
const.DOMAIN, context={"source": config_entries.SOURCE_DHCP}, data=dhcp_data
|
||||
DOMAIN, context={"source": config_entries.SOURCE_DHCP}, data=dhcp_data
|
||||
)
|
||||
|
||||
for host in host_call_list:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue