Add type hints to integration tests (part 24) (#88307)
This commit is contained in:
parent
f3e4783a5e
commit
aa50096a31
49 changed files with 627 additions and 359 deletions
|
@ -13,7 +13,7 @@ from tests.common import MockConfigEntry, async_fire_time_changed
|
||||||
|
|
||||||
async def test_upnp_binary_sensors(
|
async def test_upnp_binary_sensors(
|
||||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry
|
hass: HomeAssistant, mock_config_entry: MockConfigEntry
|
||||||
):
|
) -> None:
|
||||||
"""Test normal sensors."""
|
"""Test normal sensors."""
|
||||||
# First poll.
|
# First poll.
|
||||||
wan_status_state = hass.states.get("binary_sensor.mock_name_wan_status")
|
wan_status_state = hass.states.get("binary_sensor.mock_name_wan_status")
|
||||||
|
|
|
@ -39,7 +39,7 @@ from tests.common import MockConfigEntry
|
||||||
"mock_get_source_ip",
|
"mock_get_source_ip",
|
||||||
"mock_mac_address_from_host",
|
"mock_mac_address_from_host",
|
||||||
)
|
)
|
||||||
async def test_flow_ssdp(hass: HomeAssistant):
|
async def test_flow_ssdp(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow: discovered + configured through ssdp."""
|
"""Test config flow: discovered + configured through ssdp."""
|
||||||
# Discovered via step ssdp.
|
# Discovered via step ssdp.
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -73,7 +73,7 @@ async def test_flow_ssdp(hass: HomeAssistant):
|
||||||
"mock_get_source_ip",
|
"mock_get_source_ip",
|
||||||
"mock_mac_address_from_host",
|
"mock_mac_address_from_host",
|
||||||
)
|
)
|
||||||
async def test_flow_ssdp_ignore(hass: HomeAssistant):
|
async def test_flow_ssdp_ignore(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow: discovered + ignore through ssdp."""
|
"""Test config flow: discovered + ignore through ssdp."""
|
||||||
# Discovered via step ssdp.
|
# Discovered via step ssdp.
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -103,7 +103,7 @@ async def test_flow_ssdp_ignore(hass: HomeAssistant):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_get_source_ip")
|
@pytest.mark.usefixtures("mock_get_source_ip")
|
||||||
async def test_flow_ssdp_incomplete_discovery(hass: HomeAssistant):
|
async def test_flow_ssdp_incomplete_discovery(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow: incomplete discovery through ssdp."""
|
"""Test config flow: incomplete discovery through ssdp."""
|
||||||
# Discovered via step ssdp.
|
# Discovered via step ssdp.
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -124,7 +124,7 @@ async def test_flow_ssdp_incomplete_discovery(hass: HomeAssistant):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_get_source_ip")
|
@pytest.mark.usefixtures("mock_get_source_ip")
|
||||||
async def test_flow_ssdp_non_igd_device(hass: HomeAssistant):
|
async def test_flow_ssdp_non_igd_device(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow: incomplete discovery through ssdp."""
|
"""Test config flow: incomplete discovery through ssdp."""
|
||||||
# Discovered via step ssdp.
|
# Discovered via step ssdp.
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -150,7 +150,7 @@ async def test_flow_ssdp_non_igd_device(hass: HomeAssistant):
|
||||||
"mock_get_source_ip",
|
"mock_get_source_ip",
|
||||||
"mock_no_mac_address_from_host",
|
"mock_no_mac_address_from_host",
|
||||||
)
|
)
|
||||||
async def test_flow_ssdp_no_mac_address(hass: HomeAssistant):
|
async def test_flow_ssdp_no_mac_address(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow: discovered + configured through ssdp."""
|
"""Test config flow: discovered + configured through ssdp."""
|
||||||
# Discovered via step ssdp.
|
# Discovered via step ssdp.
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -179,7 +179,7 @@ async def test_flow_ssdp_no_mac_address(hass: HomeAssistant):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_mac_address_from_host")
|
@pytest.mark.usefixtures("mock_mac_address_from_host")
|
||||||
async def test_flow_ssdp_discovery_changed_udn_match_mac(hass: HomeAssistant):
|
async def test_flow_ssdp_discovery_changed_udn_match_mac(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow: discovery through ssdp, same device, but new UDN, matched on mac address."""
|
"""Test config flow: discovery through ssdp, same device, but new UDN, matched on mac address."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -211,7 +211,7 @@ async def test_flow_ssdp_discovery_changed_udn_match_mac(hass: HomeAssistant):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_mac_address_from_host")
|
@pytest.mark.usefixtures("mock_mac_address_from_host")
|
||||||
async def test_flow_ssdp_discovery_changed_udn_match_host(hass: HomeAssistant):
|
async def test_flow_ssdp_discovery_changed_udn_match_host(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow: discovery through ssdp, same device, but new UDN, matched on mac address."""
|
"""Test config flow: discovery through ssdp, same device, but new UDN, matched on mac address."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -247,7 +247,9 @@ async def test_flow_ssdp_discovery_changed_udn_match_host(hass: HomeAssistant):
|
||||||
"mock_setup_entry",
|
"mock_setup_entry",
|
||||||
"mock_get_source_ip",
|
"mock_get_source_ip",
|
||||||
)
|
)
|
||||||
async def test_flow_ssdp_discovery_changed_udn_but_st_differs(hass: HomeAssistant):
|
async def test_flow_ssdp_discovery_changed_udn_but_st_differs(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
) -> None:
|
||||||
"""Test config flow: discovery through ssdp, same device, but new UDN, and different ST, so not matched --> new discovery."""
|
"""Test config flow: discovery through ssdp, same device, but new UDN, and different ST, so not matched --> new discovery."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -301,7 +303,7 @@ async def test_flow_ssdp_discovery_changed_udn_but_st_differs(hass: HomeAssistan
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_mac_address_from_host")
|
@pytest.mark.usefixtures("mock_mac_address_from_host")
|
||||||
async def test_flow_ssdp_discovery_changed_location(hass: HomeAssistant):
|
async def test_flow_ssdp_discovery_changed_location(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow: discovery through ssdp, same device, but new location."""
|
"""Test config flow: discovery through ssdp, same device, but new location."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -335,7 +337,7 @@ async def test_flow_ssdp_discovery_changed_location(hass: HomeAssistant):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_mac_address_from_host")
|
@pytest.mark.usefixtures("mock_mac_address_from_host")
|
||||||
async def test_flow_ssdp_discovery_ignored_entry(hass: HomeAssistant):
|
async def test_flow_ssdp_discovery_ignored_entry(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow: discovery through ssdp, same device, but new UDN, matched on mac address."""
|
"""Test config flow: discovery through ssdp, same device, but new UDN, matched on mac address."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -361,7 +363,9 @@ async def test_flow_ssdp_discovery_ignored_entry(hass: HomeAssistant):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_mac_address_from_host")
|
@pytest.mark.usefixtures("mock_mac_address_from_host")
|
||||||
async def test_flow_ssdp_discovery_changed_udn_ignored_entry(hass: HomeAssistant):
|
async def test_flow_ssdp_discovery_changed_udn_ignored_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
) -> None:
|
||||||
"""Test config flow: discovery through ssdp, same device, but new UDN, matched on mac address, entry ignored."""
|
"""Test config flow: discovery through ssdp, same device, but new UDN, matched on mac address, entry ignored."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -397,7 +401,7 @@ async def test_flow_ssdp_discovery_changed_udn_ignored_entry(hass: HomeAssistant
|
||||||
"mock_get_source_ip",
|
"mock_get_source_ip",
|
||||||
"mock_mac_address_from_host",
|
"mock_mac_address_from_host",
|
||||||
)
|
)
|
||||||
async def test_flow_user(hass: HomeAssistant):
|
async def test_flow_user(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow: discovered + configured through user."""
|
"""Test config flow: discovered + configured through user."""
|
||||||
# Discovered via step user.
|
# Discovered via step user.
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -429,7 +433,7 @@ async def test_flow_user(hass: HomeAssistant):
|
||||||
"mock_get_source_ip",
|
"mock_get_source_ip",
|
||||||
"mock_mac_address_from_host",
|
"mock_mac_address_from_host",
|
||||||
)
|
)
|
||||||
async def test_flow_user_no_discovery(hass: HomeAssistant):
|
async def test_flow_user_no_discovery(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow: user, but no discovery."""
|
"""Test config flow: user, but no discovery."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
|
|
@ -21,7 +21,7 @@ from tests.common import MockConfigEntry
|
||||||
@pytest.mark.usefixtures(
|
@pytest.mark.usefixtures(
|
||||||
"ssdp_instant_discovery", "mock_get_source_ip", "mock_mac_address_from_host"
|
"ssdp_instant_discovery", "mock_get_source_ip", "mock_mac_address_from_host"
|
||||||
)
|
)
|
||||||
async def test_async_setup_entry_default(hass: HomeAssistant):
|
async def test_async_setup_entry_default(hass: HomeAssistant) -> None:
|
||||||
"""Test async_setup_entry."""
|
"""Test async_setup_entry."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -43,7 +43,7 @@ async def test_async_setup_entry_default(hass: HomeAssistant):
|
||||||
@pytest.mark.usefixtures(
|
@pytest.mark.usefixtures(
|
||||||
"ssdp_instant_discovery", "mock_get_source_ip", "mock_no_mac_address_from_host"
|
"ssdp_instant_discovery", "mock_get_source_ip", "mock_no_mac_address_from_host"
|
||||||
)
|
)
|
||||||
async def test_async_setup_entry_default_no_mac_address(hass: HomeAssistant):
|
async def test_async_setup_entry_default_no_mac_address(hass: HomeAssistant) -> None:
|
||||||
"""Test async_setup_entry."""
|
"""Test async_setup_entry."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
|
|
@ -11,7 +11,9 @@ import homeassistant.util.dt as dt_util
|
||||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||||
|
|
||||||
|
|
||||||
async def test_upnp_sensors(hass: HomeAssistant, mock_config_entry: MockConfigEntry):
|
async def test_upnp_sensors(
|
||||||
|
hass: HomeAssistant, mock_config_entry: MockConfigEntry
|
||||||
|
) -> None:
|
||||||
"""Test sensors."""
|
"""Test sensors."""
|
||||||
# First poll.
|
# First poll.
|
||||||
assert hass.states.get("sensor.mock_name_b_received").state == "0"
|
assert hass.states.get("sensor.mock_name_b_received").state == "0"
|
||||||
|
|
|
@ -29,7 +29,7 @@ from tests.common import MockConfigEntry, async_fire_time_changed
|
||||||
|
|
||||||
async def test_reauthentication_trigger_in_setup(
|
async def test_reauthentication_trigger_in_setup(
|
||||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
):
|
) -> None:
|
||||||
"""Test reauthentication trigger."""
|
"""Test reauthentication trigger."""
|
||||||
mock_config_entry = MockConfigEntry(**MOCK_UPTIMEROBOT_CONFIG_ENTRY_DATA)
|
mock_config_entry = MockConfigEntry(**MOCK_UPTIMEROBOT_CONFIG_ENTRY_DATA)
|
||||||
mock_config_entry.add_to_hass(hass)
|
mock_config_entry.add_to_hass(hass)
|
||||||
|
@ -61,7 +61,7 @@ async def test_reauthentication_trigger_in_setup(
|
||||||
|
|
||||||
async def test_reauthentication_trigger_key_read_only(
|
async def test_reauthentication_trigger_key_read_only(
|
||||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
):
|
) -> None:
|
||||||
"""Test reauthentication trigger."""
|
"""Test reauthentication trigger."""
|
||||||
mock_config_entry = MockConfigEntry(
|
mock_config_entry = MockConfigEntry(
|
||||||
**MOCK_UPTIMEROBOT_CONFIG_ENTRY_DATA_KEY_READ_ONLY
|
**MOCK_UPTIMEROBOT_CONFIG_ENTRY_DATA_KEY_READ_ONLY
|
||||||
|
@ -94,7 +94,7 @@ async def test_reauthentication_trigger_key_read_only(
|
||||||
|
|
||||||
async def test_reauthentication_trigger_after_setup(
|
async def test_reauthentication_trigger_after_setup(
|
||||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
):
|
) -> None:
|
||||||
"""Test reauthentication trigger."""
|
"""Test reauthentication trigger."""
|
||||||
mock_config_entry = await setup_uptimerobot_integration(hass)
|
mock_config_entry = await setup_uptimerobot_integration(hass)
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ async def test_reauthentication_trigger_after_setup(
|
||||||
assert flow["context"]["entry_id"] == mock_config_entry.entry_id
|
assert flow["context"]["entry_id"] == mock_config_entry.entry_id
|
||||||
|
|
||||||
|
|
||||||
async def test_integration_reload(hass: HomeAssistant):
|
async def test_integration_reload(hass: HomeAssistant) -> None:
|
||||||
"""Test integration reload."""
|
"""Test integration reload."""
|
||||||
mock_entry = await setup_uptimerobot_integration(hass)
|
mock_entry = await setup_uptimerobot_integration(hass)
|
||||||
|
|
||||||
|
@ -142,7 +142,9 @@ async def test_integration_reload(hass: HomeAssistant):
|
||||||
assert hass.states.get(UPTIMEROBOT_BINARY_SENSOR_TEST_ENTITY).state == STATE_ON
|
assert hass.states.get(UPTIMEROBOT_BINARY_SENSOR_TEST_ENTITY).state == STATE_ON
|
||||||
|
|
||||||
|
|
||||||
async def test_update_errors(hass: HomeAssistant, caplog: pytest.LogCaptureFixture):
|
async def test_update_errors(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
"""Test errors during updates."""
|
"""Test errors during updates."""
|
||||||
await setup_uptimerobot_integration(hass)
|
await setup_uptimerobot_integration(hass)
|
||||||
|
|
||||||
|
@ -179,7 +181,7 @@ async def test_update_errors(hass: HomeAssistant, caplog: pytest.LogCaptureFixtu
|
||||||
assert "Error fetching uptimerobot data: test error from API" in caplog.text
|
assert "Error fetching uptimerobot data: test error from API" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
async def test_device_management(hass: HomeAssistant):
|
async def test_device_management(hass: HomeAssistant) -> None:
|
||||||
"""Test that we are adding and removing devices for monitors returned from the API."""
|
"""Test that we are adding and removing devices for monitors returned from the API."""
|
||||||
mock_entry = await setup_uptimerobot_integration(hass)
|
mock_entry = await setup_uptimerobot_integration(hass)
|
||||||
dev_reg = dr.async_get(hass)
|
dev_reg = dr.async_get(hass)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""Test UptimeRobot switch."""
|
"""Test UptimeRobot switch."""
|
||||||
|
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
from pyuptimerobot import UptimeRobotAuthenticationException
|
from pyuptimerobot import UptimeRobotAuthenticationException
|
||||||
|
|
||||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
||||||
|
@ -94,7 +94,9 @@ async def test_switch_on(hass: HomeAssistant) -> None:
|
||||||
assert entity.state == STATE_ON
|
assert entity.state == STATE_ON
|
||||||
|
|
||||||
|
|
||||||
async def test_authentication_error(hass: HomeAssistant, caplog) -> None:
|
async def test_authentication_error(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
"""Test authentication error turning switch on/off."""
|
"""Test authentication error turning switch on/off."""
|
||||||
await setup_uptimerobot_integration(hass)
|
await setup_uptimerobot_integration(hass)
|
||||||
|
|
||||||
|
@ -117,7 +119,9 @@ async def test_authentication_error(hass: HomeAssistant, caplog) -> None:
|
||||||
assert config_entry_reauth.assert_called
|
assert config_entry_reauth.assert_called
|
||||||
|
|
||||||
|
|
||||||
async def test_refresh_data(hass: HomeAssistant, caplog) -> None:
|
async def test_refresh_data(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
"""Test authentication error turning switch on/off."""
|
"""Test authentication error turning switch on/off."""
|
||||||
await setup_uptimerobot_integration(hass)
|
await setup_uptimerobot_integration(hass)
|
||||||
|
|
||||||
|
@ -137,7 +141,9 @@ async def test_refresh_data(hass: HomeAssistant, caplog) -> None:
|
||||||
assert coordinator_refresh.assert_called
|
assert coordinator_refresh.assert_called
|
||||||
|
|
||||||
|
|
||||||
async def test_switch_api_failure(hass: HomeAssistant, caplog) -> None:
|
async def test_switch_api_failure(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
"""Test general exception turning switch on/off."""
|
"""Test general exception turning switch on/off."""
|
||||||
await setup_uptimerobot_integration(hass)
|
await setup_uptimerobot_integration(hass)
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,9 @@ def mock_venv():
|
||||||
not sys.platform.startswith("linux"),
|
not sys.platform.startswith("linux"),
|
||||||
reason="Only works on linux",
|
reason="Only works on linux",
|
||||||
)
|
)
|
||||||
async def test_observer_discovery(hass, hass_ws_client, venv):
|
async def test_observer_discovery(
|
||||||
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, venv
|
||||||
|
) -> None:
|
||||||
"""Test that observer can discover a device without raising an exception."""
|
"""Test that observer can discover a device without raising an exception."""
|
||||||
new_usb = [{"domain": "test1", "vid": "3039"}]
|
new_usb = [{"domain": "test1", "vid": "3039"}]
|
||||||
|
|
||||||
|
@ -113,7 +115,9 @@ async def test_observer_discovery(hass, hass_ws_client, venv):
|
||||||
not sys.platform.startswith("linux"),
|
not sys.platform.startswith("linux"),
|
||||||
reason="Only works on linux",
|
reason="Only works on linux",
|
||||||
)
|
)
|
||||||
async def test_removal_by_observer_before_started(hass, operating_system):
|
async def test_removal_by_observer_before_started(
|
||||||
|
hass: HomeAssistant, operating_system
|
||||||
|
) -> None:
|
||||||
"""Test a device is removed by the observer before started."""
|
"""Test a device is removed by the observer before started."""
|
||||||
|
|
||||||
async def _mock_monitor_observer_callback(callback):
|
async def _mock_monitor_observer_callback(callback):
|
||||||
|
@ -198,8 +202,8 @@ async def test_discovered_by_websocket_scan(
|
||||||
|
|
||||||
|
|
||||||
async def test_discovered_by_websocket_scan_limited_by_description_matcher(
|
async def test_discovered_by_websocket_scan_limited_by_description_matcher(
|
||||||
hass, hass_ws_client
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||||
):
|
) -> None:
|
||||||
"""Test a device is discovered from websocket scan is limited by the description matcher."""
|
"""Test a device is discovered from websocket scan is limited by the description matcher."""
|
||||||
new_usb = [
|
new_usb = [
|
||||||
{"domain": "test1", "vid": "3039", "pid": "3039", "description": "*2652*"}
|
{"domain": "test1", "vid": "3039", "pid": "3039", "description": "*2652*"}
|
||||||
|
@ -279,8 +283,8 @@ async def test_most_targeted_matcher_wins(
|
||||||
|
|
||||||
|
|
||||||
async def test_discovered_by_websocket_scan_rejected_by_description_matcher(
|
async def test_discovered_by_websocket_scan_rejected_by_description_matcher(
|
||||||
hass, hass_ws_client
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||||
):
|
) -> None:
|
||||||
"""Test a device is discovered from websocket scan rejected by the description matcher."""
|
"""Test a device is discovered from websocket scan rejected by the description matcher."""
|
||||||
new_usb = [
|
new_usb = [
|
||||||
{"domain": "test1", "vid": "3039", "pid": "3039", "description": "*not_it*"}
|
{"domain": "test1", "vid": "3039", "pid": "3039", "description": "*not_it*"}
|
||||||
|
@ -318,8 +322,8 @@ async def test_discovered_by_websocket_scan_rejected_by_description_matcher(
|
||||||
|
|
||||||
|
|
||||||
async def test_discovered_by_websocket_scan_limited_by_serial_number_matcher(
|
async def test_discovered_by_websocket_scan_limited_by_serial_number_matcher(
|
||||||
hass, hass_ws_client
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||||
):
|
) -> None:
|
||||||
"""Test a device is discovered from websocket scan is limited by the serial_number matcher."""
|
"""Test a device is discovered from websocket scan is limited by the serial_number matcher."""
|
||||||
new_usb = [
|
new_usb = [
|
||||||
{
|
{
|
||||||
|
@ -363,8 +367,8 @@ async def test_discovered_by_websocket_scan_limited_by_serial_number_matcher(
|
||||||
|
|
||||||
|
|
||||||
async def test_discovered_by_websocket_scan_rejected_by_serial_number_matcher(
|
async def test_discovered_by_websocket_scan_rejected_by_serial_number_matcher(
|
||||||
hass, hass_ws_client
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||||
):
|
) -> None:
|
||||||
"""Test a device is discovered from websocket scan is rejected by the serial_number matcher."""
|
"""Test a device is discovered from websocket scan is rejected by the serial_number matcher."""
|
||||||
new_usb = [
|
new_usb = [
|
||||||
{"domain": "test1", "vid": "3039", "pid": "3039", "serial_number": "123*"}
|
{"domain": "test1", "vid": "3039", "pid": "3039", "serial_number": "123*"}
|
||||||
|
@ -402,8 +406,8 @@ async def test_discovered_by_websocket_scan_rejected_by_serial_number_matcher(
|
||||||
|
|
||||||
|
|
||||||
async def test_discovered_by_websocket_scan_limited_by_manufacturer_matcher(
|
async def test_discovered_by_websocket_scan_limited_by_manufacturer_matcher(
|
||||||
hass, hass_ws_client
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||||
):
|
) -> None:
|
||||||
"""Test a device is discovered from websocket scan is limited by the manufacturer matcher."""
|
"""Test a device is discovered from websocket scan is limited by the manufacturer matcher."""
|
||||||
new_usb = [
|
new_usb = [
|
||||||
{
|
{
|
||||||
|
@ -447,8 +451,8 @@ async def test_discovered_by_websocket_scan_limited_by_manufacturer_matcher(
|
||||||
|
|
||||||
|
|
||||||
async def test_discovered_by_websocket_scan_rejected_by_manufacturer_matcher(
|
async def test_discovered_by_websocket_scan_rejected_by_manufacturer_matcher(
|
||||||
hass, hass_ws_client
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||||
):
|
) -> None:
|
||||||
"""Test a device is discovered from websocket scan is rejected by the manufacturer matcher."""
|
"""Test a device is discovered from websocket scan is rejected by the manufacturer matcher."""
|
||||||
new_usb = [
|
new_usb = [
|
||||||
{
|
{
|
||||||
|
@ -491,8 +495,8 @@ async def test_discovered_by_websocket_scan_rejected_by_manufacturer_matcher(
|
||||||
|
|
||||||
|
|
||||||
async def test_discovered_by_websocket_rejected_with_empty_serial_number_only(
|
async def test_discovered_by_websocket_rejected_with_empty_serial_number_only(
|
||||||
hass, hass_ws_client
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||||
):
|
) -> None:
|
||||||
"""Test a device is discovered from websocket is rejected with empty serial number."""
|
"""Test a device is discovered from websocket is rejected with empty serial number."""
|
||||||
new_usb = [
|
new_usb = [
|
||||||
{"domain": "test1", "vid": "3039", "pid": "3039", "serial_number": "123*"}
|
{"domain": "test1", "vid": "3039", "pid": "3039", "serial_number": "123*"}
|
||||||
|
@ -643,8 +647,8 @@ async def test_discovered_by_websocket_no_vid_pid(
|
||||||
|
|
||||||
@pytest.mark.parametrize("exception_type", [ImportError, OSError])
|
@pytest.mark.parametrize("exception_type", [ImportError, OSError])
|
||||||
async def test_non_matching_discovered_by_scanner_after_started(
|
async def test_non_matching_discovered_by_scanner_after_started(
|
||||||
hass, exception_type, hass_ws_client
|
hass: HomeAssistant, exception_type, hass_ws_client: WebSocketGenerator
|
||||||
):
|
) -> None:
|
||||||
"""Test a websocket scan that does not match."""
|
"""Test a websocket scan that does not match."""
|
||||||
new_usb = [{"domain": "test1", "vid": "4444", "pid": "4444"}]
|
new_usb = [{"domain": "test1", "vid": "4444", "pid": "4444"}]
|
||||||
|
|
||||||
|
@ -684,8 +688,8 @@ async def test_non_matching_discovered_by_scanner_after_started(
|
||||||
reason="Only works on linux",
|
reason="Only works on linux",
|
||||||
)
|
)
|
||||||
async def test_observer_on_wsl_fallback_without_throwing_exception(
|
async def test_observer_on_wsl_fallback_without_throwing_exception(
|
||||||
hass, hass_ws_client, venv
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, venv
|
||||||
):
|
) -> None:
|
||||||
"""Test that observer on WSL failure results in fallback to scanning without raising an exception."""
|
"""Test that observer on WSL failure results in fallback to scanning without raising an exception."""
|
||||||
new_usb = [{"domain": "test1", "vid": "3039"}]
|
new_usb = [{"domain": "test1", "vid": "3039"}]
|
||||||
|
|
||||||
|
@ -725,7 +729,9 @@ async def test_observer_on_wsl_fallback_without_throwing_exception(
|
||||||
not sys.platform.startswith("linux"),
|
not sys.platform.startswith("linux"),
|
||||||
reason="Only works on linux",
|
reason="Only works on linux",
|
||||||
)
|
)
|
||||||
async def test_not_discovered_by_observer_before_started_on_docker(hass, docker):
|
async def test_not_discovered_by_observer_before_started_on_docker(
|
||||||
|
hass: HomeAssistant, docker
|
||||||
|
) -> None:
|
||||||
"""Test a device is not discovered since observer is not running on bare docker."""
|
"""Test a device is not discovered since observer is not running on bare docker."""
|
||||||
|
|
||||||
async def _mock_monitor_observer_callback(callback):
|
async def _mock_monitor_observer_callback(callback):
|
||||||
|
@ -902,7 +908,9 @@ async def test_async_is_plugged_in(
|
||||||
{"description": "A description"},
|
{"description": "A description"},
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_async_is_plugged_in_case_enforcement(hass, matcher):
|
async def test_async_is_plugged_in_case_enforcement(
|
||||||
|
hass: HomeAssistant, matcher
|
||||||
|
) -> None:
|
||||||
"""Test `async_is_plugged_in` throws an error when incorrect cases are used."""
|
"""Test `async_is_plugged_in` throws an error when incorrect cases are used."""
|
||||||
|
|
||||||
new_usb = [{"domain": "test1", "vid": "ABCD"}]
|
new_usb = [{"domain": "test1", "vid": "ABCD"}]
|
||||||
|
|
|
@ -66,7 +66,7 @@ async def test_restore_state(hass: HomeAssistant) -> None:
|
||||||
"select.energy_bill",
|
"select.energy_bill",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
async def test_services(hass, meter):
|
async def test_services(hass: HomeAssistant, meter) -> None:
|
||||||
"""Test energy sensor reset service."""
|
"""Test energy sensor reset service."""
|
||||||
config = {
|
config = {
|
||||||
"utility_meter": {
|
"utility_meter": {
|
||||||
|
|
|
@ -83,7 +83,7 @@ def set_utc(hass):
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
async def test_state(hass, yaml_config, config_entry_config):
|
async def test_state(hass: HomeAssistant, yaml_config, config_entry_config) -> None:
|
||||||
"""Test utility sensor state."""
|
"""Test utility sensor state."""
|
||||||
if yaml_config:
|
if yaml_config:
|
||||||
assert await async_setup_component(hass, DOMAIN, yaml_config)
|
assert await async_setup_component(hass, DOMAIN, yaml_config)
|
||||||
|
@ -245,7 +245,7 @@ async def test_state(hass, yaml_config, config_entry_config):
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
async def test_not_unique_tariffs(hass, yaml_config):
|
async def test_not_unique_tariffs(hass: HomeAssistant, yaml_config) -> None:
|
||||||
"""Test utility sensor state initializtion."""
|
"""Test utility sensor state initializtion."""
|
||||||
assert not await async_setup_component(hass, DOMAIN, yaml_config)
|
assert not await async_setup_component(hass, DOMAIN, yaml_config)
|
||||||
|
|
||||||
|
@ -278,7 +278,7 @@ async def test_not_unique_tariffs(hass, yaml_config):
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
async def test_init(hass, yaml_config, config_entry_config):
|
async def test_init(hass: HomeAssistant, yaml_config, config_entry_config) -> None:
|
||||||
"""Test utility sensor state initializtion."""
|
"""Test utility sensor state initializtion."""
|
||||||
if yaml_config:
|
if yaml_config:
|
||||||
assert await async_setup_component(hass, DOMAIN, yaml_config)
|
assert await async_setup_component(hass, DOMAIN, yaml_config)
|
||||||
|
@ -389,7 +389,7 @@ async def test_unique_id(hass: HomeAssistant) -> None:
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
async def test_entity_name(hass, yaml_config, entity_id, name):
|
async def test_entity_name(hass: HomeAssistant, yaml_config, entity_id, name) -> None:
|
||||||
"""Test utility sensor state initializtion."""
|
"""Test utility sensor state initializtion."""
|
||||||
assert await async_setup_component(hass, DOMAIN, yaml_config)
|
assert await async_setup_component(hass, DOMAIN, yaml_config)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -445,7 +445,9 @@ async def test_entity_name(hass, yaml_config, entity_id, name):
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
async def test_device_class(hass, yaml_config, config_entry_configs):
|
async def test_device_class(
|
||||||
|
hass: HomeAssistant, yaml_config, config_entry_configs
|
||||||
|
) -> None:
|
||||||
"""Test utility device_class."""
|
"""Test utility device_class."""
|
||||||
if yaml_config:
|
if yaml_config:
|
||||||
assert await async_setup_component(hass, DOMAIN, yaml_config)
|
assert await async_setup_component(hass, DOMAIN, yaml_config)
|
||||||
|
@ -519,7 +521,9 @@ async def test_device_class(hass, yaml_config, config_entry_configs):
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
async def test_restore_state(hass, yaml_config, config_entry_config):
|
async def test_restore_state(
|
||||||
|
hass: HomeAssistant, yaml_config, config_entry_config
|
||||||
|
) -> None:
|
||||||
"""Test utility sensor restore state."""
|
"""Test utility sensor restore state."""
|
||||||
# Home assistant is not runnit yet
|
# Home assistant is not runnit yet
|
||||||
hass.state = CoreState.not_running
|
hass.state = CoreState.not_running
|
||||||
|
@ -676,7 +680,9 @@ async def test_restore_state(hass, yaml_config, config_entry_config):
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
async def test_net_consumption(hass, yaml_config, config_entry_config):
|
async def test_net_consumption(
|
||||||
|
hass: HomeAssistant, yaml_config, config_entry_config
|
||||||
|
) -> None:
|
||||||
"""Test utility sensor state."""
|
"""Test utility sensor state."""
|
||||||
if yaml_config:
|
if yaml_config:
|
||||||
assert await async_setup_component(hass, DOMAIN, yaml_config)
|
assert await async_setup_component(hass, DOMAIN, yaml_config)
|
||||||
|
@ -744,7 +750,12 @@ async def test_net_consumption(hass, yaml_config, config_entry_config):
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
async def test_non_net_consumption(hass, yaml_config, config_entry_config, caplog):
|
async def test_non_net_consumption(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
yaml_config,
|
||||||
|
config_entry_config,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
) -> None:
|
||||||
"""Test utility sensor state."""
|
"""Test utility sensor state."""
|
||||||
if yaml_config:
|
if yaml_config:
|
||||||
assert await async_setup_component(hass, DOMAIN, yaml_config)
|
assert await async_setup_component(hass, DOMAIN, yaml_config)
|
||||||
|
@ -823,7 +834,12 @@ async def test_non_net_consumption(hass, yaml_config, config_entry_config, caplo
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
async def test_delta_values(hass, yaml_config, config_entry_config, caplog):
|
async def test_delta_values(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
yaml_config,
|
||||||
|
config_entry_config,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
) -> None:
|
||||||
"""Test utility meter "delta_values" mode."""
|
"""Test utility meter "delta_values" mode."""
|
||||||
# Home assistant is not runnit yet
|
# Home assistant is not runnit yet
|
||||||
hass.state = CoreState.not_running
|
hass.state = CoreState.not_running
|
||||||
|
|
|
@ -15,6 +15,7 @@ from homeassistant.components.camera import (
|
||||||
async_get_image,
|
async_get_image,
|
||||||
async_get_stream_source,
|
async_get_stream_source,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.entity_registry import async_get as async_get_entity_registry
|
from homeassistant.helpers.entity_registry import async_get as async_get_entity_registry
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
@ -109,7 +110,7 @@ def camera_v313_fixture():
|
||||||
yield camera
|
yield camera
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_full_config(hass, mock_remote, camera_info):
|
async def test_setup_full_config(hass: HomeAssistant, mock_remote, camera_info) -> None:
|
||||||
"""Test the setup with full configuration."""
|
"""Test the setup with full configuration."""
|
||||||
config = {
|
config = {
|
||||||
"platform": "uvc",
|
"platform": "uvc",
|
||||||
|
@ -161,7 +162,7 @@ async def test_setup_full_config(hass, mock_remote, camera_info):
|
||||||
assert entity_entry.unique_id == "id2"
|
assert entity_entry.unique_id == "id2"
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_partial_config(hass, mock_remote):
|
async def test_setup_partial_config(hass: HomeAssistant, mock_remote) -> None:
|
||||||
"""Test the setup with partial configuration."""
|
"""Test the setup with partial configuration."""
|
||||||
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
|
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
|
||||||
|
|
||||||
|
@ -195,7 +196,7 @@ async def test_setup_partial_config(hass, mock_remote):
|
||||||
assert entity_entry.unique_id == "id2"
|
assert entity_entry.unique_id == "id2"
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_partial_config_v31x(hass, mock_remote):
|
async def test_setup_partial_config_v31x(hass: HomeAssistant, mock_remote) -> None:
|
||||||
"""Test the setup with a v3.1.x server."""
|
"""Test the setup with a v3.1.x server."""
|
||||||
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
|
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
|
||||||
mock_remote.return_value.server_version = (3, 1, 3)
|
mock_remote.return_value.server_version = (3, 1, 3)
|
||||||
|
@ -238,7 +239,9 @@ async def test_setup_partial_config_v31x(hass, mock_remote):
|
||||||
{"platform": "uvc", "nvr": "foo", "key": "secret", "port": "invalid"},
|
{"platform": "uvc", "nvr": "foo", "key": "secret", "port": "invalid"},
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_setup_incomplete_config(hass, mock_remote, config):
|
async def test_setup_incomplete_config(
|
||||||
|
hass: HomeAssistant, mock_remote, config
|
||||||
|
) -> None:
|
||||||
"""Test the setup with incomplete or invalid configuration."""
|
"""Test the setup with incomplete or invalid configuration."""
|
||||||
assert await async_setup_component(hass, "camera", config)
|
assert await async_setup_component(hass, "camera", config)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -256,7 +259,9 @@ async def test_setup_incomplete_config(hass, mock_remote, config):
|
||||||
(requests.exceptions.ConnectionError, 2),
|
(requests.exceptions.ConnectionError, 2),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_setup_nvr_errors_during_indexing(hass, mock_remote, error, ready_states):
|
async def test_setup_nvr_errors_during_indexing(
|
||||||
|
hass: HomeAssistant, mock_remote, error, ready_states
|
||||||
|
) -> None:
|
||||||
"""Set up test for NVR errors during indexing."""
|
"""Set up test for NVR errors during indexing."""
|
||||||
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
|
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
|
||||||
now = utcnow()
|
now = utcnow()
|
||||||
|
@ -288,8 +293,8 @@ async def test_setup_nvr_errors_during_indexing(hass, mock_remote, error, ready_
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_setup_nvr_errors_during_initialization(
|
async def test_setup_nvr_errors_during_initialization(
|
||||||
hass, mock_remote, error, ready_states
|
hass: HomeAssistant, mock_remote, error, ready_states
|
||||||
):
|
) -> None:
|
||||||
"""Set up test for NVR errors during initialization."""
|
"""Set up test for NVR errors during initialization."""
|
||||||
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
|
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
|
||||||
now = utcnow()
|
now = utcnow()
|
||||||
|
@ -314,7 +319,7 @@ async def test_setup_nvr_errors_during_initialization(
|
||||||
assert len(camera_states) == ready_states
|
assert len(camera_states) == ready_states
|
||||||
|
|
||||||
|
|
||||||
async def test_properties(hass, mock_remote):
|
async def test_properties(hass: HomeAssistant, mock_remote) -> None:
|
||||||
"""Test the properties."""
|
"""Test the properties."""
|
||||||
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
|
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
|
||||||
assert await async_setup_component(hass, "camera", {"camera": config})
|
assert await async_setup_component(hass, "camera", {"camera": config})
|
||||||
|
@ -334,7 +339,9 @@ async def test_properties(hass, mock_remote):
|
||||||
assert state.attributes["supported_features"] == CameraEntityFeature.STREAM
|
assert state.attributes["supported_features"] == CameraEntityFeature.STREAM
|
||||||
|
|
||||||
|
|
||||||
async def test_motion_recording_mode_properties(hass, mock_remote):
|
async def test_motion_recording_mode_properties(
|
||||||
|
hass: HomeAssistant, mock_remote
|
||||||
|
) -> None:
|
||||||
"""Test the properties."""
|
"""Test the properties."""
|
||||||
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
|
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
|
||||||
now = utcnow()
|
now = utcnow()
|
||||||
|
@ -399,7 +406,7 @@ async def test_motion_recording_mode_properties(hass, mock_remote):
|
||||||
assert state.state == STATE_RECORDING
|
assert state.state == STATE_RECORDING
|
||||||
|
|
||||||
|
|
||||||
async def test_stream(hass, mock_remote):
|
async def test_stream(hass: HomeAssistant, mock_remote) -> None:
|
||||||
"""Test the RTSP stream URI."""
|
"""Test the RTSP stream URI."""
|
||||||
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
|
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
|
||||||
assert await async_setup_component(hass, "camera", {"camera": config})
|
assert await async_setup_component(hass, "camera", {"camera": config})
|
||||||
|
@ -410,7 +417,7 @@ async def test_stream(hass, mock_remote):
|
||||||
assert stream_source == "rtsp://foo:7447/uuid_rtspchannel_0"
|
assert stream_source == "rtsp://foo:7447/uuid_rtspchannel_0"
|
||||||
|
|
||||||
|
|
||||||
async def test_login(hass, mock_remote, camera_v320):
|
async def test_login(hass: HomeAssistant, mock_remote, camera_v320) -> None:
|
||||||
"""Test the login."""
|
"""Test the login."""
|
||||||
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
|
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
|
||||||
assert await async_setup_component(hass, "camera", {"camera": config})
|
assert await async_setup_component(hass, "camera", {"camera": config})
|
||||||
|
@ -425,7 +432,7 @@ async def test_login(hass, mock_remote, camera_v320):
|
||||||
assert image.content == "test_image"
|
assert image.content == "test_image"
|
||||||
|
|
||||||
|
|
||||||
async def test_login_v31x(hass, mock_remote, camera_v313):
|
async def test_login_v31x(hass: HomeAssistant, mock_remote, camera_v313) -> None:
|
||||||
"""Test login with v3.1.x server."""
|
"""Test login with v3.1.x server."""
|
||||||
mock_remote.return_value.server_version = (3, 1, 3)
|
mock_remote.return_value.server_version = (3, 1, 3)
|
||||||
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
|
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
|
||||||
|
@ -444,7 +451,9 @@ async def test_login_v31x(hass, mock_remote, camera_v313):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"error", [OSError, camera.CameraConnectError, camera.CameraAuthError]
|
"error", [OSError, camera.CameraConnectError, camera.CameraAuthError]
|
||||||
)
|
)
|
||||||
async def test_login_tries_both_addrs_and_caches(hass, mock_remote, camera_v320, error):
|
async def test_login_tries_both_addrs_and_caches(
|
||||||
|
hass: HomeAssistant, mock_remote, camera_v320, error
|
||||||
|
) -> None:
|
||||||
"""Test the login tries."""
|
"""Test the login tries."""
|
||||||
responses = [0]
|
responses = [0]
|
||||||
|
|
||||||
|
@ -492,7 +501,9 @@ async def test_login_tries_both_addrs_and_caches(hass, mock_remote, camera_v320,
|
||||||
assert image.content == "test_image"
|
assert image.content == "test_image"
|
||||||
|
|
||||||
|
|
||||||
async def test_login_fails_both_properly(hass, mock_remote, camera_v320):
|
async def test_login_fails_both_properly(
|
||||||
|
hass: HomeAssistant, mock_remote, camera_v320
|
||||||
|
) -> None:
|
||||||
"""Test if login fails properly."""
|
"""Test if login fails properly."""
|
||||||
camera_v320.return_value.login.side_effect = OSError
|
camera_v320.return_value.login.side_effect = OSError
|
||||||
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
|
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
|
||||||
|
@ -513,8 +524,13 @@ async def test_login_fails_both_properly(hass, mock_remote, camera_v320):
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_camera_image_error(
|
async def test_camera_image_error(
|
||||||
hass, mock_remote, camera_v320, source_error, raised_error, snapshot_calls
|
hass: HomeAssistant,
|
||||||
):
|
mock_remote,
|
||||||
|
camera_v320,
|
||||||
|
source_error,
|
||||||
|
raised_error,
|
||||||
|
snapshot_calls,
|
||||||
|
) -> None:
|
||||||
"""Test the camera image error."""
|
"""Test the camera image error."""
|
||||||
camera_v320.return_value.get_snapshot.side_effect = source_error
|
camera_v320.return_value.get_snapshot.side_effect = source_error
|
||||||
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
|
config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
|
||||||
|
@ -527,7 +543,9 @@ async def test_camera_image_error(
|
||||||
assert camera_v320.return_value.get_snapshot.call_count == snapshot_calls
|
assert camera_v320.return_value.get_snapshot.call_count == snapshot_calls
|
||||||
|
|
||||||
|
|
||||||
async def test_enable_disable_motion_detection(hass, mock_remote, camera_info):
|
async def test_enable_disable_motion_detection(
|
||||||
|
hass: HomeAssistant, mock_remote, camera_info
|
||||||
|
) -> None:
|
||||||
"""Test enable and disable motion detection."""
|
"""Test enable and disable motion detection."""
|
||||||
|
|
||||||
def set_recordmode(uuid, mode):
|
def set_recordmode(uuid, mode):
|
||||||
|
|
|
@ -6,7 +6,7 @@ from homeassistant.components.device_automation import DeviceAutomationType
|
||||||
from homeassistant.components.vacuum import DOMAIN
|
from homeassistant.components.vacuum import DOMAIN
|
||||||
from homeassistant.const import EntityCategory
|
from homeassistant.const import EntityCategory
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
from homeassistant.helpers.entity_registry import RegistryEntryHider
|
from homeassistant.helpers.entity_registry import RegistryEntryHider
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
@ -19,7 +19,11 @@ from tests.common import (
|
||||||
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
|
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
|
||||||
|
|
||||||
|
|
||||||
async def test_get_actions(hass, device_registry, entity_registry):
|
async def test_get_actions(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
) -> None:
|
||||||
"""Test we get the expected actions from a vacuum."""
|
"""Test we get the expected actions from a vacuum."""
|
||||||
config_entry = MockConfigEntry(domain="test", data={})
|
config_entry = MockConfigEntry(domain="test", data={})
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
@ -57,12 +61,12 @@ async def test_get_actions(hass, device_registry, entity_registry):
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
async def test_get_actions_hidden_auxiliary(
|
async def test_get_actions_hidden_auxiliary(
|
||||||
hass,
|
hass: HomeAssistant,
|
||||||
device_registry,
|
device_registry: dr.DeviceRegistry,
|
||||||
entity_registry,
|
entity_registry: er.EntityRegistry,
|
||||||
hidden_by,
|
hidden_by,
|
||||||
entity_category,
|
entity_category,
|
||||||
):
|
) -> None:
|
||||||
"""Test we get the expected actions from a hidden or auxiliary entity."""
|
"""Test we get the expected actions from a hidden or auxiliary entity."""
|
||||||
config_entry = MockConfigEntry(domain="test", data={})
|
config_entry = MockConfigEntry(domain="test", data={})
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
|
|
@ -10,7 +10,8 @@ from homeassistant.components.vacuum import (
|
||||||
STATE_RETURNING,
|
STATE_RETURNING,
|
||||||
)
|
)
|
||||||
from homeassistant.const import EntityCategory
|
from homeassistant.const import EntityCategory
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
from homeassistant.helpers.entity_registry import RegistryEntryHider
|
from homeassistant.helpers.entity_registry import RegistryEntryHider
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
@ -29,7 +30,11 @@ def calls(hass):
|
||||||
return async_mock_service(hass, "test", "automation")
|
return async_mock_service(hass, "test", "automation")
|
||||||
|
|
||||||
|
|
||||||
async def test_get_conditions(hass, device_registry, entity_registry):
|
async def test_get_conditions(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
) -> None:
|
||||||
"""Test we get the expected conditions from a vacuum."""
|
"""Test we get the expected conditions from a vacuum."""
|
||||||
config_entry = MockConfigEntry(domain="test", data={})
|
config_entry = MockConfigEntry(domain="test", data={})
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
@ -67,12 +72,12 @@ async def test_get_conditions(hass, device_registry, entity_registry):
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
async def test_get_conditions_hidden_auxiliary(
|
async def test_get_conditions_hidden_auxiliary(
|
||||||
hass,
|
hass: HomeAssistant,
|
||||||
device_registry,
|
device_registry: dr.DeviceRegistry,
|
||||||
entity_registry,
|
entity_registry: er.EntityRegistry,
|
||||||
hidden_by,
|
hidden_by,
|
||||||
entity_category,
|
entity_category,
|
||||||
):
|
) -> None:
|
||||||
"""Test we get the expected conditions from a hidden or auxiliary entity."""
|
"""Test we get the expected conditions from a hidden or auxiliary entity."""
|
||||||
config_entry = MockConfigEntry(domain="test", data={})
|
config_entry = MockConfigEntry(domain="test", data={})
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
@ -105,7 +110,7 @@ async def test_get_conditions_hidden_auxiliary(
|
||||||
assert_lists_same(conditions, expected_conditions)
|
assert_lists_same(conditions, expected_conditions)
|
||||||
|
|
||||||
|
|
||||||
async def test_if_state(hass, calls):
|
async def test_if_state(hass: HomeAssistant, calls) -> None:
|
||||||
"""Test for turn_on and turn_off conditions."""
|
"""Test for turn_on and turn_off conditions."""
|
||||||
hass.states.async_set("vacuum.entity", STATE_DOCKED)
|
hass.states.async_set("vacuum.entity", STATE_DOCKED)
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,8 @@ import homeassistant.components.automation as automation
|
||||||
from homeassistant.components.device_automation import DeviceAutomationType
|
from homeassistant.components.device_automation import DeviceAutomationType
|
||||||
from homeassistant.components.vacuum import DOMAIN, STATE_CLEANING, STATE_DOCKED
|
from homeassistant.components.vacuum import DOMAIN, STATE_CLEANING, STATE_DOCKED
|
||||||
from homeassistant.const import EntityCategory
|
from homeassistant.const import EntityCategory
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
from homeassistant.helpers.entity_registry import RegistryEntryHider
|
from homeassistant.helpers.entity_registry import RegistryEntryHider
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
@ -29,7 +30,11 @@ def calls(hass):
|
||||||
return async_mock_service(hass, "test", "automation")
|
return async_mock_service(hass, "test", "automation")
|
||||||
|
|
||||||
|
|
||||||
async def test_get_triggers(hass, device_registry, entity_registry):
|
async def test_get_triggers(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
) -> None:
|
||||||
"""Test we get the expected triggers from a vacuum."""
|
"""Test we get the expected triggers from a vacuum."""
|
||||||
config_entry = MockConfigEntry(domain="test", data={})
|
config_entry = MockConfigEntry(domain="test", data={})
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
@ -67,12 +72,12 @@ async def test_get_triggers(hass, device_registry, entity_registry):
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
async def test_get_triggers_hidden_auxiliary(
|
async def test_get_triggers_hidden_auxiliary(
|
||||||
hass,
|
hass: HomeAssistant,
|
||||||
device_registry,
|
device_registry: dr.DeviceRegistry,
|
||||||
entity_registry,
|
entity_registry: er.EntityRegistry,
|
||||||
hidden_by,
|
hidden_by,
|
||||||
entity_category,
|
entity_category,
|
||||||
):
|
) -> None:
|
||||||
"""Test we get the expected triggers from a hidden or auxiliary entity."""
|
"""Test we get the expected triggers from a hidden or auxiliary entity."""
|
||||||
config_entry = MockConfigEntry(domain="test", data={})
|
config_entry = MockConfigEntry(domain="test", data={})
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
@ -105,7 +110,11 @@ async def test_get_triggers_hidden_auxiliary(
|
||||||
assert_lists_same(triggers, expected_triggers)
|
assert_lists_same(triggers, expected_triggers)
|
||||||
|
|
||||||
|
|
||||||
async def test_get_trigger_capabilities(hass, device_registry, entity_registry):
|
async def test_get_trigger_capabilities(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
) -> None:
|
||||||
"""Test we get the expected capabilities from a vacuum device."""
|
"""Test we get the expected capabilities from a vacuum device."""
|
||||||
config_entry = MockConfigEntry(domain="test", data={})
|
config_entry = MockConfigEntry(domain="test", data={})
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
@ -132,7 +141,7 @@ async def test_get_trigger_capabilities(hass, device_registry, entity_registry):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_if_fires_on_state_change(hass, calls):
|
async def test_if_fires_on_state_change(hass: HomeAssistant, calls) -> None:
|
||||||
"""Test for turn_on and turn_off triggers firing."""
|
"""Test for turn_on and turn_off triggers firing."""
|
||||||
hass.states.async_set("vacuum.entity", STATE_DOCKED)
|
hass.states.async_set("vacuum.entity", STATE_DOCKED)
|
||||||
|
|
||||||
|
@ -200,7 +209,7 @@ async def test_if_fires_on_state_change(hass, calls):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_if_fires_on_state_change_with_for(hass, calls):
|
async def test_if_fires_on_state_change_with_for(hass: HomeAssistant, calls) -> None:
|
||||||
"""Test for triggers firing with delay."""
|
"""Test for triggers firing with delay."""
|
||||||
entity_id = f"{DOMAIN}.entity"
|
entity_id = f"{DOMAIN}.entity"
|
||||||
hass.states.async_set(entity_id, STATE_DOCKED)
|
hass.states.async_set(entity_id, STATE_DOCKED)
|
||||||
|
|
|
@ -4,11 +4,12 @@ from __future__ import annotations
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from homeassistant.components import vacuum
|
from homeassistant.components import vacuum
|
||||||
|
from homeassistant.components.recorder import Recorder
|
||||||
from homeassistant.components.recorder.db_schema import StateAttributes, States
|
from homeassistant.components.recorder.db_schema import StateAttributes, States
|
||||||
from homeassistant.components.recorder.util import session_scope
|
from homeassistant.components.recorder.util import session_scope
|
||||||
from homeassistant.components.vacuum import ATTR_FAN_SPEED_LIST
|
from homeassistant.components.vacuum import ATTR_FAN_SPEED_LIST
|
||||||
from homeassistant.const import ATTR_FRIENDLY_NAME
|
from homeassistant.const import ATTR_FRIENDLY_NAME
|
||||||
from homeassistant.core import State
|
from homeassistant.core import HomeAssistant, State
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
|
@ -16,7 +17,7 @@ from tests.common import async_fire_time_changed
|
||||||
from tests.components.recorder.common import async_wait_recording_done
|
from tests.components.recorder.common import async_wait_recording_done
|
||||||
|
|
||||||
|
|
||||||
async def test_exclude_attributes(recorder_mock, hass):
|
async def test_exclude_attributes(recorder_mock: Recorder, hass: HomeAssistant) -> None:
|
||||||
"""Test vacuum registered attributes to be excluded."""
|
"""Test vacuum registered attributes to be excluded."""
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass, vacuum.DOMAIN, {vacuum.DOMAIN: {"platform": "demo"}}
|
hass, vacuum.DOMAIN, {vacuum.DOMAIN: {"platform": "demo"}}
|
||||||
|
|
|
@ -47,7 +47,7 @@ def _now_at_13():
|
||||||
|
|
||||||
async def test_remaining_filter_returns_timestamp(
|
async def test_remaining_filter_returns_timestamp(
|
||||||
mock_entry: MockConfigEntry, hass: HomeAssistant
|
mock_entry: MockConfigEntry, hass: HomeAssistant
|
||||||
):
|
) -> None:
|
||||||
"""Test that the remaining time for filter sensor returns a timestamp."""
|
"""Test that the remaining time for filter sensor returns a timestamp."""
|
||||||
# Act
|
# Act
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -64,7 +64,7 @@ async def test_remaining_filter_returns_timestamp(
|
||||||
|
|
||||||
async def test_remaining_time_for_filter_none_returned_from_vallox(
|
async def test_remaining_time_for_filter_none_returned_from_vallox(
|
||||||
mock_entry: MockConfigEntry, hass: HomeAssistant
|
mock_entry: MockConfigEntry, hass: HomeAssistant
|
||||||
):
|
) -> None:
|
||||||
"""Test that the remaining time for filter sensor returns 'unknown' when Vallox returns None."""
|
"""Test that the remaining time for filter sensor returns 'unknown' when Vallox returns None."""
|
||||||
# Act
|
# Act
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -90,7 +90,7 @@ async def test_remaining_time_for_filter_none_returned_from_vallox(
|
||||||
)
|
)
|
||||||
async def test_remaining_time_for_filter_in_the_future(
|
async def test_remaining_time_for_filter_in_the_future(
|
||||||
mock_entry: MockConfigEntry, set_tz: tzinfo, hass: HomeAssistant
|
mock_entry: MockConfigEntry, set_tz: tzinfo, hass: HomeAssistant
|
||||||
):
|
) -> None:
|
||||||
"""Test remaining time for filter when Vallox returns a date in the future."""
|
"""Test remaining time for filter when Vallox returns a date in the future."""
|
||||||
# Arrange
|
# Arrange
|
||||||
remaining_days = 112
|
remaining_days = 112
|
||||||
|
@ -114,7 +114,7 @@ async def test_remaining_time_for_filter_in_the_future(
|
||||||
|
|
||||||
async def test_remaining_time_for_filter_today(
|
async def test_remaining_time_for_filter_today(
|
||||||
mock_entry: MockConfigEntry, hass: HomeAssistant
|
mock_entry: MockConfigEntry, hass: HomeAssistant
|
||||||
):
|
) -> None:
|
||||||
"""Test remaining time for filter when Vallox returns today."""
|
"""Test remaining time for filter when Vallox returns today."""
|
||||||
# Arrange
|
# Arrange
|
||||||
remaining_days = 0
|
remaining_days = 0
|
||||||
|
@ -138,7 +138,7 @@ async def test_remaining_time_for_filter_today(
|
||||||
|
|
||||||
async def test_remaining_time_for_filter_in_the_past(
|
async def test_remaining_time_for_filter_in_the_past(
|
||||||
mock_entry: MockConfigEntry, hass: HomeAssistant
|
mock_entry: MockConfigEntry, hass: HomeAssistant
|
||||||
):
|
) -> None:
|
||||||
"""Test remaining time for filter when Vallox returns a date in the past."""
|
"""Test remaining time for filter when Vallox returns a date in the past."""
|
||||||
# Arrange
|
# Arrange
|
||||||
remaining_days = -3
|
remaining_days = -3
|
||||||
|
@ -162,7 +162,7 @@ async def test_remaining_time_for_filter_in_the_past(
|
||||||
|
|
||||||
async def test_cell_state_sensor_heat_recovery(
|
async def test_cell_state_sensor_heat_recovery(
|
||||||
mock_entry: MockConfigEntry, hass: HomeAssistant
|
mock_entry: MockConfigEntry, hass: HomeAssistant
|
||||||
):
|
) -> None:
|
||||||
"""Test cell state sensor in heat recovery state."""
|
"""Test cell state sensor in heat recovery state."""
|
||||||
# Arrange
|
# Arrange
|
||||||
metrics = {"A_CYC_CELL_STATE": 0}
|
metrics = {"A_CYC_CELL_STATE": 0}
|
||||||
|
@ -179,7 +179,7 @@ async def test_cell_state_sensor_heat_recovery(
|
||||||
|
|
||||||
async def test_cell_state_sensor_cool_recovery(
|
async def test_cell_state_sensor_cool_recovery(
|
||||||
mock_entry: MockConfigEntry, hass: HomeAssistant
|
mock_entry: MockConfigEntry, hass: HomeAssistant
|
||||||
):
|
) -> None:
|
||||||
"""Test cell state sensor in cool recovery state."""
|
"""Test cell state sensor in cool recovery state."""
|
||||||
# Arrange
|
# Arrange
|
||||||
metrics = {"A_CYC_CELL_STATE": 1}
|
metrics = {"A_CYC_CELL_STATE": 1}
|
||||||
|
@ -196,7 +196,7 @@ async def test_cell_state_sensor_cool_recovery(
|
||||||
|
|
||||||
async def test_cell_state_sensor_bypass(
|
async def test_cell_state_sensor_bypass(
|
||||||
mock_entry: MockConfigEntry, hass: HomeAssistant
|
mock_entry: MockConfigEntry, hass: HomeAssistant
|
||||||
):
|
) -> None:
|
||||||
"""Test cell state sensor in bypass state."""
|
"""Test cell state sensor in bypass state."""
|
||||||
# Arrange
|
# Arrange
|
||||||
metrics = {"A_CYC_CELL_STATE": 2}
|
metrics = {"A_CYC_CELL_STATE": 2}
|
||||||
|
@ -213,7 +213,7 @@ async def test_cell_state_sensor_bypass(
|
||||||
|
|
||||||
async def test_cell_state_sensor_defrosting(
|
async def test_cell_state_sensor_defrosting(
|
||||||
mock_entry: MockConfigEntry, hass: HomeAssistant
|
mock_entry: MockConfigEntry, hass: HomeAssistant
|
||||||
):
|
) -> None:
|
||||||
"""Test cell state sensor in defrosting state."""
|
"""Test cell state sensor in defrosting state."""
|
||||||
# Arrange
|
# Arrange
|
||||||
metrics = {"A_CYC_CELL_STATE": 3}
|
metrics = {"A_CYC_CELL_STATE": 3}
|
||||||
|
@ -230,7 +230,7 @@ async def test_cell_state_sensor_defrosting(
|
||||||
|
|
||||||
async def test_cell_state_sensor_unknown_state(
|
async def test_cell_state_sensor_unknown_state(
|
||||||
mock_entry: MockConfigEntry, hass: HomeAssistant
|
mock_entry: MockConfigEntry, hass: HomeAssistant
|
||||||
):
|
) -> None:
|
||||||
"""Test cell state sensor in unknown state."""
|
"""Test cell state sensor in unknown state."""
|
||||||
# Arrange
|
# Arrange
|
||||||
metrics = {"A_CYC_CELL_STATE": 4}
|
metrics = {"A_CYC_CELL_STATE": 4}
|
||||||
|
|
|
@ -64,7 +64,7 @@ def mock_controller_connection_failed():
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("controller")
|
@pytest.mark.usefixtures("controller")
|
||||||
async def test_user(hass: HomeAssistant):
|
async def test_user(hass: HomeAssistant) -> None:
|
||||||
"""Test user config."""
|
"""Test user config."""
|
||||||
# simple user form
|
# simple user form
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -103,7 +103,7 @@ async def test_user(hass: HomeAssistant):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("controller_connection_failed")
|
@pytest.mark.usefixtures("controller_connection_failed")
|
||||||
async def test_user_fail(hass: HomeAssistant):
|
async def test_user_fail(hass: HomeAssistant) -> None:
|
||||||
"""Test user config."""
|
"""Test user config."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
@ -125,7 +125,7 @@ async def test_user_fail(hass: HomeAssistant):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("config_entry")
|
@pytest.mark.usefixtures("config_entry")
|
||||||
async def test_abort_if_already_setup(hass: HomeAssistant):
|
async def test_abort_if_already_setup(hass: HomeAssistant) -> None:
|
||||||
"""Test we abort if Velbus is already setup."""
|
"""Test we abort if Velbus is already setup."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
@ -139,7 +139,7 @@ async def test_abort_if_already_setup(hass: HomeAssistant):
|
||||||
|
|
||||||
@pytest.mark.usefixtures("controller")
|
@pytest.mark.usefixtures("controller")
|
||||||
@patch("serial.tools.list_ports.comports", MagicMock(return_value=[com_port()]))
|
@patch("serial.tools.list_ports.comports", MagicMock(return_value=[com_port()]))
|
||||||
async def test_flow_usb(hass: HomeAssistant):
|
async def test_flow_usb(hass: HomeAssistant) -> None:
|
||||||
"""Test usb discovery flow."""
|
"""Test usb discovery flow."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
@ -175,7 +175,7 @@ async def test_flow_usb(hass: HomeAssistant):
|
||||||
|
|
||||||
@pytest.mark.usefixtures("controller_connection_failed")
|
@pytest.mark.usefixtures("controller_connection_failed")
|
||||||
@patch("serial.tools.list_ports.comports", MagicMock(return_value=[com_port()]))
|
@patch("serial.tools.list_ports.comports", MagicMock(return_value=[com_port()]))
|
||||||
async def test_flow_usb_failed(hass: HomeAssistant):
|
async def test_flow_usb_failed(hass: HomeAssistant) -> None:
|
||||||
"""Test usb discovery flow with a failed velbus test."""
|
"""Test usb discovery flow with a failed velbus test."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
|
|
@ -13,7 +13,7 @@ from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("controller")
|
@pytest.mark.usefixtures("controller")
|
||||||
async def test_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry):
|
async def test_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
|
||||||
"""Test being able to unload an entry."""
|
"""Test being able to unload an entry."""
|
||||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -31,7 +31,7 @@ async def test_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry):
|
||||||
@pytest.mark.usefixtures("controller")
|
@pytest.mark.usefixtures("controller")
|
||||||
async def test_device_identifier_migration(
|
async def test_device_identifier_migration(
|
||||||
hass: HomeAssistant, config_entry: ConfigEntry, device_registry: dr.DeviceRegistry
|
hass: HomeAssistant, config_entry: ConfigEntry, device_registry: dr.DeviceRegistry
|
||||||
):
|
) -> None:
|
||||||
"""Test being able to unload an entry."""
|
"""Test being able to unload an entry."""
|
||||||
original_identifiers = {(DOMAIN, "module_address", "module_serial")}
|
original_identifiers = {(DOMAIN, "module_address", "module_serial")}
|
||||||
target_identifiers = {(DOMAIN, "module_address")}
|
target_identifiers = {(DOMAIN, "module_address")}
|
||||||
|
|
|
@ -13,7 +13,7 @@ from tests.common import MockConfigEntry
|
||||||
TEST_HOST = "venstartest.localdomain"
|
TEST_HOST = "venstartest.localdomain"
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_entry(hass: HomeAssistant):
|
async def test_setup_entry(hass: HomeAssistant) -> None:
|
||||||
"""Validate that setup entry also configure the client."""
|
"""Validate that setup entry also configure the client."""
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
domain=VENSTAR_DOMAIN,
|
domain=VENSTAR_DOMAIN,
|
||||||
|
@ -53,7 +53,7 @@ async def test_setup_entry(hass: HomeAssistant):
|
||||||
assert config_entry.state == ConfigEntryState.NOT_LOADED
|
assert config_entry.state == ConfigEntryState.NOT_LOADED
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_entry_exception(hass: HomeAssistant):
|
async def test_setup_entry_exception(hass: HomeAssistant) -> None:
|
||||||
"""Validate that setup entry also configure the client."""
|
"""Validate that setup entry also configure the client."""
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
domain=VENSTAR_DOMAIN,
|
domain=VENSTAR_DOMAIN,
|
||||||
|
|
|
@ -7,7 +7,7 @@ from homeassistant.core import HomeAssistant
|
||||||
from .common import setup_version_integration
|
from .common import setup_version_integration
|
||||||
|
|
||||||
|
|
||||||
async def test_version_binary_sensor_local_source(hass: HomeAssistant):
|
async def test_version_binary_sensor_local_source(hass: HomeAssistant) -> None:
|
||||||
"""Test the Version binary sensor with local source."""
|
"""Test the Version binary sensor with local source."""
|
||||||
await setup_version_integration(hass)
|
await setup_version_integration(hass)
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ async def test_version_binary_sensor_local_source(hass: HomeAssistant):
|
||||||
assert not state
|
assert not state
|
||||||
|
|
||||||
|
|
||||||
async def test_version_binary_sensor(hass: HomeAssistant):
|
async def test_version_binary_sensor(hass: HomeAssistant) -> None:
|
||||||
"""Test the Version binary sensor."""
|
"""Test the Version binary sensor."""
|
||||||
await setup_version_integration(hass, {**DEFAULT_CONFIGURATION, "source": "pypi"})
|
await setup_version_integration(hass, {**DEFAULT_CONFIGURATION, "source": "pypi"})
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ from .common import MOCK_VERSION, MOCK_VERSION_DATA, setup_version_integration
|
||||||
from tests.common import async_fire_time_changed
|
from tests.common import async_fire_time_changed
|
||||||
|
|
||||||
|
|
||||||
async def test_reload_config_entry(hass: HomeAssistant):
|
async def test_reload_config_entry(hass: HomeAssistant) -> None:
|
||||||
"""Test reloading the config entry."""
|
"""Test reloading the config entry."""
|
||||||
config_entry = await setup_version_integration(hass)
|
config_entry = await setup_version_integration(hass)
|
||||||
assert config_entry.state == config_entries.ConfigEntryState.LOADED
|
assert config_entry.state == config_entries.ConfigEntryState.LOADED
|
||||||
|
|
|
@ -9,7 +9,7 @@ from homeassistant.core import HomeAssistant
|
||||||
from .common import MOCK_VERSION, mock_get_version_update, setup_version_integration
|
from .common import MOCK_VERSION, mock_get_version_update, setup_version_integration
|
||||||
|
|
||||||
|
|
||||||
async def test_version_sensor(hass: HomeAssistant):
|
async def test_version_sensor(hass: HomeAssistant) -> None:
|
||||||
"""Test the Version sensor with different sources."""
|
"""Test the Version sensor with different sources."""
|
||||||
await setup_version_integration(hass)
|
await setup_version_integration(hass)
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ async def test_version_sensor(hass: HomeAssistant):
|
||||||
assert "channel" not in state.attributes
|
assert "channel" not in state.attributes
|
||||||
|
|
||||||
|
|
||||||
async def test_update(hass: HomeAssistant, caplog: pytest.LogCaptureFixture):
|
async def test_update(hass: HomeAssistant, caplog: pytest.LogCaptureFixture) -> None:
|
||||||
"""Test updates."""
|
"""Test updates."""
|
||||||
await setup_version_integration(hass)
|
await setup_version_integration(hass)
|
||||||
assert hass.states.get("sensor.local_installation").state == MOCK_VERSION
|
assert hass.states.get("sensor.local_installation").state == MOCK_VERSION
|
||||||
|
|
|
@ -669,7 +669,7 @@ async def test_import_error(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
vizio_connect: pytest.fixture,
|
vizio_connect: pytest.fixture,
|
||||||
vizio_bypass_setup: pytest.fixture,
|
vizio_bypass_setup: pytest.fixture,
|
||||||
caplog: pytest.fixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that error is logged when import config has an error."""
|
"""Test that error is logged when import config has an error."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
|
|
|
@ -508,7 +508,7 @@ async def test_update_unavailable_to_available(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
vizio_connect: pytest.fixture,
|
vizio_connect: pytest.fixture,
|
||||||
vizio_update: pytest.fixture,
|
vizio_update: pytest.fixture,
|
||||||
caplog: pytest.fixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test device becomes available after being unavailable."""
|
"""Test device becomes available after being unavailable."""
|
||||||
await _test_update_availability_switch(hass, None, True, caplog)
|
await _test_update_availability_switch(hass, None, True, caplog)
|
||||||
|
@ -518,7 +518,7 @@ async def test_update_available_to_unavailable(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
vizio_connect: pytest.fixture,
|
vizio_connect: pytest.fixture,
|
||||||
vizio_update: pytest.fixture,
|
vizio_update: pytest.fixture,
|
||||||
caplog: pytest.fixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test device becomes unavailable after being available."""
|
"""Test device becomes unavailable after being available."""
|
||||||
await _test_update_availability_switch(hass, True, None, caplog)
|
await _test_update_availability_switch(hass, True, None, caplog)
|
||||||
|
@ -528,7 +528,7 @@ async def test_setup_with_apps(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
vizio_connect: pytest.fixture,
|
vizio_connect: pytest.fixture,
|
||||||
vizio_update_with_apps: pytest.fixture,
|
vizio_update_with_apps: pytest.fixture,
|
||||||
caplog: pytest.fixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test device setup with apps."""
|
"""Test device setup with apps."""
|
||||||
async with _cm_for_test_setup_tv_with_apps(
|
async with _cm_for_test_setup_tv_with_apps(
|
||||||
|
@ -556,7 +556,7 @@ async def test_setup_with_apps_include(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
vizio_connect: pytest.fixture,
|
vizio_connect: pytest.fixture,
|
||||||
vizio_update_with_apps: pytest.fixture,
|
vizio_update_with_apps: pytest.fixture,
|
||||||
caplog: pytest.fixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test device setup with apps and apps["include"] in config."""
|
"""Test device setup with apps and apps["include"] in config."""
|
||||||
async with _cm_for_test_setup_tv_with_apps(
|
async with _cm_for_test_setup_tv_with_apps(
|
||||||
|
@ -574,7 +574,7 @@ async def test_setup_with_apps_exclude(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
vizio_connect: pytest.fixture,
|
vizio_connect: pytest.fixture,
|
||||||
vizio_update_with_apps: pytest.fixture,
|
vizio_update_with_apps: pytest.fixture,
|
||||||
caplog: pytest.fixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test device setup with apps and apps["exclude"] in config."""
|
"""Test device setup with apps and apps["exclude"] in config."""
|
||||||
async with _cm_for_test_setup_tv_with_apps(
|
async with _cm_for_test_setup_tv_with_apps(
|
||||||
|
@ -592,7 +592,7 @@ async def test_setup_with_apps_additional_apps_config(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
vizio_connect: pytest.fixture,
|
vizio_connect: pytest.fixture,
|
||||||
vizio_update_with_apps: pytest.fixture,
|
vizio_update_with_apps: pytest.fixture,
|
||||||
caplog: pytest.fixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test device setup with apps and apps["additional_configs"] in config."""
|
"""Test device setup with apps and apps["additional_configs"] in config."""
|
||||||
async with _cm_for_test_setup_tv_with_apps(
|
async with _cm_for_test_setup_tv_with_apps(
|
||||||
|
@ -655,7 +655,7 @@ async def test_setup_with_apps_additional_apps_config(
|
||||||
assert not service_call2.called
|
assert not service_call2.called
|
||||||
|
|
||||||
|
|
||||||
def test_invalid_apps_config(hass: HomeAssistant):
|
def test_invalid_apps_config(hass: HomeAssistant) -> None:
|
||||||
"""Test that schema validation fails on certain conditions."""
|
"""Test that schema validation fails on certain conditions."""
|
||||||
with pytest.raises(vol.Invalid):
|
with pytest.raises(vol.Invalid):
|
||||||
vol.Schema(vol.All(VIZIO_SCHEMA, validate_apps))(MOCK_TV_APPS_FAILURE)
|
vol.Schema(vol.All(VIZIO_SCHEMA, validate_apps))(MOCK_TV_APPS_FAILURE)
|
||||||
|
@ -668,7 +668,7 @@ async def test_setup_with_unknown_app_config(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
vizio_connect: pytest.fixture,
|
vizio_connect: pytest.fixture,
|
||||||
vizio_update_with_apps: pytest.fixture,
|
vizio_update_with_apps: pytest.fixture,
|
||||||
caplog: pytest.fixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test device setup with apps where app config returned is unknown."""
|
"""Test device setup with apps where app config returned is unknown."""
|
||||||
async with _cm_for_test_setup_tv_with_apps(
|
async with _cm_for_test_setup_tv_with_apps(
|
||||||
|
@ -685,7 +685,7 @@ async def test_setup_with_no_running_app(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
vizio_connect: pytest.fixture,
|
vizio_connect: pytest.fixture,
|
||||||
vizio_update_with_apps: pytest.fixture,
|
vizio_update_with_apps: pytest.fixture,
|
||||||
caplog: pytest.fixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test device setup with apps where no app is running."""
|
"""Test device setup with apps where no app is running."""
|
||||||
async with _cm_for_test_setup_tv_with_apps(
|
async with _cm_for_test_setup_tv_with_apps(
|
||||||
|
@ -726,7 +726,7 @@ async def test_apps_update(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
vizio_connect: pytest.fixture,
|
vizio_connect: pytest.fixture,
|
||||||
vizio_update_with_apps: pytest.fixture,
|
vizio_update_with_apps: pytest.fixture,
|
||||||
caplog: pytest.fixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test device setup with apps where no app is running."""
|
"""Test device setup with apps where no app is running."""
|
||||||
with patch(
|
with patch(
|
||||||
|
|
|
@ -45,8 +45,8 @@ async def test_show_form(hass: HomeAssistant) -> None:
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Account.register")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Account.register")
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
||||||
async def test_config_flow_auth_success(
|
async def test_config_flow_auth_success(
|
||||||
mock_keystore, mock_account, mock_student, hass
|
mock_keystore, mock_account, mock_student, hass: HomeAssistant
|
||||||
):
|
) -> None:
|
||||||
"""Test a successful config flow initialized by the user."""
|
"""Test a successful config flow initialized by the user."""
|
||||||
mock_keystore.return_value = fake_keystore
|
mock_keystore.return_value = fake_keystore
|
||||||
mock_account.return_value = fake_account
|
mock_account.return_value = fake_account
|
||||||
|
@ -80,8 +80,8 @@ async def test_config_flow_auth_success(
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Account.register")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Account.register")
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
||||||
async def test_config_flow_auth_success_with_multiple_students(
|
async def test_config_flow_auth_success_with_multiple_students(
|
||||||
mock_keystore, mock_account, mock_student, hass
|
mock_keystore, mock_account, mock_student, hass: HomeAssistant
|
||||||
):
|
) -> None:
|
||||||
"""Test a successful config flow with multiple students."""
|
"""Test a successful config flow with multiple students."""
|
||||||
mock_keystore.return_value = fake_keystore
|
mock_keystore.return_value = fake_keystore
|
||||||
mock_account.return_value = fake_account
|
mock_account.return_value = fake_account
|
||||||
|
@ -125,8 +125,8 @@ async def test_config_flow_auth_success_with_multiple_students(
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Account.register")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Account.register")
|
||||||
async def test_config_flow_reauth_success(
|
async def test_config_flow_reauth_success(
|
||||||
mock_account, mock_keystore, mock_student, hass
|
mock_account, mock_keystore, mock_student, hass: HomeAssistant
|
||||||
):
|
) -> None:
|
||||||
"""Test a successful config flow reauth."""
|
"""Test a successful config flow reauth."""
|
||||||
mock_keystore.return_value = fake_keystore
|
mock_keystore.return_value = fake_keystore
|
||||||
mock_account.return_value = fake_account
|
mock_account.return_value = fake_account
|
||||||
|
@ -164,8 +164,8 @@ async def test_config_flow_reauth_success(
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Account.register")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Account.register")
|
||||||
async def test_config_flow_reauth_without_matching_entries(
|
async def test_config_flow_reauth_without_matching_entries(
|
||||||
mock_account, mock_keystore, mock_student, hass
|
mock_account, mock_keystore, mock_student, hass: HomeAssistant
|
||||||
):
|
) -> None:
|
||||||
"""Test a aborted config flow reauth caused by leak of matching entries."""
|
"""Test a aborted config flow reauth caused by leak of matching entries."""
|
||||||
mock_keystore.return_value = fake_keystore
|
mock_keystore.return_value = fake_keystore
|
||||||
mock_account.return_value = fake_account
|
mock_account.return_value = fake_account
|
||||||
|
@ -196,7 +196,9 @@ async def test_config_flow_reauth_without_matching_entries(
|
||||||
|
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Account.register")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Account.register")
|
||||||
async def test_config_flow_reauth_with_errors(mock_account, mock_keystore, hass):
|
async def test_config_flow_reauth_with_errors(
|
||||||
|
mock_account, mock_keystore, hass: HomeAssistant
|
||||||
|
) -> None:
|
||||||
"""Test reauth config flow with errors."""
|
"""Test reauth config flow with errors."""
|
||||||
mock_keystore.return_value = fake_keystore
|
mock_keystore.return_value = fake_keystore
|
||||||
mock_account.return_value = fake_account
|
mock_account.return_value = fake_account
|
||||||
|
@ -288,7 +290,9 @@ async def test_config_flow_reauth_with_errors(mock_account, mock_keystore, hass)
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Vulcan.get_students")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Vulcan.get_students")
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Account.register")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Account.register")
|
||||||
async def test_multiple_config_entries(mock_account, mock_keystore, mock_student, hass):
|
async def test_multiple_config_entries(
|
||||||
|
mock_account, mock_keystore, mock_student, hass: HomeAssistant
|
||||||
|
) -> None:
|
||||||
"""Test a successful config flow for multiple config entries."""
|
"""Test a successful config flow for multiple config entries."""
|
||||||
mock_keystore.return_value = fake_keystore
|
mock_keystore.return_value = fake_keystore
|
||||||
mock_account.return_value = fake_account
|
mock_account.return_value = fake_account
|
||||||
|
@ -333,7 +337,9 @@ async def test_multiple_config_entries(mock_account, mock_keystore, mock_student
|
||||||
|
|
||||||
|
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Vulcan.get_students")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Vulcan.get_students")
|
||||||
async def test_multiple_config_entries_using_saved_credentials(mock_student, hass):
|
async def test_multiple_config_entries_using_saved_credentials(
|
||||||
|
mock_student, hass: HomeAssistant
|
||||||
|
) -> None:
|
||||||
"""Test a successful config flow for multiple config entries using saved credentials."""
|
"""Test a successful config flow for multiple config entries using saved credentials."""
|
||||||
mock_student.return_value = [
|
mock_student.return_value = [
|
||||||
Student.load(load_fixture("fake_student_1.json", "vulcan"))
|
Student.load(load_fixture("fake_student_1.json", "vulcan"))
|
||||||
|
@ -367,7 +373,9 @@ async def test_multiple_config_entries_using_saved_credentials(mock_student, has
|
||||||
|
|
||||||
|
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Vulcan.get_students")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Vulcan.get_students")
|
||||||
async def test_multiple_config_entries_using_saved_credentials_2(mock_student, hass):
|
async def test_multiple_config_entries_using_saved_credentials_2(
|
||||||
|
mock_student, hass: HomeAssistant
|
||||||
|
) -> None:
|
||||||
"""Test a successful config flow for multiple config entries using saved credentials (different situation)."""
|
"""Test a successful config flow for multiple config entries using saved credentials (different situation)."""
|
||||||
mock_student.return_value = [
|
mock_student.return_value = [
|
||||||
Student.load(load_fixture("fake_student_1.json", "vulcan"))
|
Student.load(load_fixture("fake_student_1.json", "vulcan"))
|
||||||
|
@ -410,7 +418,9 @@ async def test_multiple_config_entries_using_saved_credentials_2(mock_student, h
|
||||||
|
|
||||||
|
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Vulcan.get_students")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Vulcan.get_students")
|
||||||
async def test_multiple_config_entries_using_saved_credentials_3(mock_student, hass):
|
async def test_multiple_config_entries_using_saved_credentials_3(
|
||||||
|
mock_student, hass: HomeAssistant
|
||||||
|
) -> None:
|
||||||
"""Test a successful config flow for multiple config entries using saved credentials."""
|
"""Test a successful config flow for multiple config entries using saved credentials."""
|
||||||
mock_student.return_value = [
|
mock_student.return_value = [
|
||||||
Student.load(load_fixture("fake_student_1.json", "vulcan"))
|
Student.load(load_fixture("fake_student_1.json", "vulcan"))
|
||||||
|
@ -461,7 +471,9 @@ async def test_multiple_config_entries_using_saved_credentials_3(mock_student, h
|
||||||
|
|
||||||
|
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Vulcan.get_students")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Vulcan.get_students")
|
||||||
async def test_multiple_config_entries_using_saved_credentials_4(mock_student, hass):
|
async def test_multiple_config_entries_using_saved_credentials_4(
|
||||||
|
mock_student, hass: HomeAssistant
|
||||||
|
) -> None:
|
||||||
"""Test a successful config flow for multiple config entries using saved credentials (different situation)."""
|
"""Test a successful config flow for multiple config entries using saved credentials (different situation)."""
|
||||||
mock_student.return_value = [
|
mock_student.return_value = [
|
||||||
Student.load(load_fixture("fake_student_1.json", "vulcan"))
|
Student.load(load_fixture("fake_student_1.json", "vulcan"))
|
||||||
|
@ -569,8 +581,8 @@ async def test_multiple_config_entries_without_valid_saved_credentials(
|
||||||
|
|
||||||
|
|
||||||
async def test_multiple_config_entries_using_saved_credentials_with_connections_issues(
|
async def test_multiple_config_entries_using_saved_credentials_with_connections_issues(
|
||||||
hass,
|
hass: HomeAssistant,
|
||||||
):
|
) -> None:
|
||||||
"""Test a unsuccessful config flow for multiple config entries without valid saved credentials."""
|
"""Test a unsuccessful config flow for multiple config entries without valid saved credentials."""
|
||||||
MockConfigEntry(
|
MockConfigEntry(
|
||||||
entry_id="456",
|
entry_id="456",
|
||||||
|
@ -667,7 +679,9 @@ async def test_multiple_config_entries_using_saved_credentials_with_unknown_erro
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Vulcan.get_students")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Vulcan.get_students")
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Account.register")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Account.register")
|
||||||
async def test_student_already_exists(mock_account, mock_keystore, mock_student, hass):
|
async def test_student_already_exists(
|
||||||
|
mock_account, mock_keystore, mock_student, hass: HomeAssistant
|
||||||
|
) -> None:
|
||||||
"""Test config entry when student's entry already exists."""
|
"""Test config entry when student's entry already exists."""
|
||||||
mock_keystore.return_value = fake_keystore
|
mock_keystore.return_value = fake_keystore
|
||||||
mock_account.return_value = fake_account
|
mock_account.return_value = fake_account
|
||||||
|
@ -701,7 +715,9 @@ async def test_student_already_exists(mock_account, mock_keystore, mock_student,
|
||||||
|
|
||||||
|
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
||||||
async def test_config_flow_auth_invalid_token(mock_keystore, hass):
|
async def test_config_flow_auth_invalid_token(
|
||||||
|
mock_keystore, hass: HomeAssistant
|
||||||
|
) -> None:
|
||||||
"""Test a config flow initialized by the user using invalid token."""
|
"""Test a config flow initialized by the user using invalid token."""
|
||||||
mock_keystore.return_value = fake_keystore
|
mock_keystore.return_value = fake_keystore
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -727,7 +743,9 @@ async def test_config_flow_auth_invalid_token(mock_keystore, hass):
|
||||||
|
|
||||||
|
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
||||||
async def test_config_flow_auth_invalid_region(mock_keystore, hass):
|
async def test_config_flow_auth_invalid_region(
|
||||||
|
mock_keystore, hass: HomeAssistant
|
||||||
|
) -> None:
|
||||||
"""Test a config flow initialized by the user using invalid region."""
|
"""Test a config flow initialized by the user using invalid region."""
|
||||||
mock_keystore.return_value = fake_keystore
|
mock_keystore.return_value = fake_keystore
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -753,7 +771,7 @@ async def test_config_flow_auth_invalid_region(mock_keystore, hass):
|
||||||
|
|
||||||
|
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
||||||
async def test_config_flow_auth_invalid_pin(mock_keystore, hass):
|
async def test_config_flow_auth_invalid_pin(mock_keystore, hass: HomeAssistant) -> None:
|
||||||
"""Test a config flow initialized by the with invalid pin."""
|
"""Test a config flow initialized by the with invalid pin."""
|
||||||
mock_keystore.return_value = fake_keystore
|
mock_keystore.return_value = fake_keystore
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -779,7 +797,9 @@ async def test_config_flow_auth_invalid_pin(mock_keystore, hass):
|
||||||
|
|
||||||
|
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
||||||
async def test_config_flow_auth_expired_token(mock_keystore, hass):
|
async def test_config_flow_auth_expired_token(
|
||||||
|
mock_keystore, hass: HomeAssistant
|
||||||
|
) -> None:
|
||||||
"""Test a config flow initialized by the with expired token."""
|
"""Test a config flow initialized by the with expired token."""
|
||||||
mock_keystore.return_value = fake_keystore
|
mock_keystore.return_value = fake_keystore
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -805,7 +825,9 @@ async def test_config_flow_auth_expired_token(mock_keystore, hass):
|
||||||
|
|
||||||
|
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
||||||
async def test_config_flow_auth_connection_error(mock_keystore, hass):
|
async def test_config_flow_auth_connection_error(
|
||||||
|
mock_keystore, hass: HomeAssistant
|
||||||
|
) -> None:
|
||||||
"""Test a config flow with connection error."""
|
"""Test a config flow with connection error."""
|
||||||
mock_keystore.return_value = fake_keystore
|
mock_keystore.return_value = fake_keystore
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -831,7 +853,9 @@ async def test_config_flow_auth_connection_error(mock_keystore, hass):
|
||||||
|
|
||||||
|
|
||||||
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
@mock.patch("homeassistant.components.vulcan.config_flow.Keystore.create")
|
||||||
async def test_config_flow_auth_unknown_error(mock_keystore, hass):
|
async def test_config_flow_auth_unknown_error(
|
||||||
|
mock_keystore, hass: HomeAssistant
|
||||||
|
) -> None:
|
||||||
"""Test a config flow with unknown error."""
|
"""Test a config flow with unknown error."""
|
||||||
mock_keystore.return_value = fake_keystore
|
mock_keystore.return_value = fake_keystore
|
||||||
with patch(
|
with patch(
|
||||||
|
|
|
@ -24,7 +24,7 @@ CONFIGS = [
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("valid_config")
|
@pytest.mark.usefixtures("valid_config")
|
||||||
def test_binary_sensor(hass: HomeAssistant):
|
def test_binary_sensor(hass: HomeAssistant) -> None:
|
||||||
"""Test successful instance."""
|
"""Test successful instance."""
|
||||||
hass_devices = []
|
hass_devices = []
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ def test_invalid_sensor_config() -> None:
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("valid_config")
|
@pytest.mark.usefixtures("valid_config")
|
||||||
def test_invalid_sensors(hass: HomeAssistant):
|
def test_invalid_sensors(hass: HomeAssistant) -> None:
|
||||||
"""Test the VultrBinarySensor fails."""
|
"""Test the VultrBinarySensor fails."""
|
||||||
hass_devices = []
|
hass_devices = []
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ from .const import VALID_CONFIG
|
||||||
from tests.common import load_fixture
|
from tests.common import load_fixture
|
||||||
|
|
||||||
|
|
||||||
def test_setup(hass: HomeAssistant):
|
def test_setup(hass: HomeAssistant) -> None:
|
||||||
"""Test successful setup."""
|
"""Test successful setup."""
|
||||||
with patch(
|
with patch(
|
||||||
"vultr.Vultr.server_list",
|
"vultr.Vultr.server_list",
|
||||||
|
@ -22,7 +22,7 @@ def test_setup(hass: HomeAssistant):
|
||||||
assert response
|
assert response
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_no_api_key(hass: HomeAssistant):
|
async def test_setup_no_api_key(hass: HomeAssistant) -> None:
|
||||||
"""Test failed setup with missing API Key."""
|
"""Test failed setup with missing API Key."""
|
||||||
conf = deepcopy(VALID_CONFIG)
|
conf = deepcopy(VALID_CONFIG)
|
||||||
del conf["vultr"]["api_key"]
|
del conf["vultr"]["api_key"]
|
||||||
|
|
|
@ -33,7 +33,7 @@ CONFIGS = [
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("valid_config")
|
@pytest.mark.usefixtures("valid_config")
|
||||||
def test_sensor(hass: HomeAssistant):
|
def test_sensor(hass: HomeAssistant) -> None:
|
||||||
"""Test the Vultr sensor class and methods."""
|
"""Test the Vultr sensor class and methods."""
|
||||||
hass_devices = []
|
hass_devices = []
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ def test_invalid_sensor_config() -> None:
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("valid_config")
|
@pytest.mark.usefixtures("valid_config")
|
||||||
def test_invalid_sensors(hass: HomeAssistant):
|
def test_invalid_sensors(hass: HomeAssistant) -> None:
|
||||||
"""Test the VultrSensor fails."""
|
"""Test the VultrSensor fails."""
|
||||||
hass_devices = []
|
hass_devices = []
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,7 @@ def test_invalid_switch_config() -> None:
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("valid_config")
|
@pytest.mark.usefixtures("valid_config")
|
||||||
def test_invalid_switches(hass: HomeAssistant):
|
def test_invalid_switches(hass: HomeAssistant) -> None:
|
||||||
"""Test the VultrSwitch fails."""
|
"""Test the VultrSwitch fails."""
|
||||||
hass_devices = []
|
hass_devices = []
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ from homeassistant.components.device_automation import DeviceAutomationType
|
||||||
from homeassistant.components.water_heater import DOMAIN
|
from homeassistant.components.water_heater import DOMAIN
|
||||||
from homeassistant.const import EntityCategory
|
from homeassistant.const import EntityCategory
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
from homeassistant.helpers.entity_registry import RegistryEntryHider
|
from homeassistant.helpers.entity_registry import RegistryEntryHider
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
@ -19,7 +19,11 @@ from tests.common import (
|
||||||
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
|
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
|
||||||
|
|
||||||
|
|
||||||
async def test_get_actions(hass, device_registry, entity_registry):
|
async def test_get_actions(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
) -> None:
|
||||||
"""Test we get the expected actions from a water_heater."""
|
"""Test we get the expected actions from a water_heater."""
|
||||||
config_entry = MockConfigEntry(domain="test", data={})
|
config_entry = MockConfigEntry(domain="test", data={})
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
@ -57,12 +61,12 @@ async def test_get_actions(hass, device_registry, entity_registry):
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
async def test_get_actions_hidden_auxiliary(
|
async def test_get_actions_hidden_auxiliary(
|
||||||
hass,
|
hass: HomeAssistant,
|
||||||
device_registry,
|
device_registry: dr.DeviceRegistry,
|
||||||
entity_registry,
|
entity_registry: er.EntityRegistry,
|
||||||
hidden_by,
|
hidden_by,
|
||||||
entity_category,
|
entity_category,
|
||||||
):
|
) -> None:
|
||||||
"""Test we get the expected actions from a hidden or auxiliary entity."""
|
"""Test we get the expected actions from a hidden or auxiliary entity."""
|
||||||
config_entry = MockConfigEntry(domain="test", data={})
|
config_entry = MockConfigEntry(domain="test", data={})
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
|
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from homeassistant.components import water_heater
|
from homeassistant.components import water_heater
|
||||||
|
from homeassistant.components.recorder import Recorder
|
||||||
from homeassistant.components.recorder.db_schema import StateAttributes, States
|
from homeassistant.components.recorder.db_schema import StateAttributes, States
|
||||||
from homeassistant.components.recorder.util import session_scope
|
from homeassistant.components.recorder.util import session_scope
|
||||||
from homeassistant.components.water_heater import (
|
from homeassistant.components.water_heater import (
|
||||||
|
@ -12,7 +13,7 @@ from homeassistant.components.water_heater import (
|
||||||
ATTR_OPERATION_LIST,
|
ATTR_OPERATION_LIST,
|
||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_FRIENDLY_NAME
|
from homeassistant.const import ATTR_FRIENDLY_NAME
|
||||||
from homeassistant.core import State
|
from homeassistant.core import HomeAssistant, State
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
|
@ -20,7 +21,7 @@ from tests.common import async_fire_time_changed
|
||||||
from tests.components.recorder.common import async_wait_recording_done
|
from tests.components.recorder.common import async_wait_recording_done
|
||||||
|
|
||||||
|
|
||||||
async def test_exclude_attributes(recorder_mock, hass):
|
async def test_exclude_attributes(recorder_mock: Recorder, hass: HomeAssistant) -> None:
|
||||||
"""Test water_heater registered attributes to be excluded."""
|
"""Test water_heater registered attributes to be excluded."""
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass, water_heater.DOMAIN, {water_heater.DOMAIN: {"platform": "demo"}}
|
hass, water_heater.DOMAIN, {water_heater.DOMAIN: {"platform": "demo"}}
|
||||||
|
|
|
@ -84,7 +84,7 @@ async def test_coordinate_errors(
|
||||||
)
|
)
|
||||||
async def test_duplicate_error(
|
async def test_duplicate_error(
|
||||||
hass: HomeAssistant, config_auth, config_entry, config_location_type, setup_watttime
|
hass: HomeAssistant, config_auth, config_entry, config_location_type, setup_watttime
|
||||||
):
|
) -> None:
|
||||||
"""Test that errors are shown when duplicate entries are added."""
|
"""Test that errors are shown when duplicate entries are added."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}, data=config_auth
|
DOMAIN, context={"source": config_entries.SOURCE_USER}, data=config_auth
|
||||||
|
@ -96,7 +96,7 @@ async def test_duplicate_error(
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
async def test_options_flow(hass: HomeAssistant, config_entry):
|
async def test_options_flow(hass: HomeAssistant, config_entry) -> None:
|
||||||
"""Test config flow options."""
|
"""Test config flow options."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.watttime.async_setup_entry", return_value=True
|
"homeassistant.components.watttime.async_setup_entry", return_value=True
|
||||||
|
|
|
@ -1,10 +1,17 @@
|
||||||
"""Test WattTime diagnostics."""
|
"""Test WattTime diagnostics."""
|
||||||
from homeassistant.components.diagnostics import REDACTED
|
from homeassistant.components.diagnostics import REDACTED
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
|
|
||||||
async def test_entry_diagnostics(hass, config_entry, hass_client, setup_watttime):
|
async def test_entry_diagnostics(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry,
|
||||||
|
hass_client: ClientSessionGenerator,
|
||||||
|
setup_watttime,
|
||||||
|
) -> None:
|
||||||
"""Test config entry diagnostics."""
|
"""Test config entry diagnostics."""
|
||||||
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
|
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
|
||||||
"entry": {
|
"entry": {
|
||||||
|
|
|
@ -145,11 +145,11 @@ async def create_entity(hass: HomeAssistant, **kwargs):
|
||||||
)
|
)
|
||||||
async def test_temperature(
|
async def test_temperature(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
enable_custom_integrations,
|
enable_custom_integrations: None,
|
||||||
native_unit: str,
|
native_unit: str,
|
||||||
state_unit: str,
|
state_unit: str,
|
||||||
unit_system,
|
unit_system,
|
||||||
):
|
) -> None:
|
||||||
"""Test temperature."""
|
"""Test temperature."""
|
||||||
hass.config.units = unit_system
|
hass.config.units = unit_system
|
||||||
native_value = 38
|
native_value = 38
|
||||||
|
@ -181,11 +181,11 @@ async def test_temperature(
|
||||||
)
|
)
|
||||||
async def test_temperature_no_unit(
|
async def test_temperature_no_unit(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
enable_custom_integrations,
|
enable_custom_integrations: None,
|
||||||
native_unit: str,
|
native_unit: str,
|
||||||
state_unit: str,
|
state_unit: str,
|
||||||
unit_system,
|
unit_system,
|
||||||
):
|
) -> None:
|
||||||
"""Test temperature when the entity does not declare a native unit."""
|
"""Test temperature when the entity does not declare a native unit."""
|
||||||
hass.config.units = unit_system
|
hass.config.units = unit_system
|
||||||
native_value = 38
|
native_value = 38
|
||||||
|
@ -214,11 +214,11 @@ async def test_temperature_no_unit(
|
||||||
)
|
)
|
||||||
async def test_pressure(
|
async def test_pressure(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
enable_custom_integrations,
|
enable_custom_integrations: None,
|
||||||
native_unit: str,
|
native_unit: str,
|
||||||
state_unit: str,
|
state_unit: str,
|
||||||
unit_system,
|
unit_system,
|
||||||
):
|
) -> None:
|
||||||
"""Test pressure."""
|
"""Test pressure."""
|
||||||
hass.config.units = unit_system
|
hass.config.units = unit_system
|
||||||
native_value = 30
|
native_value = 30
|
||||||
|
@ -244,11 +244,11 @@ async def test_pressure(
|
||||||
)
|
)
|
||||||
async def test_pressure_no_unit(
|
async def test_pressure_no_unit(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
enable_custom_integrations,
|
enable_custom_integrations: None,
|
||||||
native_unit: str,
|
native_unit: str,
|
||||||
state_unit: str,
|
state_unit: str,
|
||||||
unit_system,
|
unit_system,
|
||||||
):
|
) -> None:
|
||||||
"""Test pressure when the entity does not declare a native unit."""
|
"""Test pressure when the entity does not declare a native unit."""
|
||||||
hass.config.units = unit_system
|
hass.config.units = unit_system
|
||||||
native_value = 30
|
native_value = 30
|
||||||
|
@ -284,11 +284,11 @@ async def test_pressure_no_unit(
|
||||||
)
|
)
|
||||||
async def test_wind_speed(
|
async def test_wind_speed(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
enable_custom_integrations,
|
enable_custom_integrations: None,
|
||||||
native_unit: str,
|
native_unit: str,
|
||||||
state_unit: str,
|
state_unit: str,
|
||||||
unit_system,
|
unit_system,
|
||||||
):
|
) -> None:
|
||||||
"""Test wind speed."""
|
"""Test wind speed."""
|
||||||
hass.config.units = unit_system
|
hass.config.units = unit_system
|
||||||
native_value = 10
|
native_value = 10
|
||||||
|
@ -320,11 +320,11 @@ async def test_wind_speed(
|
||||||
)
|
)
|
||||||
async def test_wind_speed_no_unit(
|
async def test_wind_speed_no_unit(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
enable_custom_integrations,
|
enable_custom_integrations: None,
|
||||||
native_unit: str,
|
native_unit: str,
|
||||||
state_unit: str,
|
state_unit: str,
|
||||||
unit_system,
|
unit_system,
|
||||||
):
|
) -> None:
|
||||||
"""Test wind speed when the entity does not declare a native unit."""
|
"""Test wind speed when the entity does not declare a native unit."""
|
||||||
hass.config.units = unit_system
|
hass.config.units = unit_system
|
||||||
native_value = 10
|
native_value = 10
|
||||||
|
@ -356,11 +356,11 @@ async def test_wind_speed_no_unit(
|
||||||
)
|
)
|
||||||
async def test_visibility(
|
async def test_visibility(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
enable_custom_integrations,
|
enable_custom_integrations: None,
|
||||||
native_unit: str,
|
native_unit: str,
|
||||||
state_unit: str,
|
state_unit: str,
|
||||||
unit_system,
|
unit_system,
|
||||||
):
|
) -> None:
|
||||||
"""Test visibility."""
|
"""Test visibility."""
|
||||||
hass.config.units = unit_system
|
hass.config.units = unit_system
|
||||||
native_value = 10
|
native_value = 10
|
||||||
|
@ -387,11 +387,11 @@ async def test_visibility(
|
||||||
)
|
)
|
||||||
async def test_visibility_no_unit(
|
async def test_visibility_no_unit(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
enable_custom_integrations,
|
enable_custom_integrations: None,
|
||||||
native_unit: str,
|
native_unit: str,
|
||||||
state_unit: str,
|
state_unit: str,
|
||||||
unit_system,
|
unit_system,
|
||||||
):
|
) -> None:
|
||||||
"""Test visibility when the entity does not declare a native unit."""
|
"""Test visibility when the entity does not declare a native unit."""
|
||||||
hass.config.units = unit_system
|
hass.config.units = unit_system
|
||||||
native_value = 10
|
native_value = 10
|
||||||
|
@ -418,11 +418,11 @@ async def test_visibility_no_unit(
|
||||||
)
|
)
|
||||||
async def test_precipitation(
|
async def test_precipitation(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
enable_custom_integrations,
|
enable_custom_integrations: None,
|
||||||
native_unit: str,
|
native_unit: str,
|
||||||
state_unit: str,
|
state_unit: str,
|
||||||
unit_system,
|
unit_system,
|
||||||
):
|
) -> None:
|
||||||
"""Test precipitation."""
|
"""Test precipitation."""
|
||||||
hass.config.units = unit_system
|
hass.config.units = unit_system
|
||||||
native_value = 30
|
native_value = 30
|
||||||
|
@ -451,11 +451,11 @@ async def test_precipitation(
|
||||||
)
|
)
|
||||||
async def test_precipitation_no_unit(
|
async def test_precipitation_no_unit(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
enable_custom_integrations,
|
enable_custom_integrations: None,
|
||||||
native_unit: str,
|
native_unit: str,
|
||||||
state_unit: str,
|
state_unit: str,
|
||||||
unit_system,
|
unit_system,
|
||||||
):
|
) -> None:
|
||||||
"""Test precipitation when the entity does not declare a native unit."""
|
"""Test precipitation when the entity does not declare a native unit."""
|
||||||
hass.config.units = unit_system
|
hass.config.units = unit_system
|
||||||
native_value = 30
|
native_value = 30
|
||||||
|
@ -476,8 +476,8 @@ async def test_precipitation_no_unit(
|
||||||
|
|
||||||
async def test_wind_bearing_and_ozone(
|
async def test_wind_bearing_and_ozone(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
enable_custom_integrations,
|
enable_custom_integrations: None,
|
||||||
):
|
) -> None:
|
||||||
"""Test wind bearing."""
|
"""Test wind bearing."""
|
||||||
wind_bearing_value = 180
|
wind_bearing_value = 180
|
||||||
ozone_value = 10
|
ozone_value = 10
|
||||||
|
@ -493,8 +493,8 @@ async def test_wind_bearing_and_ozone(
|
||||||
|
|
||||||
async def test_none_forecast(
|
async def test_none_forecast(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
enable_custom_integrations,
|
enable_custom_integrations: None,
|
||||||
):
|
) -> None:
|
||||||
"""Test that conversion with None values succeeds."""
|
"""Test that conversion with None values succeeds."""
|
||||||
entity0 = await create_entity(
|
entity0 = await create_entity(
|
||||||
hass,
|
hass,
|
||||||
|
@ -514,7 +514,9 @@ async def test_none_forecast(
|
||||||
assert forecast.get(ATTR_FORECAST_PRECIPITATION) is None
|
assert forecast.get(ATTR_FORECAST_PRECIPITATION) is None
|
||||||
|
|
||||||
|
|
||||||
async def test_custom_units(hass: HomeAssistant, enable_custom_integrations) -> None:
|
async def test_custom_units(
|
||||||
|
hass: HomeAssistant, enable_custom_integrations: None
|
||||||
|
) -> None:
|
||||||
"""Test custom unit."""
|
"""Test custom unit."""
|
||||||
wind_speed_value = 5
|
wind_speed_value = 5
|
||||||
wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND
|
wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND
|
||||||
|
@ -630,7 +632,7 @@ async def test_custom_units(hass: HomeAssistant, enable_custom_integrations) ->
|
||||||
|
|
||||||
|
|
||||||
async def test_backwards_compatibility(
|
async def test_backwards_compatibility(
|
||||||
hass: HomeAssistant, enable_custom_integrations
|
hass: HomeAssistant, enable_custom_integrations: None
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test backwards compatibility."""
|
"""Test backwards compatibility."""
|
||||||
wind_speed_value = 5
|
wind_speed_value = 5
|
||||||
|
@ -746,7 +748,7 @@ async def test_backwards_compatibility(
|
||||||
|
|
||||||
|
|
||||||
async def test_backwards_compatibility_convert_values(
|
async def test_backwards_compatibility_convert_values(
|
||||||
hass: HomeAssistant, enable_custom_integrations
|
hass: HomeAssistant, enable_custom_integrations: None
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test backward compatibility for converting values."""
|
"""Test backward compatibility for converting values."""
|
||||||
wind_speed_value = 5
|
wind_speed_value = 5
|
||||||
|
|
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
|
from homeassistant.components.recorder import Recorder
|
||||||
from homeassistant.components.recorder.db_schema import StateAttributes, States
|
from homeassistant.components.recorder.db_schema import StateAttributes, States
|
||||||
from homeassistant.components.recorder.util import session_scope
|
from homeassistant.components.recorder.util import session_scope
|
||||||
from homeassistant.components.weather import ATTR_FORECAST, DOMAIN
|
from homeassistant.components.weather import ATTR_FORECAST, DOMAIN
|
||||||
|
@ -15,7 +16,7 @@ from tests.common import async_fire_time_changed
|
||||||
from tests.components.recorder.common import async_wait_recording_done
|
from tests.components.recorder.common import async_wait_recording_done
|
||||||
|
|
||||||
|
|
||||||
async def test_exclude_attributes(recorder_mock, hass: HomeAssistant) -> None:
|
async def test_exclude_attributes(recorder_mock: Recorder, hass: HomeAssistant) -> None:
|
||||||
"""Test weather attributes to be excluded."""
|
"""Test weather attributes to be excluded."""
|
||||||
await async_setup_component(hass, DOMAIN, {DOMAIN: {"platform": "demo"}})
|
await async_setup_component(hass, DOMAIN, {DOMAIN: {"platform": "demo"}})
|
||||||
hass.config.units = METRIC_SYSTEM
|
hass.config.units = METRIC_SYSTEM
|
||||||
|
|
|
@ -11,6 +11,8 @@ from homeassistant.config import async_process_ha_core_config
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
from tests.typing import WebSocketGenerator
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_client(hass, hass_client):
|
def mock_client(hass, hass_client):
|
||||||
|
@ -19,7 +21,7 @@ def mock_client(hass, hass_client):
|
||||||
return hass.loop.run_until_complete(hass_client())
|
return hass.loop.run_until_complete(hass_client())
|
||||||
|
|
||||||
|
|
||||||
async def test_unregistering_webhook(hass, mock_client):
|
async def test_unregistering_webhook(hass: HomeAssistant, mock_client) -> None:
|
||||||
"""Test unregistering a webhook."""
|
"""Test unregistering a webhook."""
|
||||||
hooks = []
|
hooks = []
|
||||||
webhook_id = webhook.async_generate_id()
|
webhook_id = webhook.async_generate_id()
|
||||||
|
@ -58,20 +60,20 @@ async def test_async_generate_path(hass: HomeAssistant) -> None:
|
||||||
assert path == "/api/webhook/some_id"
|
assert path == "/api/webhook/some_id"
|
||||||
|
|
||||||
|
|
||||||
async def test_posting_webhook_nonexisting(hass, mock_client):
|
async def test_posting_webhook_nonexisting(hass: HomeAssistant, mock_client) -> None:
|
||||||
"""Test posting to a nonexisting webhook."""
|
"""Test posting to a nonexisting webhook."""
|
||||||
resp = await mock_client.post("/api/webhook/non-existing")
|
resp = await mock_client.post("/api/webhook/non-existing")
|
||||||
assert resp.status == HTTPStatus.OK
|
assert resp.status == HTTPStatus.OK
|
||||||
|
|
||||||
|
|
||||||
async def test_posting_webhook_invalid_json(hass, mock_client):
|
async def test_posting_webhook_invalid_json(hass: HomeAssistant, mock_client) -> None:
|
||||||
"""Test posting to a nonexisting webhook."""
|
"""Test posting to a nonexisting webhook."""
|
||||||
webhook.async_register(hass, "test", "Test hook", "hello", None)
|
webhook.async_register(hass, "test", "Test hook", "hello", None)
|
||||||
resp = await mock_client.post("/api/webhook/hello", data="not-json")
|
resp = await mock_client.post("/api/webhook/hello", data="not-json")
|
||||||
assert resp.status == HTTPStatus.OK
|
assert resp.status == HTTPStatus.OK
|
||||||
|
|
||||||
|
|
||||||
async def test_posting_webhook_json(hass, mock_client):
|
async def test_posting_webhook_json(hass: HomeAssistant, mock_client) -> None:
|
||||||
"""Test posting a webhook with JSON data."""
|
"""Test posting a webhook with JSON data."""
|
||||||
hooks = []
|
hooks = []
|
||||||
webhook_id = webhook.async_generate_id()
|
webhook_id = webhook.async_generate_id()
|
||||||
|
@ -90,7 +92,7 @@ async def test_posting_webhook_json(hass, mock_client):
|
||||||
assert hooks[0][2] == '{"data": true}'
|
assert hooks[0][2] == '{"data": true}'
|
||||||
|
|
||||||
|
|
||||||
async def test_posting_webhook_no_data(hass, mock_client):
|
async def test_posting_webhook_no_data(hass: HomeAssistant, mock_client) -> None:
|
||||||
"""Test posting a webhook with no data."""
|
"""Test posting a webhook with no data."""
|
||||||
hooks = []
|
hooks = []
|
||||||
webhook_id = webhook.async_generate_id()
|
webhook_id = webhook.async_generate_id()
|
||||||
|
@ -110,7 +112,7 @@ async def test_posting_webhook_no_data(hass, mock_client):
|
||||||
assert await hooks[0][2].text() == ""
|
assert await hooks[0][2].text() == ""
|
||||||
|
|
||||||
|
|
||||||
async def test_webhook_put(hass, mock_client):
|
async def test_webhook_put(hass: HomeAssistant, mock_client) -> None:
|
||||||
"""Test sending a put request to a webhook."""
|
"""Test sending a put request to a webhook."""
|
||||||
hooks = []
|
hooks = []
|
||||||
webhook_id = webhook.async_generate_id()
|
webhook_id = webhook.async_generate_id()
|
||||||
|
@ -129,7 +131,7 @@ async def test_webhook_put(hass, mock_client):
|
||||||
assert hooks[0][2].method == "PUT"
|
assert hooks[0][2].method == "PUT"
|
||||||
|
|
||||||
|
|
||||||
async def test_webhook_head(hass, mock_client):
|
async def test_webhook_head(hass: HomeAssistant, mock_client) -> None:
|
||||||
"""Test sending a head request to a webhook."""
|
"""Test sending a head request to a webhook."""
|
||||||
hooks = []
|
hooks = []
|
||||||
webhook_id = webhook.async_generate_id()
|
webhook_id = webhook.async_generate_id()
|
||||||
|
@ -148,7 +150,7 @@ async def test_webhook_head(hass, mock_client):
|
||||||
assert hooks[0][2].method == "HEAD"
|
assert hooks[0][2].method == "HEAD"
|
||||||
|
|
||||||
|
|
||||||
async def test_webhook_local_only(hass, mock_client):
|
async def test_webhook_local_only(hass: HomeAssistant, mock_client) -> None:
|
||||||
"""Test posting a webhook with local only."""
|
"""Test posting a webhook with local only."""
|
||||||
hooks = []
|
hooks = []
|
||||||
webhook_id = webhook.async_generate_id()
|
webhook_id = webhook.async_generate_id()
|
||||||
|
@ -180,8 +182,11 @@ async def test_webhook_local_only(hass, mock_client):
|
||||||
|
|
||||||
|
|
||||||
async def test_listing_webhook(
|
async def test_listing_webhook(
|
||||||
hass, hass_ws_client, hass_access_token, enable_custom_integrations
|
hass: HomeAssistant,
|
||||||
):
|
hass_ws_client: WebSocketGenerator,
|
||||||
|
hass_access_token: str,
|
||||||
|
enable_custom_integrations: None,
|
||||||
|
) -> None:
|
||||||
"""Test unregistering a webhook."""
|
"""Test unregistering a webhook."""
|
||||||
assert await async_setup_component(hass, "webhook", {})
|
assert await async_setup_component(hass, "webhook", {})
|
||||||
client = await hass_ws_client(hass, hass_access_token)
|
client = await hass_ws_client(hass, hass_access_token)
|
||||||
|
@ -210,7 +215,11 @@ async def test_listing_webhook(
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
async def test_ws_webhook(hass, caplog, hass_ws_client):
|
async def test_ws_webhook(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
hass_ws_client: WebSocketGenerator,
|
||||||
|
) -> None:
|
||||||
"""Test sending webhook msg via WS API."""
|
"""Test sending webhook msg via WS API."""
|
||||||
assert await async_setup_component(hass, "webhook", {})
|
assert await async_setup_component(hass, "webhook", {})
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ from homeassistant.components import ssdp
|
||||||
from homeassistant.components.webostv.const import CONF_SOURCES, DOMAIN, LIVE_TV_APP_ID
|
from homeassistant.components.webostv.const import CONF_SOURCES, DOMAIN, LIVE_TV_APP_ID
|
||||||
from homeassistant.config_entries import SOURCE_SSDP
|
from homeassistant.config_entries import SOURCE_SSDP
|
||||||
from homeassistant.const import CONF_CLIENT_SECRET, CONF_HOST, CONF_NAME, CONF_SOURCE
|
from homeassistant.const import CONF_CLIENT_SECRET, CONF_HOST, CONF_NAME, CONF_SOURCE
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
|
|
||||||
from . import setup_webostv
|
from . import setup_webostv
|
||||||
|
@ -31,7 +32,7 @@ MOCK_DISCOVERY_INFO = ssdp.SsdpServiceInfo(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_form(hass, client):
|
async def test_form(hass: HomeAssistant, client) -> None:
|
||||||
"""Test we get the form."""
|
"""Test we get the form."""
|
||||||
assert client
|
assert client
|
||||||
|
|
||||||
|
@ -92,7 +93,9 @@ async def test_form(hass, client):
|
||||||
({}, MOCK_INPUTS),
|
({}, MOCK_INPUTS),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_options_flow_live_tv_in_apps(hass, client, apps, inputs):
|
async def test_options_flow_live_tv_in_apps(
|
||||||
|
hass: HomeAssistant, client, apps, inputs
|
||||||
|
) -> None:
|
||||||
"""Test options config flow Live TV found in apps."""
|
"""Test options config flow Live TV found in apps."""
|
||||||
client.apps = apps
|
client.apps = apps
|
||||||
client.inputs = inputs
|
client.inputs = inputs
|
||||||
|
@ -114,7 +117,7 @@ async def test_options_flow_live_tv_in_apps(hass, client, apps, inputs):
|
||||||
assert result2["data"][CONF_SOURCES] == ["Live TV", "Input01", "Input02"]
|
assert result2["data"][CONF_SOURCES] == ["Live TV", "Input01", "Input02"]
|
||||||
|
|
||||||
|
|
||||||
async def test_options_flow_cannot_retrieve(hass, client):
|
async def test_options_flow_cannot_retrieve(hass: HomeAssistant, client) -> None:
|
||||||
"""Test options config flow cannot retrieve sources."""
|
"""Test options config flow cannot retrieve sources."""
|
||||||
entry = await setup_webostv(hass)
|
entry = await setup_webostv(hass)
|
||||||
|
|
||||||
|
@ -126,7 +129,7 @@ async def test_options_flow_cannot_retrieve(hass, client):
|
||||||
assert result["errors"] == {"base": "cannot_retrieve"}
|
assert result["errors"] == {"base": "cannot_retrieve"}
|
||||||
|
|
||||||
|
|
||||||
async def test_form_cannot_connect(hass, client):
|
async def test_form_cannot_connect(hass: HomeAssistant, client) -> None:
|
||||||
"""Test we handle cannot connect error."""
|
"""Test we handle cannot connect error."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
@ -144,7 +147,7 @@ async def test_form_cannot_connect(hass, client):
|
||||||
assert result2["errors"] == {"base": "cannot_connect"}
|
assert result2["errors"] == {"base": "cannot_connect"}
|
||||||
|
|
||||||
|
|
||||||
async def test_form_pairexception(hass, client):
|
async def test_form_pairexception(hass: HomeAssistant, client) -> None:
|
||||||
"""Test pairing exception."""
|
"""Test pairing exception."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
@ -162,7 +165,7 @@ async def test_form_pairexception(hass, client):
|
||||||
assert result2["reason"] == "error_pairing"
|
assert result2["reason"] == "error_pairing"
|
||||||
|
|
||||||
|
|
||||||
async def test_entry_already_configured(hass, client):
|
async def test_entry_already_configured(hass: HomeAssistant, client) -> None:
|
||||||
"""Test entry already configured."""
|
"""Test entry already configured."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
assert client
|
assert client
|
||||||
|
@ -177,7 +180,7 @@ async def test_entry_already_configured(hass, client):
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
async def test_form_ssdp(hass, client):
|
async def test_form_ssdp(hass: HomeAssistant, client) -> None:
|
||||||
"""Test that the ssdp confirmation form is served."""
|
"""Test that the ssdp confirmation form is served."""
|
||||||
assert client
|
assert client
|
||||||
|
|
||||||
|
@ -191,7 +194,7 @@ async def test_form_ssdp(hass, client):
|
||||||
assert result["step_id"] == "pairing"
|
assert result["step_id"] == "pairing"
|
||||||
|
|
||||||
|
|
||||||
async def test_ssdp_in_progress(hass, client):
|
async def test_ssdp_in_progress(hass: HomeAssistant, client) -> None:
|
||||||
"""Test abort if ssdp paring is already in progress."""
|
"""Test abort if ssdp paring is already in progress."""
|
||||||
assert client
|
assert client
|
||||||
|
|
||||||
|
@ -214,7 +217,7 @@ async def test_ssdp_in_progress(hass, client):
|
||||||
assert result2["reason"] == "already_in_progress"
|
assert result2["reason"] == "already_in_progress"
|
||||||
|
|
||||||
|
|
||||||
async def test_ssdp_update_uuid(hass, client):
|
async def test_ssdp_update_uuid(hass: HomeAssistant, client) -> None:
|
||||||
"""Test that ssdp updates existing host entry uuid."""
|
"""Test that ssdp updates existing host entry uuid."""
|
||||||
entry = await setup_webostv(hass, None)
|
entry = await setup_webostv(hass, None)
|
||||||
assert client
|
assert client
|
||||||
|
@ -230,7 +233,7 @@ async def test_ssdp_update_uuid(hass, client):
|
||||||
assert entry.unique_id == MOCK_DISCOVERY_INFO.upnp[ssdp.ATTR_UPNP_UDN][5:]
|
assert entry.unique_id == MOCK_DISCOVERY_INFO.upnp[ssdp.ATTR_UPNP_UDN][5:]
|
||||||
|
|
||||||
|
|
||||||
async def test_ssdp_not_update_uuid(hass, client):
|
async def test_ssdp_not_update_uuid(hass: HomeAssistant, client) -> None:
|
||||||
"""Test that ssdp not updates different host."""
|
"""Test that ssdp not updates different host."""
|
||||||
entry = await setup_webostv(hass, None)
|
entry = await setup_webostv(hass, None)
|
||||||
assert client
|
assert client
|
||||||
|
@ -249,7 +252,7 @@ async def test_ssdp_not_update_uuid(hass, client):
|
||||||
assert entry.unique_id is None
|
assert entry.unique_id is None
|
||||||
|
|
||||||
|
|
||||||
async def test_form_abort_uuid_configured(hass, client):
|
async def test_form_abort_uuid_configured(hass: HomeAssistant, client) -> None:
|
||||||
"""Test abort if uuid is already configured, verify host update."""
|
"""Test abort if uuid is already configured, verify host update."""
|
||||||
entry = await setup_webostv(hass, MOCK_DISCOVERY_INFO.upnp[ssdp.ATTR_UPNP_UDN][5:])
|
entry = await setup_webostv(hass, MOCK_DISCOVERY_INFO.upnp[ssdp.ATTR_UPNP_UDN][5:])
|
||||||
assert client
|
assert client
|
||||||
|
@ -291,7 +294,7 @@ async def test_form_abort_uuid_configured(hass, client):
|
||||||
assert entry.data[CONF_HOST] == "new_host"
|
assert entry.data[CONF_HOST] == "new_host"
|
||||||
|
|
||||||
|
|
||||||
async def test_reauth_successful(hass, client, monkeypatch):
|
async def test_reauth_successful(hass: HomeAssistant, client, monkeypatch) -> None:
|
||||||
"""Test that the reauthorization is successful."""
|
"""Test that the reauthorization is successful."""
|
||||||
entry = await setup_webostv(hass)
|
entry = await setup_webostv(hass)
|
||||||
assert client
|
assert client
|
||||||
|
@ -326,7 +329,9 @@ async def test_reauth_successful(hass, client, monkeypatch):
|
||||||
(ConnectionRefusedError, "reauth_unsuccessful"),
|
(ConnectionRefusedError, "reauth_unsuccessful"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_reauth_errors(hass, client, monkeypatch, side_effect, reason):
|
async def test_reauth_errors(
|
||||||
|
hass: HomeAssistant, client, monkeypatch, side_effect, reason
|
||||||
|
) -> None:
|
||||||
"""Test reauthorization errors."""
|
"""Test reauthorization errors."""
|
||||||
entry = await setup_webostv(hass)
|
entry = await setup_webostv(hass)
|
||||||
assert client
|
assert client
|
||||||
|
|
|
@ -8,6 +8,7 @@ from homeassistant.components.device_automation.exceptions import (
|
||||||
)
|
)
|
||||||
from homeassistant.components.webostv import DOMAIN, device_trigger
|
from homeassistant.components.webostv import DOMAIN, device_trigger
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.device_registry import async_get as get_dev_reg
|
from homeassistant.helpers.device_registry import async_get as get_dev_reg
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
@ -18,7 +19,7 @@ from .const import ENTITY_ID, FAKE_UUID
|
||||||
from tests.common import MockConfigEntry, async_get_device_automations
|
from tests.common import MockConfigEntry, async_get_device_automations
|
||||||
|
|
||||||
|
|
||||||
async def test_get_triggers(hass, client):
|
async def test_get_triggers(hass: HomeAssistant, client) -> None:
|
||||||
"""Test we get the expected triggers."""
|
"""Test we get the expected triggers."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
|
|
||||||
|
@ -39,7 +40,7 @@ async def test_get_triggers(hass, client):
|
||||||
assert turn_on_trigger in triggers
|
assert turn_on_trigger in triggers
|
||||||
|
|
||||||
|
|
||||||
async def test_if_fires_on_turn_on_request(hass, calls, client):
|
async def test_if_fires_on_turn_on_request(hass: HomeAssistant, calls, client) -> None:
|
||||||
"""Test for turn_on and turn_off triggers firing."""
|
"""Test for turn_on and turn_off triggers firing."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
|
|
||||||
|
@ -98,7 +99,7 @@ async def test_if_fires_on_turn_on_request(hass, calls, client):
|
||||||
assert calls[1].data["id"] == 0
|
assert calls[1].data["id"] == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_failure_scenarios(hass, client):
|
async def test_failure_scenarios(hass: HomeAssistant, client) -> None:
|
||||||
"""Test failure scenarios."""
|
"""Test failure scenarios."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,12 @@ from aiowebostv import WebOsTvPairError
|
||||||
from homeassistant.components.webostv.const import DOMAIN
|
from homeassistant.components.webostv.const import DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
||||||
from homeassistant.const import CONF_CLIENT_SECRET
|
from homeassistant.const import CONF_CLIENT_SECRET
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from . import setup_webostv
|
from . import setup_webostv
|
||||||
|
|
||||||
|
|
||||||
async def test_reauth_setup_entry(hass, client, monkeypatch):
|
async def test_reauth_setup_entry(hass: HomeAssistant, client, monkeypatch) -> None:
|
||||||
"""Test reauth flow triggered by setup entry."""
|
"""Test reauth flow triggered by setup entry."""
|
||||||
monkeypatch.setattr(client, "is_connected", Mock(return_value=False))
|
monkeypatch.setattr(client, "is_connected", Mock(return_value=False))
|
||||||
monkeypatch.setattr(client, "connect", Mock(side_effect=WebOsTvPairError))
|
monkeypatch.setattr(client, "connect", Mock(side_effect=WebOsTvPairError))
|
||||||
|
@ -30,7 +31,7 @@ async def test_reauth_setup_entry(hass, client, monkeypatch):
|
||||||
assert flow["context"].get("entry_id") == entry.entry_id
|
assert flow["context"].get("entry_id") == entry.entry_id
|
||||||
|
|
||||||
|
|
||||||
async def test_key_update_setup_entry(hass, client, monkeypatch):
|
async def test_key_update_setup_entry(hass: HomeAssistant, client, monkeypatch) -> None:
|
||||||
"""Test key update from setup entry."""
|
"""Test key update from setup entry."""
|
||||||
monkeypatch.setattr(client, "client_key", "new_key")
|
monkeypatch.setattr(client, "client_key", "new_key")
|
||||||
entry = await setup_webostv(hass)
|
entry = await setup_webostv(hass)
|
||||||
|
|
|
@ -59,7 +59,7 @@ from homeassistant.const import (
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
)
|
)
|
||||||
from homeassistant.core import State
|
from homeassistant.core import HomeAssistant, State
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import device_registry
|
from homeassistant.helpers import device_registry
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
@ -69,6 +69,8 @@ from . import setup_webostv
|
||||||
from .const import CHANNEL_2, ENTITY_ID, TV_NAME
|
from .const import CHANNEL_2, ENTITY_ID, TV_NAME
|
||||||
|
|
||||||
from tests.common import async_fire_time_changed, mock_restore_cache
|
from tests.common import async_fire_time_changed, mock_restore_cache
|
||||||
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
@ -81,7 +83,9 @@ from tests.common import async_fire_time_changed, mock_restore_cache
|
||||||
(SERVICE_VOLUME_SET, {ATTR_MEDIA_VOLUME_LEVEL: 0.0}, ("set_volume", 0)),
|
(SERVICE_VOLUME_SET, {ATTR_MEDIA_VOLUME_LEVEL: 0.0}, ("set_volume", 0)),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_services_with_parameters(hass, client, service, attr_data, client_call):
|
async def test_services_with_parameters(
|
||||||
|
hass: HomeAssistant, client, service, attr_data, client_call
|
||||||
|
) -> None:
|
||||||
"""Test services that has parameters in calls."""
|
"""Test services that has parameters in calls."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
|
|
||||||
|
@ -102,7 +106,7 @@ async def test_services_with_parameters(hass, client, service, attr_data, client
|
||||||
(SERVICE_MEDIA_STOP, "stop"),
|
(SERVICE_MEDIA_STOP, "stop"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_services(hass, client, service, client_call):
|
async def test_services(hass: HomeAssistant, client, service, client_call) -> None:
|
||||||
"""Test simple services without parameters."""
|
"""Test simple services without parameters."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
|
|
||||||
|
@ -112,7 +116,7 @@ async def test_services(hass, client, service, client_call):
|
||||||
getattr(client, client_call).assert_called_once()
|
getattr(client, client_call).assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
async def test_media_play_pause(hass, client):
|
async def test_media_play_pause(hass: HomeAssistant, client) -> None:
|
||||||
"""Test media play pause service."""
|
"""Test media play pause service."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
|
|
||||||
|
@ -143,8 +147,8 @@ async def test_media_play_pause(hass, client):
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_media_next_previous_track(
|
async def test_media_next_previous_track(
|
||||||
hass, client, service, client_call, monkeypatch
|
hass: HomeAssistant, client, service, client_call, monkeypatch
|
||||||
):
|
) -> None:
|
||||||
"""Test media next/previous track services."""
|
"""Test media next/previous track services."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
|
|
||||||
|
@ -164,7 +168,9 @@ async def test_media_next_previous_track(
|
||||||
getattr(client, client_call[1]).assert_called_once()
|
getattr(client, client_call[1]).assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
async def test_select_source_with_empty_source_list(hass, client, caplog):
|
async def test_select_source_with_empty_source_list(
|
||||||
|
hass: HomeAssistant, client, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
"""Ensure we don't call client methods when we don't have sources."""
|
"""Ensure we don't call client methods when we don't have sources."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
await client.mock_state_update()
|
await client.mock_state_update()
|
||||||
|
@ -180,7 +186,7 @@ async def test_select_source_with_empty_source_list(hass, client, caplog):
|
||||||
assert f"Source nonexistent not found for {TV_NAME}" in caplog.text
|
assert f"Source nonexistent not found for {TV_NAME}" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
async def test_select_app_source(hass, client):
|
async def test_select_app_source(hass: HomeAssistant, client) -> None:
|
||||||
"""Test select app source."""
|
"""Test select app source."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
await client.mock_state_update()
|
await client.mock_state_update()
|
||||||
|
@ -195,7 +201,7 @@ async def test_select_app_source(hass, client):
|
||||||
client.set_input.assert_not_called()
|
client.set_input.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
async def test_select_input_source(hass, client):
|
async def test_select_input_source(hass: HomeAssistant, client) -> None:
|
||||||
"""Test select input source."""
|
"""Test select input source."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
await client.mock_state_update()
|
await client.mock_state_update()
|
||||||
|
@ -210,7 +216,7 @@ async def test_select_input_source(hass, client):
|
||||||
client.set_input.assert_called_once_with("in1")
|
client.set_input.assert_called_once_with("in1")
|
||||||
|
|
||||||
|
|
||||||
async def test_button(hass, client):
|
async def test_button(hass: HomeAssistant, client) -> None:
|
||||||
"""Test generic button functionality."""
|
"""Test generic button functionality."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
|
|
||||||
|
@ -224,7 +230,7 @@ async def test_button(hass, client):
|
||||||
client.button.assert_called_with("test")
|
client.button.assert_called_with("test")
|
||||||
|
|
||||||
|
|
||||||
async def test_command(hass, client):
|
async def test_command(hass: HomeAssistant, client) -> None:
|
||||||
"""Test generic command functionality."""
|
"""Test generic command functionality."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
|
|
||||||
|
@ -237,7 +243,7 @@ async def test_command(hass, client):
|
||||||
client.request.assert_called_with("test", payload=None)
|
client.request.assert_called_with("test", payload=None)
|
||||||
|
|
||||||
|
|
||||||
async def test_command_with_optional_arg(hass, client):
|
async def test_command_with_optional_arg(hass: HomeAssistant, client) -> None:
|
||||||
"""Test generic command functionality."""
|
"""Test generic command functionality."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
|
|
||||||
|
@ -253,7 +259,7 @@ async def test_command_with_optional_arg(hass, client):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_select_sound_output(hass, client):
|
async def test_select_sound_output(hass: HomeAssistant, client) -> None:
|
||||||
"""Test select sound output service."""
|
"""Test select sound output service."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
|
|
||||||
|
@ -268,7 +274,9 @@ async def test_select_sound_output(hass, client):
|
||||||
client.change_sound_output.assert_called_once_with("external_speaker")
|
client.change_sound_output.assert_called_once_with("external_speaker")
|
||||||
|
|
||||||
|
|
||||||
async def test_device_info_startup_off(hass, client, monkeypatch):
|
async def test_device_info_startup_off(
|
||||||
|
hass: HomeAssistant, client, monkeypatch
|
||||||
|
) -> None:
|
||||||
"""Test device info when device is off at startup."""
|
"""Test device info when device is off at startup."""
|
||||||
monkeypatch.setattr(client, "system_info", None)
|
monkeypatch.setattr(client, "system_info", None)
|
||||||
monkeypatch.setattr(client, "is_on", False)
|
monkeypatch.setattr(client, "is_on", False)
|
||||||
|
@ -288,7 +296,7 @@ async def test_device_info_startup_off(hass, client, monkeypatch):
|
||||||
assert device.model is None
|
assert device.model is None
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_attributes(hass, client, monkeypatch):
|
async def test_entity_attributes(hass: HomeAssistant, client, monkeypatch) -> None:
|
||||||
"""Test entity attributes."""
|
"""Test entity attributes."""
|
||||||
entry = await setup_webostv(hass)
|
entry = await setup_webostv(hass)
|
||||||
await client.mock_state_update()
|
await client.mock_state_update()
|
||||||
|
@ -343,7 +351,7 @@ async def test_entity_attributes(hass, client, monkeypatch):
|
||||||
assert state.attributes.get(ATTR_SOUND_OUTPUT) is None
|
assert state.attributes.get(ATTR_SOUND_OUTPUT) is None
|
||||||
|
|
||||||
|
|
||||||
async def test_service_entity_id_none(hass, client):
|
async def test_service_entity_id_none(hass: HomeAssistant, client) -> None:
|
||||||
"""Test service call with none as entity id."""
|
"""Test service call with none as entity id."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
|
|
||||||
|
@ -366,7 +374,7 @@ async def test_service_entity_id_none(hass, client):
|
||||||
("20", "ch2id"), # Perfect Match by channel number
|
("20", "ch2id"), # Perfect Match by channel number
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_play_media(hass, client, media_id, ch_id):
|
async def test_play_media(hass: HomeAssistant, client, media_id, ch_id) -> None:
|
||||||
"""Test play media service."""
|
"""Test play media service."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
await client.mock_state_update()
|
await client.mock_state_update()
|
||||||
|
@ -381,7 +389,9 @@ async def test_play_media(hass, client, media_id, ch_id):
|
||||||
client.set_channel.assert_called_once_with(ch_id)
|
client.set_channel.assert_called_once_with(ch_id)
|
||||||
|
|
||||||
|
|
||||||
async def test_update_sources_live_tv_find(hass, client, monkeypatch):
|
async def test_update_sources_live_tv_find(
|
||||||
|
hass: HomeAssistant, client, monkeypatch
|
||||||
|
) -> None:
|
||||||
"""Test finding live TV app id in update sources."""
|
"""Test finding live TV app id in update sources."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
await client.mock_state_update()
|
await client.mock_state_update()
|
||||||
|
@ -463,7 +473,7 @@ async def test_update_sources_live_tv_find(hass, client, monkeypatch):
|
||||||
assert len(sources) == 1
|
assert len(sources) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_client_disconnected(hass, client, monkeypatch):
|
async def test_client_disconnected(hass: HomeAssistant, client, monkeypatch) -> None:
|
||||||
"""Test error not raised when client is disconnected."""
|
"""Test error not raised when client is disconnected."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
monkeypatch.setattr(client, "is_connected", Mock(return_value=False))
|
monkeypatch.setattr(client, "is_connected", Mock(return_value=False))
|
||||||
|
@ -473,7 +483,9 @@ async def test_client_disconnected(hass, client, monkeypatch):
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
|
||||||
async def test_control_error_handling(hass, client, caplog, monkeypatch):
|
async def test_control_error_handling(
|
||||||
|
hass: HomeAssistant, client, caplog: pytest.LogCaptureFixture, monkeypatch
|
||||||
|
) -> None:
|
||||||
"""Test control errors handling."""
|
"""Test control errors handling."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
monkeypatch.setattr(client, "play", Mock(side_effect=WebOsTvCommandError))
|
monkeypatch.setattr(client, "play", Mock(side_effect=WebOsTvCommandError))
|
||||||
|
@ -502,7 +514,7 @@ async def test_control_error_handling(hass, client, caplog, monkeypatch):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_supported_features(hass, client, monkeypatch):
|
async def test_supported_features(hass: HomeAssistant, client, monkeypatch) -> None:
|
||||||
"""Test test supported features."""
|
"""Test test supported features."""
|
||||||
monkeypatch.setattr(client, "sound_output", "lineout")
|
monkeypatch.setattr(client, "sound_output", "lineout")
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
|
@ -559,7 +571,9 @@ async def test_supported_features(hass, client, monkeypatch):
|
||||||
assert attrs[ATTR_SUPPORTED_FEATURES] == supported
|
assert attrs[ATTR_SUPPORTED_FEATURES] == supported
|
||||||
|
|
||||||
|
|
||||||
async def test_cached_supported_features(hass, client, monkeypatch):
|
async def test_cached_supported_features(
|
||||||
|
hass: HomeAssistant, client, monkeypatch
|
||||||
|
) -> None:
|
||||||
"""Test test supported features."""
|
"""Test test supported features."""
|
||||||
monkeypatch.setattr(client, "is_on", False)
|
monkeypatch.setattr(client, "is_on", False)
|
||||||
monkeypatch.setattr(client, "sound_output", None)
|
monkeypatch.setattr(client, "sound_output", None)
|
||||||
|
@ -664,7 +678,9 @@ async def test_cached_supported_features(hass, client, monkeypatch):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_supported_features_no_cache(hass, client, monkeypatch):
|
async def test_supported_features_no_cache(
|
||||||
|
hass: HomeAssistant, client, monkeypatch
|
||||||
|
) -> None:
|
||||||
"""Test supported features if device is off and no cache."""
|
"""Test supported features if device is off and no cache."""
|
||||||
monkeypatch.setattr(client, "is_on", False)
|
monkeypatch.setattr(client, "is_on", False)
|
||||||
monkeypatch.setattr(client, "sound_output", None)
|
monkeypatch.setattr(client, "sound_output", None)
|
||||||
|
@ -678,7 +694,7 @@ async def test_supported_features_no_cache(hass, client, monkeypatch):
|
||||||
assert attrs[ATTR_SUPPORTED_FEATURES] == supported
|
assert attrs[ATTR_SUPPORTED_FEATURES] == supported
|
||||||
|
|
||||||
|
|
||||||
async def test_supported_features_ignore_cache(hass, client):
|
async def test_supported_features_ignore_cache(hass: HomeAssistant, client) -> None:
|
||||||
"""Test ignore cached supported features if device is on at startup."""
|
"""Test ignore cached supported features if device is on at startup."""
|
||||||
mock_restore_cache(
|
mock_restore_cache(
|
||||||
hass,
|
hass,
|
||||||
|
@ -703,8 +719,12 @@ async def test_supported_features_ignore_cache(hass, client):
|
||||||
|
|
||||||
|
|
||||||
async def test_get_image_http(
|
async def test_get_image_http(
|
||||||
hass, client, hass_client_no_auth, aioclient_mock, monkeypatch
|
hass: HomeAssistant,
|
||||||
):
|
client,
|
||||||
|
hass_client_no_auth: ClientSessionGenerator,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
monkeypatch,
|
||||||
|
) -> None:
|
||||||
"""Test get image via http."""
|
"""Test get image via http."""
|
||||||
url = "http://something/valid_icon"
|
url = "http://something/valid_icon"
|
||||||
monkeypatch.setitem(client.apps[LIVE_TV_APP_ID], "icon", url)
|
monkeypatch.setitem(client.apps[LIVE_TV_APP_ID], "icon", url)
|
||||||
|
@ -724,8 +744,13 @@ async def test_get_image_http(
|
||||||
|
|
||||||
|
|
||||||
async def test_get_image_http_error(
|
async def test_get_image_http_error(
|
||||||
hass, client, hass_client_no_auth, aioclient_mock, caplog, monkeypatch
|
hass: HomeAssistant,
|
||||||
):
|
client,
|
||||||
|
hass_client_no_auth: ClientSessionGenerator,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
monkeypatch,
|
||||||
|
) -> None:
|
||||||
"""Test get image via http error."""
|
"""Test get image via http error."""
|
||||||
url = "http://something/icon_error"
|
url = "http://something/icon_error"
|
||||||
monkeypatch.setitem(client.apps[LIVE_TV_APP_ID], "icon", url)
|
monkeypatch.setitem(client.apps[LIVE_TV_APP_ID], "icon", url)
|
||||||
|
@ -747,8 +772,12 @@ async def test_get_image_http_error(
|
||||||
|
|
||||||
|
|
||||||
async def test_get_image_https(
|
async def test_get_image_https(
|
||||||
hass, client, hass_client_no_auth, aioclient_mock, monkeypatch
|
hass: HomeAssistant,
|
||||||
):
|
client,
|
||||||
|
hass_client_no_auth: ClientSessionGenerator,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
monkeypatch,
|
||||||
|
) -> None:
|
||||||
"""Test get image via http."""
|
"""Test get image via http."""
|
||||||
url = "https://something/valid_icon_https"
|
url = "https://something/valid_icon_https"
|
||||||
monkeypatch.setitem(client.apps[LIVE_TV_APP_ID], "icon", url)
|
monkeypatch.setitem(client.apps[LIVE_TV_APP_ID], "icon", url)
|
||||||
|
@ -767,7 +796,7 @@ async def test_get_image_https(
|
||||||
assert content == b"https_image"
|
assert content == b"https_image"
|
||||||
|
|
||||||
|
|
||||||
async def test_reauth_reconnect(hass, client, monkeypatch):
|
async def test_reauth_reconnect(hass: HomeAssistant, client, monkeypatch) -> None:
|
||||||
"""Test reauth flow triggered by reconnect."""
|
"""Test reauth flow triggered by reconnect."""
|
||||||
entry = await setup_webostv(hass)
|
entry = await setup_webostv(hass)
|
||||||
monkeypatch.setattr(client, "is_connected", Mock(return_value=False))
|
monkeypatch.setattr(client, "is_connected", Mock(return_value=False))
|
||||||
|
|
|
@ -21,7 +21,7 @@ ICON_PATH = "/some/path"
|
||||||
MESSAGE = "one, two, testing, testing"
|
MESSAGE = "one, two, testing, testing"
|
||||||
|
|
||||||
|
|
||||||
async def test_notify(hass, client):
|
async def test_notify(hass: HomeAssistant, client) -> None:
|
||||||
"""Test sending a message."""
|
"""Test sending a message."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
assert hass.services.has_service(NOTIFY_DOMAIN, TV_NAME)
|
assert hass.services.has_service(NOTIFY_DOMAIN, TV_NAME)
|
||||||
|
@ -71,7 +71,7 @@ async def test_notify(hass, client):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_notify_not_connected(hass, client, monkeypatch):
|
async def test_notify_not_connected(hass: HomeAssistant, client, monkeypatch) -> None:
|
||||||
"""Test sending a message when client is not connected."""
|
"""Test sending a message when client is not connected."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
assert hass.services.has_service(NOTIFY_DOMAIN, TV_NAME)
|
assert hass.services.has_service(NOTIFY_DOMAIN, TV_NAME)
|
||||||
|
@ -93,7 +93,9 @@ async def test_notify_not_connected(hass, client, monkeypatch):
|
||||||
client.send_message.assert_called_with(MESSAGE, icon_path=ICON_PATH)
|
client.send_message.assert_called_with(MESSAGE, icon_path=ICON_PATH)
|
||||||
|
|
||||||
|
|
||||||
async def test_icon_not_found(hass, caplog, client, monkeypatch):
|
async def test_icon_not_found(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, client, monkeypatch
|
||||||
|
) -> None:
|
||||||
"""Test notify icon not found error."""
|
"""Test notify icon not found error."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
assert hass.services.has_service(NOTIFY_DOMAIN, TV_NAME)
|
assert hass.services.has_service(NOTIFY_DOMAIN, TV_NAME)
|
||||||
|
@ -123,7 +125,14 @@ async def test_icon_not_found(hass, caplog, client, monkeypatch):
|
||||||
(ConnectionRefusedError, "TV unreachable"),
|
(ConnectionRefusedError, "TV unreachable"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_connection_errors(hass, caplog, client, monkeypatch, side_effect, error):
|
async def test_connection_errors(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
client,
|
||||||
|
monkeypatch,
|
||||||
|
side_effect,
|
||||||
|
error,
|
||||||
|
) -> None:
|
||||||
"""Test connection errors scenarios."""
|
"""Test connection errors scenarios."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
assert hass.services.has_service("notify", TV_NAME)
|
assert hass.services.has_service("notify", TV_NAME)
|
||||||
|
|
|
@ -6,6 +6,7 @@ import pytest
|
||||||
from homeassistant.components import automation
|
from homeassistant.components import automation
|
||||||
from homeassistant.components.webostv import DOMAIN
|
from homeassistant.components.webostv import DOMAIN
|
||||||
from homeassistant.const import SERVICE_RELOAD
|
from homeassistant.const import SERVICE_RELOAD
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.device_registry import async_get as get_dev_reg
|
from homeassistant.helpers.device_registry import async_get as get_dev_reg
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
@ -16,7 +17,9 @@ from .const import ENTITY_ID, FAKE_UUID
|
||||||
from tests.common import MockEntity, MockEntityPlatform
|
from tests.common import MockEntity, MockEntityPlatform
|
||||||
|
|
||||||
|
|
||||||
async def test_webostv_turn_on_trigger_device_id(hass, calls, client):
|
async def test_webostv_turn_on_trigger_device_id(
|
||||||
|
hass: HomeAssistant, calls, client
|
||||||
|
) -> None:
|
||||||
"""Test for turn_on triggers by device_id firing."""
|
"""Test for turn_on triggers by device_id firing."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
|
|
||||||
|
@ -74,7 +77,9 @@ async def test_webostv_turn_on_trigger_device_id(hass, calls, client):
|
||||||
assert len(calls) == 0
|
assert len(calls) == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_webostv_turn_on_trigger_entity_id(hass, calls, client):
|
async def test_webostv_turn_on_trigger_entity_id(
|
||||||
|
hass: HomeAssistant, calls, client
|
||||||
|
) -> None:
|
||||||
"""Test for turn_on triggers by entity_id firing."""
|
"""Test for turn_on triggers by entity_id firing."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
|
|
||||||
|
@ -113,7 +118,9 @@ async def test_webostv_turn_on_trigger_entity_id(hass, calls, client):
|
||||||
assert calls[0].data["id"] == 0
|
assert calls[0].data["id"] == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_wrong_trigger_platform_type(hass, caplog, client):
|
async def test_wrong_trigger_platform_type(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, client
|
||||||
|
) -> None:
|
||||||
"""Test wrong trigger platform type."""
|
"""Test wrong trigger platform type."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
|
|
||||||
|
@ -145,7 +152,9 @@ async def test_wrong_trigger_platform_type(hass, caplog, client):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_trigger_invalid_entity_id(hass, caplog, client):
|
async def test_trigger_invalid_entity_id(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, client
|
||||||
|
) -> None:
|
||||||
"""Test turn on trigger using invalid entity_id."""
|
"""Test turn on trigger using invalid entity_id."""
|
||||||
await setup_webostv(hass)
|
await setup_webostv(hass)
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,9 @@ from unittest.mock import patch
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant.auth.providers.legacy_api_password import (
|
||||||
|
LegacyApiPasswordAuthProvider,
|
||||||
|
)
|
||||||
from homeassistant.components.websocket_api.auth import (
|
from homeassistant.components.websocket_api.auth import (
|
||||||
TYPE_AUTH,
|
TYPE_AUTH,
|
||||||
TYPE_AUTH_INVALID,
|
TYPE_AUTH_INVALID,
|
||||||
|
@ -45,8 +48,12 @@ def track_connected(hass):
|
||||||
|
|
||||||
|
|
||||||
async def test_auth_events(
|
async def test_auth_events(
|
||||||
hass, no_auth_websocket_client, legacy_auth, hass_access_token, track_connected
|
hass: HomeAssistant,
|
||||||
):
|
no_auth_websocket_client,
|
||||||
|
legacy_auth: LegacyApiPasswordAuthProvider,
|
||||||
|
hass_access_token: str,
|
||||||
|
track_connected,
|
||||||
|
) -> None:
|
||||||
"""Test authenticating."""
|
"""Test authenticating."""
|
||||||
|
|
||||||
await test_auth_active_with_token(hass, no_auth_websocket_client, hass_access_token)
|
await test_auth_active_with_token(hass, no_auth_websocket_client, hass_access_token)
|
||||||
|
@ -60,7 +67,7 @@ async def test_auth_events(
|
||||||
assert len(track_connected["disconnected"]) == 1
|
assert len(track_connected["disconnected"]) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_auth_via_msg_incorrect_pass(no_auth_websocket_client):
|
async def test_auth_via_msg_incorrect_pass(no_auth_websocket_client) -> None:
|
||||||
"""Test authenticating."""
|
"""Test authenticating."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.websocket_api.auth.process_wrong_login",
|
"homeassistant.components.websocket_api.auth.process_wrong_login",
|
||||||
|
@ -77,7 +84,9 @@ async def test_auth_via_msg_incorrect_pass(no_auth_websocket_client):
|
||||||
assert msg["message"] == "Invalid access token or password"
|
assert msg["message"] == "Invalid access token or password"
|
||||||
|
|
||||||
|
|
||||||
async def test_auth_events_incorrect_pass(no_auth_websocket_client, track_connected):
|
async def test_auth_events_incorrect_pass(
|
||||||
|
no_auth_websocket_client, track_connected
|
||||||
|
) -> None:
|
||||||
"""Test authenticating."""
|
"""Test authenticating."""
|
||||||
|
|
||||||
await test_auth_via_msg_incorrect_pass(no_auth_websocket_client)
|
await test_auth_via_msg_incorrect_pass(no_auth_websocket_client)
|
||||||
|
@ -91,7 +100,7 @@ async def test_auth_events_incorrect_pass(no_auth_websocket_client, track_connec
|
||||||
assert not track_connected["disconnected"]
|
assert not track_connected["disconnected"]
|
||||||
|
|
||||||
|
|
||||||
async def test_pre_auth_only_auth_allowed(no_auth_websocket_client):
|
async def test_pre_auth_only_auth_allowed(no_auth_websocket_client) -> None:
|
||||||
"""Verify that before authentication, only auth messages are allowed."""
|
"""Verify that before authentication, only auth messages are allowed."""
|
||||||
await no_auth_websocket_client.send_json(
|
await no_auth_websocket_client.send_json(
|
||||||
{
|
{
|
||||||
|
@ -109,8 +118,8 @@ async def test_pre_auth_only_auth_allowed(no_auth_websocket_client):
|
||||||
|
|
||||||
|
|
||||||
async def test_auth_active_with_token(
|
async def test_auth_active_with_token(
|
||||||
hass, no_auth_websocket_client, hass_access_token
|
hass: HomeAssistant, no_auth_websocket_client, hass_access_token: str
|
||||||
):
|
) -> None:
|
||||||
"""Test authenticating with a token."""
|
"""Test authenticating with a token."""
|
||||||
await no_auth_websocket_client.send_json(
|
await no_auth_websocket_client.send_json(
|
||||||
{"type": TYPE_AUTH, "access_token": hass_access_token}
|
{"type": TYPE_AUTH, "access_token": hass_access_token}
|
||||||
|
@ -120,7 +129,11 @@ async def test_auth_active_with_token(
|
||||||
assert auth_msg["type"] == TYPE_AUTH_OK
|
assert auth_msg["type"] == TYPE_AUTH_OK
|
||||||
|
|
||||||
|
|
||||||
async def test_auth_active_user_inactive(hass, hass_client_no_auth, hass_access_token):
|
async def test_auth_active_user_inactive(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
hass_client_no_auth: ClientSessionGenerator,
|
||||||
|
hass_access_token: str,
|
||||||
|
) -> None:
|
||||||
"""Test authenticating with a token."""
|
"""Test authenticating with a token."""
|
||||||
refresh_token = await hass.auth.async_validate_access_token(hass_access_token)
|
refresh_token = await hass.auth.async_validate_access_token(hass_access_token)
|
||||||
refresh_token.user.is_active = False
|
refresh_token.user.is_active = False
|
||||||
|
@ -159,8 +172,10 @@ async def test_auth_active_with_password_not_allow(
|
||||||
|
|
||||||
|
|
||||||
async def test_auth_legacy_support_with_password(
|
async def test_auth_legacy_support_with_password(
|
||||||
hass, hass_client_no_auth, legacy_auth
|
hass: HomeAssistant,
|
||||||
):
|
hass_client_no_auth: ClientSessionGenerator,
|
||||||
|
legacy_auth: LegacyApiPasswordAuthProvider,
|
||||||
|
) -> None:
|
||||||
"""Test authenticating with a token."""
|
"""Test authenticating with a token."""
|
||||||
assert await async_setup_component(hass, "websocket_api", {})
|
assert await async_setup_component(hass, "websocket_api", {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -196,7 +211,9 @@ async def test_auth_with_invalid_token(
|
||||||
assert auth_msg["type"] == TYPE_AUTH_INVALID
|
assert auth_msg["type"] == TYPE_AUTH_INVALID
|
||||||
|
|
||||||
|
|
||||||
async def test_auth_close_after_revoke(hass, websocket_client, hass_access_token):
|
async def test_auth_close_after_revoke(
|
||||||
|
hass: HomeAssistant, websocket_client, hass_access_token: str
|
||||||
|
) -> None:
|
||||||
"""Test that a websocket is closed after the refresh token is revoked."""
|
"""Test that a websocket is closed after the refresh token is revoked."""
|
||||||
assert not websocket_client.closed
|
assert not websocket_client.closed
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,8 @@ from homeassistant.helpers.json import json_loads
|
||||||
from homeassistant.loader import async_get_integration
|
from homeassistant.loader import async_get_integration
|
||||||
from homeassistant.setup import DATA_SETUP_TIME, async_setup_component
|
from homeassistant.setup import DATA_SETUP_TIME, async_setup_component
|
||||||
|
|
||||||
from tests.common import MockEntity, MockEntityPlatform, async_mock_service
|
from tests.common import MockEntity, MockEntityPlatform, MockUser, async_mock_service
|
||||||
from tests.typing import WebSocketGenerator
|
from tests.typing import ClientSessionGenerator, WebSocketGenerator
|
||||||
|
|
||||||
STATE_KEY_SHORT_NAMES = {
|
STATE_KEY_SHORT_NAMES = {
|
||||||
"entity_id": "e",
|
"entity_id": "e",
|
||||||
|
@ -59,7 +59,7 @@ def _apply_entities_changes(state_dict: dict, change_dict: dict) -> None:
|
||||||
del state_dict[STATE_KEY_LONG_NAMES[key]][item]
|
del state_dict[STATE_KEY_LONG_NAMES[key]][item]
|
||||||
|
|
||||||
|
|
||||||
async def test_fire_event(hass, websocket_client):
|
async def test_fire_event(hass: HomeAssistant, websocket_client) -> None:
|
||||||
"""Test fire event command."""
|
"""Test fire event command."""
|
||||||
runs = []
|
runs = []
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ async def test_fire_event(hass, websocket_client):
|
||||||
assert runs[0].data == {"hello": "world"}
|
assert runs[0].data == {"hello": "world"}
|
||||||
|
|
||||||
|
|
||||||
async def test_fire_event_without_data(hass, websocket_client):
|
async def test_fire_event_without_data(hass: HomeAssistant, websocket_client) -> None:
|
||||||
"""Test fire event command."""
|
"""Test fire event command."""
|
||||||
runs = []
|
runs = []
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ async def test_fire_event_without_data(hass, websocket_client):
|
||||||
assert runs[0].data == {}
|
assert runs[0].data == {}
|
||||||
|
|
||||||
|
|
||||||
async def test_call_service(hass, websocket_client):
|
async def test_call_service(hass: HomeAssistant, websocket_client) -> None:
|
||||||
"""Test call service command."""
|
"""Test call service command."""
|
||||||
calls = async_mock_service(hass, "domain_test", "test_service")
|
calls = async_mock_service(hass, "domain_test", "test_service")
|
||||||
|
|
||||||
|
@ -145,7 +145,9 @@ async def test_call_service(hass, websocket_client):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("command", ("call_service", "call_service_action"))
|
@pytest.mark.parametrize("command", ("call_service", "call_service_action"))
|
||||||
async def test_call_service_blocking(hass, websocket_client, command):
|
async def test_call_service_blocking(
|
||||||
|
hass: HomeAssistant, websocket_client, command
|
||||||
|
) -> None:
|
||||||
"""Test call service commands block, except for homeassistant restart / stop."""
|
"""Test call service commands block, except for homeassistant restart / stop."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.core.ServiceRegistry.async_call", autospec=True
|
"homeassistant.core.ServiceRegistry.async_call", autospec=True
|
||||||
|
@ -221,7 +223,7 @@ async def test_call_service_blocking(hass, websocket_client, command):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_call_service_target(hass, websocket_client):
|
async def test_call_service_target(hass: HomeAssistant, websocket_client) -> None:
|
||||||
"""Test call service command with target."""
|
"""Test call service command with target."""
|
||||||
calls = async_mock_service(hass, "domain_test", "test_service")
|
calls = async_mock_service(hass, "domain_test", "test_service")
|
||||||
|
|
||||||
|
@ -257,7 +259,9 @@ async def test_call_service_target(hass, websocket_client):
|
||||||
assert call.context.as_dict() == msg["result"]["context"]
|
assert call.context.as_dict() == msg["result"]["context"]
|
||||||
|
|
||||||
|
|
||||||
async def test_call_service_target_template(hass, websocket_client):
|
async def test_call_service_target_template(
|
||||||
|
hass: HomeAssistant, websocket_client
|
||||||
|
) -> None:
|
||||||
"""Test call service command with target does not allow template."""
|
"""Test call service command with target does not allow template."""
|
||||||
await websocket_client.send_json(
|
await websocket_client.send_json(
|
||||||
{
|
{
|
||||||
|
@ -279,7 +283,7 @@ async def test_call_service_target_template(hass, websocket_client):
|
||||||
assert msg["error"]["code"] == const.ERR_INVALID_FORMAT
|
assert msg["error"]["code"] == const.ERR_INVALID_FORMAT
|
||||||
|
|
||||||
|
|
||||||
async def test_call_service_not_found(hass, websocket_client):
|
async def test_call_service_not_found(hass: HomeAssistant, websocket_client) -> None:
|
||||||
"""Test call service command."""
|
"""Test call service command."""
|
||||||
await websocket_client.send_json(
|
await websocket_client.send_json(
|
||||||
{
|
{
|
||||||
|
@ -298,7 +302,9 @@ async def test_call_service_not_found(hass, websocket_client):
|
||||||
assert msg["error"]["code"] == const.ERR_NOT_FOUND
|
assert msg["error"]["code"] == const.ERR_NOT_FOUND
|
||||||
|
|
||||||
|
|
||||||
async def test_call_service_child_not_found(hass, websocket_client):
|
async def test_call_service_child_not_found(
|
||||||
|
hass: HomeAssistant, websocket_client
|
||||||
|
) -> None:
|
||||||
"""Test not reporting not found errors if it's not the called service."""
|
"""Test not reporting not found errors if it's not the called service."""
|
||||||
|
|
||||||
async def serv_handler(call):
|
async def serv_handler(call):
|
||||||
|
@ -325,7 +331,7 @@ async def test_call_service_child_not_found(hass, websocket_client):
|
||||||
|
|
||||||
async def test_call_service_schema_validation_error(
|
async def test_call_service_schema_validation_error(
|
||||||
hass: HomeAssistant, websocket_client
|
hass: HomeAssistant, websocket_client
|
||||||
):
|
) -> None:
|
||||||
"""Test call service command with invalid service data."""
|
"""Test call service command with invalid service data."""
|
||||||
|
|
||||||
calls = []
|
calls = []
|
||||||
|
@ -394,7 +400,7 @@ async def test_call_service_schema_validation_error(
|
||||||
assert len(calls) == 0
|
assert len(calls) == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_call_service_error(hass, websocket_client):
|
async def test_call_service_error(hass: HomeAssistant, websocket_client) -> None:
|
||||||
"""Test call service command with error."""
|
"""Test call service command with error."""
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -441,7 +447,9 @@ async def test_call_service_error(hass, websocket_client):
|
||||||
assert msg["error"]["message"] == "value_error"
|
assert msg["error"]["message"] == "value_error"
|
||||||
|
|
||||||
|
|
||||||
async def test_subscribe_unsubscribe_events(hass, websocket_client):
|
async def test_subscribe_unsubscribe_events(
|
||||||
|
hass: HomeAssistant, websocket_client
|
||||||
|
) -> None:
|
||||||
"""Test subscribe/unsubscribe events command."""
|
"""Test subscribe/unsubscribe events command."""
|
||||||
init_count = sum(hass.bus.async_listeners().values())
|
init_count = sum(hass.bus.async_listeners().values())
|
||||||
|
|
||||||
|
@ -485,7 +493,7 @@ async def test_subscribe_unsubscribe_events(hass, websocket_client):
|
||||||
assert sum(hass.bus.async_listeners().values()) == init_count
|
assert sum(hass.bus.async_listeners().values()) == init_count
|
||||||
|
|
||||||
|
|
||||||
async def test_get_states(hass, websocket_client):
|
async def test_get_states(hass: HomeAssistant, websocket_client) -> None:
|
||||||
"""Test get_states command."""
|
"""Test get_states command."""
|
||||||
hass.states.async_set("greeting.hello", "world")
|
hass.states.async_set("greeting.hello", "world")
|
||||||
hass.states.async_set("greeting.bye", "universe")
|
hass.states.async_set("greeting.bye", "universe")
|
||||||
|
@ -504,7 +512,7 @@ async def test_get_states(hass, websocket_client):
|
||||||
assert msg["result"] == states
|
assert msg["result"] == states
|
||||||
|
|
||||||
|
|
||||||
async def test_get_services(hass, websocket_client):
|
async def test_get_services(hass: HomeAssistant, websocket_client) -> None:
|
||||||
"""Test get_services command."""
|
"""Test get_services command."""
|
||||||
await websocket_client.send_json({"id": 5, "type": "get_services"})
|
await websocket_client.send_json({"id": 5, "type": "get_services"})
|
||||||
|
|
||||||
|
@ -515,7 +523,7 @@ async def test_get_services(hass, websocket_client):
|
||||||
assert msg["result"] == hass.services.async_services()
|
assert msg["result"] == hass.services.async_services()
|
||||||
|
|
||||||
|
|
||||||
async def test_get_config(hass, websocket_client):
|
async def test_get_config(hass: HomeAssistant, websocket_client) -> None:
|
||||||
"""Test get_config command."""
|
"""Test get_config command."""
|
||||||
await websocket_client.send_json({"id": 5, "type": "get_config"})
|
await websocket_client.send_json({"id": 5, "type": "get_config"})
|
||||||
|
|
||||||
|
@ -542,7 +550,7 @@ async def test_get_config(hass, websocket_client):
|
||||||
assert msg["result"] == hass.config.as_dict()
|
assert msg["result"] == hass.config.as_dict()
|
||||||
|
|
||||||
|
|
||||||
async def test_ping(websocket_client):
|
async def test_ping(websocket_client) -> None:
|
||||||
"""Test get_panels command."""
|
"""Test get_panels command."""
|
||||||
await websocket_client.send_json({"id": 5, "type": "ping"})
|
await websocket_client.send_json({"id": 5, "type": "ping"})
|
||||||
|
|
||||||
|
@ -552,8 +560,10 @@ async def test_ping(websocket_client):
|
||||||
|
|
||||||
|
|
||||||
async def test_call_service_context_with_user(
|
async def test_call_service_context_with_user(
|
||||||
hass, hass_client_no_auth, hass_access_token
|
hass: HomeAssistant,
|
||||||
):
|
hass_client_no_auth: ClientSessionGenerator,
|
||||||
|
hass_access_token: str,
|
||||||
|
) -> None:
|
||||||
"""Test that the user is set in the service call context."""
|
"""Test that the user is set in the service call context."""
|
||||||
assert await async_setup_component(hass, "websocket_api", {})
|
assert await async_setup_component(hass, "websocket_api", {})
|
||||||
|
|
||||||
|
@ -592,7 +602,9 @@ async def test_call_service_context_with_user(
|
||||||
assert call.context.user_id == refresh_token.user.id
|
assert call.context.user_id == refresh_token.user.id
|
||||||
|
|
||||||
|
|
||||||
async def test_subscribe_requires_admin(websocket_client, hass_admin_user):
|
async def test_subscribe_requires_admin(
|
||||||
|
websocket_client, hass_admin_user: MockUser
|
||||||
|
) -> None:
|
||||||
"""Test subscribing events without being admin."""
|
"""Test subscribing events without being admin."""
|
||||||
hass_admin_user.groups = []
|
hass_admin_user.groups = []
|
||||||
await websocket_client.send_json(
|
await websocket_client.send_json(
|
||||||
|
@ -604,7 +616,9 @@ async def test_subscribe_requires_admin(websocket_client, hass_admin_user):
|
||||||
assert msg["error"]["code"] == const.ERR_UNAUTHORIZED
|
assert msg["error"]["code"] == const.ERR_UNAUTHORIZED
|
||||||
|
|
||||||
|
|
||||||
async def test_states_filters_visible(hass, hass_admin_user, websocket_client):
|
async def test_states_filters_visible(
|
||||||
|
hass: HomeAssistant, hass_admin_user: MockUser, websocket_client
|
||||||
|
) -> None:
|
||||||
"""Test we only get entities that we're allowed to see."""
|
"""Test we only get entities that we're allowed to see."""
|
||||||
hass_admin_user.mock_policy({"entities": {"entity_ids": {"test.entity": True}}})
|
hass_admin_user.mock_policy({"entities": {"entity_ids": {"test.entity": True}}})
|
||||||
hass.states.async_set("test.entity", "hello")
|
hass.states.async_set("test.entity", "hello")
|
||||||
|
@ -620,7 +634,7 @@ async def test_states_filters_visible(hass, hass_admin_user, websocket_client):
|
||||||
assert msg["result"][0]["entity_id"] == "test.entity"
|
assert msg["result"][0]["entity_id"] == "test.entity"
|
||||||
|
|
||||||
|
|
||||||
async def test_get_states_not_allows_nan(hass, websocket_client):
|
async def test_get_states_not_allows_nan(hass: HomeAssistant, websocket_client) -> None:
|
||||||
"""Test get_states command converts NaN to None."""
|
"""Test get_states command converts NaN to None."""
|
||||||
hass.states.async_set("greeting.hello", "world")
|
hass.states.async_set("greeting.hello", "world")
|
||||||
hass.states.async_set("greeting.bad", "data", {"hello": float("NaN")})
|
hass.states.async_set("greeting.bad", "data", {"hello": float("NaN")})
|
||||||
|
@ -643,8 +657,8 @@ async def test_get_states_not_allows_nan(hass, websocket_client):
|
||||||
|
|
||||||
|
|
||||||
async def test_subscribe_unsubscribe_events_whitelist(
|
async def test_subscribe_unsubscribe_events_whitelist(
|
||||||
hass, websocket_client, hass_admin_user
|
hass: HomeAssistant, websocket_client, hass_admin_user: MockUser
|
||||||
):
|
) -> None:
|
||||||
"""Test subscribe/unsubscribe events on whitelist."""
|
"""Test subscribe/unsubscribe events on whitelist."""
|
||||||
hass_admin_user.groups = []
|
hass_admin_user.groups = []
|
||||||
|
|
||||||
|
@ -680,8 +694,8 @@ async def test_subscribe_unsubscribe_events_whitelist(
|
||||||
|
|
||||||
|
|
||||||
async def test_subscribe_unsubscribe_events_state_changed(
|
async def test_subscribe_unsubscribe_events_state_changed(
|
||||||
hass, websocket_client, hass_admin_user
|
hass: HomeAssistant, websocket_client, hass_admin_user: MockUser
|
||||||
):
|
) -> None:
|
||||||
"""Test subscribe/unsubscribe state_changed events."""
|
"""Test subscribe/unsubscribe state_changed events."""
|
||||||
hass_admin_user.groups = []
|
hass_admin_user.groups = []
|
||||||
hass_admin_user.mock_policy({"entities": {"entity_ids": {"light.permitted": True}}})
|
hass_admin_user.mock_policy({"entities": {"entity_ids": {"light.permitted": True}}})
|
||||||
|
@ -706,8 +720,8 @@ async def test_subscribe_unsubscribe_events_state_changed(
|
||||||
|
|
||||||
|
|
||||||
async def test_subscribe_entities_with_unserializable_state(
|
async def test_subscribe_entities_with_unserializable_state(
|
||||||
hass, websocket_client, hass_admin_user
|
hass: HomeAssistant, websocket_client, hass_admin_user: MockUser
|
||||||
):
|
) -> None:
|
||||||
"""Test subscribe entities with an unserializeable state."""
|
"""Test subscribe entities with an unserializeable state."""
|
||||||
|
|
||||||
class CannotSerializeMe:
|
class CannotSerializeMe:
|
||||||
|
@ -822,7 +836,9 @@ async def test_subscribe_entities_with_unserializable_state(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_subscribe_unsubscribe_entities(hass, websocket_client, hass_admin_user):
|
async def test_subscribe_unsubscribe_entities(
|
||||||
|
hass: HomeAssistant, websocket_client, hass_admin_user: MockUser
|
||||||
|
) -> None:
|
||||||
"""Test subscribe/unsubscribe entities."""
|
"""Test subscribe/unsubscribe entities."""
|
||||||
|
|
||||||
hass.states.async_set("light.permitted", "off", {"color": "red"})
|
hass.states.async_set("light.permitted", "off", {"color": "red"})
|
||||||
|
@ -987,8 +1003,8 @@ async def test_subscribe_unsubscribe_entities(hass, websocket_client, hass_admin
|
||||||
|
|
||||||
|
|
||||||
async def test_subscribe_unsubscribe_entities_specific_entities(
|
async def test_subscribe_unsubscribe_entities_specific_entities(
|
||||||
hass, websocket_client, hass_admin_user
|
hass: HomeAssistant, websocket_client, hass_admin_user: MockUser
|
||||||
):
|
) -> None:
|
||||||
"""Test subscribe/unsubscribe entities with a list of entity ids."""
|
"""Test subscribe/unsubscribe entities with a list of entity ids."""
|
||||||
|
|
||||||
hass.states.async_set("light.permitted", "off", {"color": "red"})
|
hass.states.async_set("light.permitted", "off", {"color": "red"})
|
||||||
|
@ -1048,7 +1064,9 @@ async def test_subscribe_unsubscribe_entities_specific_entities(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_render_template_renders_template(hass, websocket_client):
|
async def test_render_template_renders_template(
|
||||||
|
hass: HomeAssistant, websocket_client
|
||||||
|
) -> None:
|
||||||
"""Test simple template is rendered and updated."""
|
"""Test simple template is rendered and updated."""
|
||||||
hass.states.async_set("light.test", "on")
|
hass.states.async_set("light.test", "on")
|
||||||
|
|
||||||
|
@ -1095,7 +1113,9 @@ async def test_render_template_renders_template(hass, websocket_client):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_render_template_with_timeout_and_variables(hass, websocket_client):
|
async def test_render_template_with_timeout_and_variables(
|
||||||
|
hass: HomeAssistant, websocket_client
|
||||||
|
) -> None:
|
||||||
"""Test a template with a timeout and variables renders without error."""
|
"""Test a template with a timeout and variables renders without error."""
|
||||||
await websocket_client.send_json(
|
await websocket_client.send_json(
|
||||||
{
|
{
|
||||||
|
@ -1128,8 +1148,8 @@ async def test_render_template_with_timeout_and_variables(hass, websocket_client
|
||||||
|
|
||||||
|
|
||||||
async def test_render_template_manual_entity_ids_no_longer_needed(
|
async def test_render_template_manual_entity_ids_no_longer_needed(
|
||||||
hass, websocket_client
|
hass: HomeAssistant, websocket_client
|
||||||
):
|
) -> None:
|
||||||
"""Test that updates to specified entity ids cause a template rerender."""
|
"""Test that updates to specified entity ids cause a template rerender."""
|
||||||
hass.states.async_set("light.test", "on")
|
hass.states.async_set("light.test", "on")
|
||||||
|
|
||||||
|
@ -1185,7 +1205,9 @@ async def test_render_template_manual_entity_ids_no_longer_needed(
|
||||||
"{{ now() | unknown_filter }}",
|
"{{ now() | unknown_filter }}",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_render_template_with_error(hass, websocket_client, caplog, template):
|
async def test_render_template_with_error(
|
||||||
|
hass: HomeAssistant, websocket_client, caplog: pytest.LogCaptureFixture, template
|
||||||
|
) -> None:
|
||||||
"""Test a template with an error."""
|
"""Test a template with an error."""
|
||||||
await websocket_client.send_json(
|
await websocket_client.send_json(
|
||||||
{"id": 5, "type": "render_template", "template": template, "strict": True}
|
{"id": 5, "type": "render_template", "template": template, "strict": True}
|
||||||
|
@ -1211,8 +1233,8 @@ async def test_render_template_with_error(hass, websocket_client, caplog, templa
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_render_template_with_timeout_and_error(
|
async def test_render_template_with_timeout_and_error(
|
||||||
hass, websocket_client, caplog, template
|
hass: HomeAssistant, websocket_client, caplog: pytest.LogCaptureFixture, template
|
||||||
):
|
) -> None:
|
||||||
"""Test a template with an error with a timeout."""
|
"""Test a template with an error with a timeout."""
|
||||||
await websocket_client.send_json(
|
await websocket_client.send_json(
|
||||||
{
|
{
|
||||||
|
@ -1234,7 +1256,9 @@ async def test_render_template_with_timeout_and_error(
|
||||||
assert "TemplateError" not in caplog.text
|
assert "TemplateError" not in caplog.text
|
||||||
|
|
||||||
|
|
||||||
async def test_render_template_error_in_template_code(hass, websocket_client, caplog):
|
async def test_render_template_error_in_template_code(
|
||||||
|
hass: HomeAssistant, websocket_client, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
"""Test a template that will throw in template.py."""
|
"""Test a template that will throw in template.py."""
|
||||||
await websocket_client.send_json(
|
await websocket_client.send_json(
|
||||||
{"id": 5, "type": "render_template", "template": "{{ now() | random }}"}
|
{"id": 5, "type": "render_template", "template": "{{ now() | random }}"}
|
||||||
|
@ -1249,7 +1273,9 @@ async def test_render_template_error_in_template_code(hass, websocket_client, ca
|
||||||
assert "TemplateError" not in caplog.text
|
assert "TemplateError" not in caplog.text
|
||||||
|
|
||||||
|
|
||||||
async def test_render_template_with_delayed_error(hass, websocket_client, caplog):
|
async def test_render_template_with_delayed_error(
|
||||||
|
hass: HomeAssistant, websocket_client, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
"""Test a template with an error that only happens after a state change."""
|
"""Test a template with an error that only happens after a state change."""
|
||||||
hass.states.async_set("sensor.test", "on")
|
hass.states.async_set("sensor.test", "on")
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -1299,7 +1325,9 @@ async def test_render_template_with_delayed_error(hass, websocket_client, caplog
|
||||||
assert "TemplateError" not in caplog.text
|
assert "TemplateError" not in caplog.text
|
||||||
|
|
||||||
|
|
||||||
async def test_render_template_with_timeout(hass, websocket_client, caplog):
|
async def test_render_template_with_timeout(
|
||||||
|
hass: HomeAssistant, websocket_client, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
"""Test a template that will timeout."""
|
"""Test a template that will timeout."""
|
||||||
|
|
||||||
slow_template_str = """
|
slow_template_str = """
|
||||||
|
@ -1328,7 +1356,9 @@ async def test_render_template_with_timeout(hass, websocket_client, caplog):
|
||||||
assert "TemplateError" not in caplog.text
|
assert "TemplateError" not in caplog.text
|
||||||
|
|
||||||
|
|
||||||
async def test_render_template_returns_with_match_all(hass, websocket_client):
|
async def test_render_template_returns_with_match_all(
|
||||||
|
hass: HomeAssistant, websocket_client
|
||||||
|
) -> None:
|
||||||
"""Test that a template that would match with all entities still return success."""
|
"""Test that a template that would match with all entities still return success."""
|
||||||
await websocket_client.send_json(
|
await websocket_client.send_json(
|
||||||
{"id": 5, "type": "render_template", "template": "State is: {{ 42 }}"}
|
{"id": 5, "type": "render_template", "template": "State is: {{ 42 }}"}
|
||||||
|
@ -1340,7 +1370,7 @@ async def test_render_template_returns_with_match_all(hass, websocket_client):
|
||||||
assert msg["success"]
|
assert msg["success"]
|
||||||
|
|
||||||
|
|
||||||
async def test_manifest_list(hass, websocket_client):
|
async def test_manifest_list(hass: HomeAssistant, websocket_client) -> None:
|
||||||
"""Test loading manifests."""
|
"""Test loading manifests."""
|
||||||
http = await async_get_integration(hass, "http")
|
http = await async_get_integration(hass, "http")
|
||||||
websocket_api = await async_get_integration(hass, "websocket_api")
|
websocket_api = await async_get_integration(hass, "websocket_api")
|
||||||
|
@ -1357,7 +1387,9 @@ async def test_manifest_list(hass, websocket_client):
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
async def test_manifest_list_specific_integrations(hass, websocket_client):
|
async def test_manifest_list_specific_integrations(
|
||||||
|
hass: HomeAssistant, websocket_client
|
||||||
|
) -> None:
|
||||||
"""Test loading manifests for specific integrations."""
|
"""Test loading manifests for specific integrations."""
|
||||||
websocket_api = await async_get_integration(hass, "websocket_api")
|
websocket_api = await async_get_integration(hass, "websocket_api")
|
||||||
|
|
||||||
|
@ -1376,7 +1408,7 @@ async def test_manifest_list_specific_integrations(hass, websocket_client):
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
async def test_manifest_get(hass, websocket_client):
|
async def test_manifest_get(hass: HomeAssistant, websocket_client) -> None:
|
||||||
"""Test getting a manifest."""
|
"""Test getting a manifest."""
|
||||||
hue = await async_get_integration(hass, "hue")
|
hue = await async_get_integration(hass, "hue")
|
||||||
|
|
||||||
|
@ -1402,7 +1434,9 @@ async def test_manifest_get(hass, websocket_client):
|
||||||
assert msg["error"]["code"] == "not_found"
|
assert msg["error"]["code"] == "not_found"
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_source_admin(hass, websocket_client, hass_admin_user):
|
async def test_entity_source_admin(
|
||||||
|
hass: HomeAssistant, websocket_client, hass_admin_user: MockUser
|
||||||
|
) -> None:
|
||||||
"""Check that we fetch sources correctly."""
|
"""Check that we fetch sources correctly."""
|
||||||
platform = MockEntityPlatform(hass)
|
platform = MockEntityPlatform(hass)
|
||||||
|
|
||||||
|
@ -1521,7 +1555,7 @@ async def test_entity_source_admin(hass, websocket_client, hass_admin_user):
|
||||||
assert msg["error"]["code"] == const.ERR_UNAUTHORIZED
|
assert msg["error"]["code"] == const.ERR_UNAUTHORIZED
|
||||||
|
|
||||||
|
|
||||||
async def test_subscribe_trigger(hass, websocket_client):
|
async def test_subscribe_trigger(hass: HomeAssistant, websocket_client) -> None:
|
||||||
"""Test subscribing to a trigger."""
|
"""Test subscribing to a trigger."""
|
||||||
init_count = sum(hass.bus.async_listeners().values())
|
init_count = sum(hass.bus.async_listeners().values())
|
||||||
|
|
||||||
|
@ -1575,7 +1609,7 @@ async def test_subscribe_trigger(hass, websocket_client):
|
||||||
assert sum(hass.bus.async_listeners().values()) == init_count
|
assert sum(hass.bus.async_listeners().values()) == init_count
|
||||||
|
|
||||||
|
|
||||||
async def test_test_condition(hass, websocket_client):
|
async def test_test_condition(hass: HomeAssistant, websocket_client) -> None:
|
||||||
"""Test testing a condition."""
|
"""Test testing a condition."""
|
||||||
hass.states.async_set("hello.world", "paulus")
|
hass.states.async_set("hello.world", "paulus")
|
||||||
|
|
||||||
|
@ -1635,7 +1669,7 @@ async def test_test_condition(hass, websocket_client):
|
||||||
assert msg["result"]["result"] is False
|
assert msg["result"]["result"] is False
|
||||||
|
|
||||||
|
|
||||||
async def test_execute_script(hass, websocket_client):
|
async def test_execute_script(hass: HomeAssistant, websocket_client) -> None:
|
||||||
"""Test testing a condition."""
|
"""Test testing a condition."""
|
||||||
calls = async_mock_service(hass, "domain_test", "test_service")
|
calls = async_mock_service(hass, "domain_test", "test_service")
|
||||||
|
|
||||||
|
@ -1693,8 +1727,8 @@ async def test_execute_script(hass, websocket_client):
|
||||||
|
|
||||||
|
|
||||||
async def test_subscribe_unsubscribe_bootstrap_integrations(
|
async def test_subscribe_unsubscribe_bootstrap_integrations(
|
||||||
hass, websocket_client, hass_admin_user
|
hass: HomeAssistant, websocket_client, hass_admin_user: MockUser
|
||||||
):
|
) -> None:
|
||||||
"""Test subscribe/unsubscribe bootstrap_integrations."""
|
"""Test subscribe/unsubscribe bootstrap_integrations."""
|
||||||
await websocket_client.send_json(
|
await websocket_client.send_json(
|
||||||
{"id": 7, "type": "subscribe_bootstrap_integrations"}
|
{"id": 7, "type": "subscribe_bootstrap_integrations"}
|
||||||
|
@ -1714,7 +1748,9 @@ async def test_subscribe_unsubscribe_bootstrap_integrations(
|
||||||
assert msg["event"] == message
|
assert msg["event"] == message
|
||||||
|
|
||||||
|
|
||||||
async def test_integration_setup_info(hass, websocket_client, hass_admin_user):
|
async def test_integration_setup_info(
|
||||||
|
hass: HomeAssistant, websocket_client, hass_admin_user: MockUser
|
||||||
|
) -> None:
|
||||||
"""Test subscribe/unsubscribe bootstrap_integrations."""
|
"""Test subscribe/unsubscribe bootstrap_integrations."""
|
||||||
hass.data[DATA_SETUP_TIME] = {
|
hass.data[DATA_SETUP_TIME] = {
|
||||||
"august": datetime.timedelta(seconds=12.5),
|
"august": datetime.timedelta(seconds=12.5),
|
||||||
|
@ -1743,7 +1779,7 @@ async def test_integration_setup_info(hass, websocket_client, hass_admin_user):
|
||||||
("action", {"service": "domain_test.test_service"}),
|
("action", {"service": "domain_test.test_service"}),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
async def test_validate_config_works(websocket_client, key, config):
|
async def test_validate_config_works(websocket_client, key, config) -> None:
|
||||||
"""Test config validation."""
|
"""Test config validation."""
|
||||||
await websocket_client.send_json({"id": 7, "type": "validate_config", key: config})
|
await websocket_client.send_json({"id": 7, "type": "validate_config", key: config})
|
||||||
|
|
||||||
|
@ -1781,7 +1817,7 @@ async def test_validate_config_works(websocket_client, key, config):
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
async def test_validate_config_invalid(websocket_client, key, config, error):
|
async def test_validate_config_invalid(websocket_client, key, config, error) -> None:
|
||||||
"""Test config validation."""
|
"""Test config validation."""
|
||||||
await websocket_client.send_json({"id": 7, "type": "validate_config", key: config})
|
await websocket_client.send_json({"id": 7, "type": "validate_config", key: config})
|
||||||
|
|
||||||
|
@ -1792,7 +1828,9 @@ async def test_validate_config_invalid(websocket_client, key, config, error):
|
||||||
assert msg["result"] == {key: {"valid": False, "error": error}}
|
assert msg["result"] == {key: {"valid": False, "error": error}}
|
||||||
|
|
||||||
|
|
||||||
async def test_message_coalescing(hass, websocket_client, hass_admin_user):
|
async def test_message_coalescing(
|
||||||
|
hass: HomeAssistant, websocket_client, hass_admin_user: MockUser
|
||||||
|
) -> None:
|
||||||
"""Test enabling message coalescing."""
|
"""Test enabling message coalescing."""
|
||||||
await websocket_client.send_json(
|
await websocket_client.send_json(
|
||||||
{
|
{
|
||||||
|
@ -1863,8 +1901,8 @@ async def test_message_coalescing(hass, websocket_client, hass_admin_user):
|
||||||
|
|
||||||
|
|
||||||
async def test_message_coalescing_not_supported_by_websocket_client(
|
async def test_message_coalescing_not_supported_by_websocket_client(
|
||||||
hass, websocket_client, hass_admin_user
|
hass: HomeAssistant, websocket_client, hass_admin_user: MockUser
|
||||||
):
|
) -> None:
|
||||||
"""Test enabling message coalescing not supported by websocket client."""
|
"""Test enabling message coalescing not supported by websocket client."""
|
||||||
await websocket_client.send_json({"id": 7, "type": "subscribe_entities"})
|
await websocket_client.send_json({"id": 7, "type": "subscribe_entities"})
|
||||||
|
|
||||||
|
@ -1904,7 +1942,9 @@ async def test_message_coalescing_not_supported_by_websocket_client(
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
|
||||||
async def test_client_message_coalescing(hass, websocket_client, hass_admin_user):
|
async def test_client_message_coalescing(
|
||||||
|
hass: HomeAssistant, websocket_client, hass_admin_user: MockUser
|
||||||
|
) -> None:
|
||||||
"""Test client message coalescing."""
|
"""Test client message coalescing."""
|
||||||
await websocket_client.send_json(
|
await websocket_client.send_json(
|
||||||
[
|
[
|
||||||
|
|
|
@ -61,7 +61,7 @@ async def test_exception_handling(
|
||||||
code: str,
|
code: str,
|
||||||
err: str,
|
err: str,
|
||||||
log: str,
|
log: str,
|
||||||
):
|
) -> None:
|
||||||
"""Test handling of exceptions."""
|
"""Test handling of exceptions."""
|
||||||
send_messages = []
|
send_messages = []
|
||||||
user = MockUser()
|
user = MockUser()
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
"""Test decorators."""
|
"""Test decorators."""
|
||||||
from homeassistant.components import http, websocket_api
|
from homeassistant.components import http, websocket_api
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
|
||||||
async def test_async_response_request_context(hass, websocket_client):
|
async def test_async_response_request_context(
|
||||||
|
hass: HomeAssistant, websocket_client
|
||||||
|
) -> None:
|
||||||
"""Test we can access current request."""
|
"""Test we can access current request."""
|
||||||
|
|
||||||
def handle_request(request, connection, msg):
|
def handle_request(request, connection, msg):
|
||||||
|
@ -68,7 +71,7 @@ async def test_async_response_request_context(hass, websocket_client):
|
||||||
assert msg["error"]["code"] == "not_found"
|
assert msg["error"]["code"] == "not_found"
|
||||||
|
|
||||||
|
|
||||||
async def test_supervisor_only(hass, websocket_client):
|
async def test_supervisor_only(hass: HomeAssistant, websocket_client) -> None:
|
||||||
"""Test that only the Supervisor can make requests."""
|
"""Test that only the Supervisor can make requests."""
|
||||||
|
|
||||||
@websocket_api.ws_require_user(only_supervisor=True)
|
@websocket_api.ws_require_user(only_supervisor=True)
|
||||||
|
|
|
@ -7,9 +7,11 @@ from aiohttp import ServerDisconnectedError, WSMsgType, web
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.websocket_api import const, http
|
from homeassistant.components.websocket_api import const, http
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.util.dt import utcnow
|
from homeassistant.util.dt import utcnow
|
||||||
|
|
||||||
from tests.common import async_fire_time_changed
|
from tests.common import async_fire_time_changed
|
||||||
|
from tests.typing import WebSocketGenerator
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -26,7 +28,9 @@ def mock_low_peak():
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
async def test_pending_msg_overflow(hass, mock_low_queue, websocket_client):
|
async def test_pending_msg_overflow(
|
||||||
|
hass: HomeAssistant, mock_low_queue, websocket_client
|
||||||
|
) -> None:
|
||||||
"""Test get_panels command."""
|
"""Test get_panels command."""
|
||||||
for idx in range(10):
|
for idx in range(10):
|
||||||
await websocket_client.send_json({"id": idx + 1, "type": "ping"})
|
await websocket_client.send_json({"id": idx + 1, "type": "ping"})
|
||||||
|
@ -34,7 +38,12 @@ async def test_pending_msg_overflow(hass, mock_low_queue, websocket_client):
|
||||||
assert msg.type == WSMsgType.close
|
assert msg.type == WSMsgType.close
|
||||||
|
|
||||||
|
|
||||||
async def test_pending_msg_peak(hass, mock_low_peak, hass_ws_client, caplog):
|
async def test_pending_msg_peak(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
mock_low_peak,
|
||||||
|
hass_ws_client: WebSocketGenerator,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
) -> None:
|
||||||
"""Test pending msg overflow command."""
|
"""Test pending msg overflow command."""
|
||||||
orig_handler = http.WebSocketHandler
|
orig_handler = http.WebSocketHandler
|
||||||
instance = None
|
instance = None
|
||||||
|
@ -68,8 +77,11 @@ async def test_pending_msg_peak(hass, mock_low_peak, hass_ws_client, caplog):
|
||||||
|
|
||||||
|
|
||||||
async def test_pending_msg_peak_but_does_not_overflow(
|
async def test_pending_msg_peak_but_does_not_overflow(
|
||||||
hass, mock_low_peak, hass_ws_client, caplog
|
hass: HomeAssistant,
|
||||||
):
|
mock_low_peak,
|
||||||
|
hass_ws_client: WebSocketGenerator,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
) -> None:
|
||||||
"""Test pending msg hits the low peak but recovers and does not overflow."""
|
"""Test pending msg hits the low peak but recovers and does not overflow."""
|
||||||
orig_handler = http.WebSocketHandler
|
orig_handler = http.WebSocketHandler
|
||||||
instance: http.WebSocketHandler | None = None
|
instance: http.WebSocketHandler | None = None
|
||||||
|
@ -111,7 +123,9 @@ async def test_pending_msg_peak_but_does_not_overflow(
|
||||||
assert "Client unable to keep up with pending messages" not in caplog.text
|
assert "Client unable to keep up with pending messages" not in caplog.text
|
||||||
|
|
||||||
|
|
||||||
async def test_non_json_message(hass, websocket_client, caplog):
|
async def test_non_json_message(
|
||||||
|
hass: HomeAssistant, websocket_client, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
"""Test trying to serialize non JSON objects."""
|
"""Test trying to serialize non JSON objects."""
|
||||||
bad_data = object()
|
bad_data = object()
|
||||||
hass.states.async_set("test_domain.entity", "testing", {"bad": bad_data})
|
hass.states.async_set("test_domain.entity", "testing", {"bad": bad_data})
|
||||||
|
@ -128,7 +142,11 @@ async def test_non_json_message(hass, websocket_client, caplog):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_prepare_fail(hass, hass_ws_client, caplog):
|
async def test_prepare_fail(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
hass_ws_client: WebSocketGenerator,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
) -> None:
|
||||||
"""Test failing to prepare."""
|
"""Test failing to prepare."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.websocket_api.http.web.WebSocketResponse.prepare",
|
"homeassistant.components.websocket_api.http.web.WebSocketResponse.prepare",
|
||||||
|
|
|
@ -9,9 +9,10 @@ from homeassistant.components.websocket_api import (
|
||||||
const,
|
const,
|
||||||
messages,
|
messages,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
|
||||||
async def test_invalid_message_format(websocket_client):
|
async def test_invalid_message_format(websocket_client) -> None:
|
||||||
"""Test sending invalid JSON."""
|
"""Test sending invalid JSON."""
|
||||||
await websocket_client.send_json({"type": 5})
|
await websocket_client.send_json({"type": 5})
|
||||||
|
|
||||||
|
@ -23,7 +24,7 @@ async def test_invalid_message_format(websocket_client):
|
||||||
assert error["message"].startswith("Message incorrectly formatted")
|
assert error["message"].startswith("Message incorrectly formatted")
|
||||||
|
|
||||||
|
|
||||||
async def test_invalid_json(websocket_client):
|
async def test_invalid_json(websocket_client) -> None:
|
||||||
"""Test sending invalid JSON."""
|
"""Test sending invalid JSON."""
|
||||||
await websocket_client.send_str("this is not JSON")
|
await websocket_client.send_str("this is not JSON")
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ async def test_invalid_json(websocket_client):
|
||||||
assert msg.type == WSMsgType.close
|
assert msg.type == WSMsgType.close
|
||||||
|
|
||||||
|
|
||||||
async def test_quiting_hass(hass, websocket_client):
|
async def test_quiting_hass(hass: HomeAssistant, websocket_client) -> None:
|
||||||
"""Test sending invalid JSON."""
|
"""Test sending invalid JSON."""
|
||||||
with patch.object(hass.loop, "stop"):
|
with patch.object(hass.loop, "stop"):
|
||||||
await hass.async_stop()
|
await hass.async_stop()
|
||||||
|
@ -42,7 +43,7 @@ async def test_quiting_hass(hass, websocket_client):
|
||||||
assert msg.type == WSMsgType.CLOSE
|
assert msg.type == WSMsgType.CLOSE
|
||||||
|
|
||||||
|
|
||||||
async def test_unknown_command(websocket_client):
|
async def test_unknown_command(websocket_client) -> None:
|
||||||
"""Test get_panels command."""
|
"""Test get_panels command."""
|
||||||
await websocket_client.send_json({"id": 5, "type": "unknown_command"})
|
await websocket_client.send_json({"id": 5, "type": "unknown_command"})
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ async def test_unknown_command(websocket_client):
|
||||||
assert msg["error"]["code"] == const.ERR_UNKNOWN_COMMAND
|
assert msg["error"]["code"] == const.ERR_UNKNOWN_COMMAND
|
||||||
|
|
||||||
|
|
||||||
async def test_handler_failing(hass, websocket_client):
|
async def test_handler_failing(hass: HomeAssistant, websocket_client) -> None:
|
||||||
"""Test a command that raises."""
|
"""Test a command that raises."""
|
||||||
async_register_command(
|
async_register_command(
|
||||||
hass,
|
hass,
|
||||||
|
@ -68,7 +69,7 @@ async def test_handler_failing(hass, websocket_client):
|
||||||
assert msg["error"]["code"] == const.ERR_UNKNOWN_ERROR
|
assert msg["error"]["code"] == const.ERR_UNKNOWN_ERROR
|
||||||
|
|
||||||
|
|
||||||
async def test_invalid_vol(hass, websocket_client):
|
async def test_invalid_vol(hass: HomeAssistant, websocket_client) -> None:
|
||||||
"""Test a command that raises invalid vol error."""
|
"""Test a command that raises invalid vol error."""
|
||||||
async_register_command(
|
async_register_command(
|
||||||
hass,
|
hass,
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
"""Test Websocket API messages module."""
|
"""Test Websocket API messages module."""
|
||||||
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.websocket_api.messages import (
|
from homeassistant.components.websocket_api.messages import (
|
||||||
_cached_event_message as lru_event_cache,
|
_cached_event_message as lru_event_cache,
|
||||||
cached_event_message,
|
cached_event_message,
|
||||||
|
@ -77,7 +79,7 @@ async def test_cached_event_message_with_different_idens(hass: HomeAssistant) ->
|
||||||
assert cache_info.currsize == 1
|
assert cache_info.currsize == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_message_to_json(caplog):
|
async def test_message_to_json(caplog: pytest.LogCaptureFixture) -> None:
|
||||||
"""Test we can serialize websocket messages."""
|
"""Test we can serialize websocket messages."""
|
||||||
|
|
||||||
json_str = message_to_json({"id": 1, "message": "xyz"})
|
json_str = message_to_json({"id": 1, "message": "xyz"})
|
||||||
|
|
|
@ -1,13 +1,23 @@
|
||||||
"""Test cases for the API stream sensor."""
|
"""Test cases for the API stream sensor."""
|
||||||
|
from homeassistant.auth.providers.legacy_api_password import (
|
||||||
|
LegacyApiPasswordAuthProvider,
|
||||||
|
)
|
||||||
from homeassistant.bootstrap import async_setup_component
|
from homeassistant.bootstrap import async_setup_component
|
||||||
from homeassistant.components.websocket_api.auth import TYPE_AUTH_REQUIRED
|
from homeassistant.components.websocket_api.auth import TYPE_AUTH_REQUIRED
|
||||||
from homeassistant.components.websocket_api.http import URL
|
from homeassistant.components.websocket_api.http import URL
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .test_auth import test_auth_active_with_token
|
from .test_auth import test_auth_active_with_token
|
||||||
|
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
async def test_websocket_api(hass, hass_client_no_auth, hass_access_token, legacy_auth):
|
|
||||||
|
async def test_websocket_api(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
hass_client_no_auth: ClientSessionGenerator,
|
||||||
|
hass_access_token: str,
|
||||||
|
legacy_auth: LegacyApiPasswordAuthProvider,
|
||||||
|
) -> None:
|
||||||
"""Test API streams."""
|
"""Test API streams."""
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass, "sensor", {"sensor": {"platform": "websocket_api"}}
|
hass, "sensor", {"sensor": {"platform": "websocket_api"}}
|
||||||
|
|
Loading…
Add table
Reference in a new issue