mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
Fix mysensors tests typing (#51621)
This commit is contained in:
parent
3fa6c97801
commit
6de604a326
@ -25,13 +25,14 @@ from homeassistant.components.mysensors.const import (
|
|||||||
ConfGatewayType,
|
ConfGatewayType,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
async def get_form(
|
async def get_form(
|
||||||
hass: HomeAssistant, gatway_type: ConfGatewayType, expected_step_id: str
|
hass: HomeAssistant, gatway_type: ConfGatewayType, expected_step_id: str
|
||||||
):
|
) -> FlowResult:
|
||||||
"""Get a form for the given gateway type."""
|
"""Get a form for the given gateway type."""
|
||||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||||
stepuser = await hass.config_entries.flow.async_init(
|
stepuser = await hass.config_entries.flow.async_init(
|
||||||
@ -107,7 +108,7 @@ async def test_missing_mqtt(hass: HomeAssistant) -> None:
|
|||||||
assert result["errors"] == {"base": "mqtt_required"}
|
assert result["errors"] == {"base": "mqtt_required"}
|
||||||
|
|
||||||
|
|
||||||
async def test_config_serial(hass: HomeAssistant):
|
async def test_config_serial(hass: HomeAssistant) -> None:
|
||||||
"""Test configuring a gateway via serial."""
|
"""Test configuring a gateway via serial."""
|
||||||
step = await get_form(hass, CONF_GATEWAY_TYPE_SERIAL, "gw_serial")
|
step = await get_form(hass, CONF_GATEWAY_TYPE_SERIAL, "gw_serial")
|
||||||
flow_id = step["flow_id"]
|
flow_id = step["flow_id"]
|
||||||
@ -147,7 +148,7 @@ async def test_config_serial(hass: HomeAssistant):
|
|||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_config_tcp(hass: HomeAssistant):
|
async def test_config_tcp(hass: HomeAssistant) -> None:
|
||||||
"""Test configuring a gateway via tcp."""
|
"""Test configuring a gateway via tcp."""
|
||||||
step = await get_form(hass, CONF_GATEWAY_TYPE_TCP, "gw_tcp")
|
step = await get_form(hass, CONF_GATEWAY_TYPE_TCP, "gw_tcp")
|
||||||
flow_id = step["flow_id"]
|
flow_id = step["flow_id"]
|
||||||
@ -184,7 +185,7 @@ async def test_config_tcp(hass: HomeAssistant):
|
|||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_fail_to_connect(hass: HomeAssistant):
|
async def test_fail_to_connect(hass: HomeAssistant) -> None:
|
||||||
"""Test configuring a gateway via tcp."""
|
"""Test configuring a gateway via tcp."""
|
||||||
step = await get_form(hass, CONF_GATEWAY_TYPE_TCP, "gw_tcp")
|
step = await get_form(hass, CONF_GATEWAY_TYPE_TCP, "gw_tcp")
|
||||||
flow_id = step["flow_id"]
|
flow_id = step["flow_id"]
|
||||||
@ -209,8 +210,9 @@ async def test_fail_to_connect(hass: HomeAssistant):
|
|||||||
|
|
||||||
assert result2["type"] == "form"
|
assert result2["type"] == "form"
|
||||||
assert "errors" in result2
|
assert "errors" in result2
|
||||||
assert "base" in result2["errors"]
|
errors = result2["errors"]
|
||||||
assert result2["errors"]["base"] == "cannot_connect"
|
assert errors
|
||||||
|
assert errors.get("base") == "cannot_connect"
|
||||||
assert len(mock_setup.mock_calls) == 0
|
assert len(mock_setup.mock_calls) == 0
|
||||||
assert len(mock_setup_entry.mock_calls) == 0
|
assert len(mock_setup_entry.mock_calls) == 0
|
||||||
|
|
||||||
@ -367,12 +369,12 @@ async def test_fail_to_connect(hass: HomeAssistant):
|
|||||||
)
|
)
|
||||||
async def test_config_invalid(
|
async def test_config_invalid(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt: config_entries.ConfigEntry,
|
mqtt: None,
|
||||||
gateway_type: ConfGatewayType,
|
gateway_type: ConfGatewayType,
|
||||||
expected_step_id: str,
|
expected_step_id: str,
|
||||||
user_input: dict[str, Any],
|
user_input: dict[str, Any],
|
||||||
err_field,
|
err_field: str,
|
||||||
err_string,
|
err_string: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Perform a test that is expected to generate an error."""
|
"""Perform a test that is expected to generate an error."""
|
||||||
step = await get_form(hass, gateway_type, expected_step_id)
|
step = await get_form(hass, gateway_type, expected_step_id)
|
||||||
@ -397,8 +399,10 @@ async def test_config_invalid(
|
|||||||
|
|
||||||
assert result2["type"] == "form"
|
assert result2["type"] == "form"
|
||||||
assert "errors" in result2
|
assert "errors" in result2
|
||||||
assert err_field in result2["errors"]
|
errors = result2["errors"]
|
||||||
assert result2["errors"][err_field] == err_string
|
assert errors
|
||||||
|
assert err_field in errors
|
||||||
|
assert errors[err_field] == err_string
|
||||||
assert len(mock_setup.mock_calls) == 0
|
assert len(mock_setup.mock_calls) == 0
|
||||||
assert len(mock_setup_entry.mock_calls) == 0
|
assert len(mock_setup_entry.mock_calls) == 0
|
||||||
|
|
||||||
|
@ -18,7 +18,9 @@ from homeassistant.core import HomeAssistant
|
|||||||
("/dev/ttyACM0", False),
|
("/dev/ttyACM0", False),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_is_serial_port_windows(hass: HomeAssistant, port: str, expect_valid: bool):
|
def test_is_serial_port_windows(
|
||||||
|
hass: HomeAssistant, port: str, expect_valid: bool
|
||||||
|
) -> None:
|
||||||
"""Test windows serial port."""
|
"""Test windows serial port."""
|
||||||
|
|
||||||
with patch("sys.platform", "win32"):
|
with patch("sys.platform", "win32"):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user