Add support for Shelly RPC devices custom TCP port (#110860)
* First coding * add port to config_entry + gen1 not supported msg * fix async_step_credentials * strings * fix reauth * fix visit device link * increased MINOR_VERSION * apply review comments * align to latest aioshelly * missing tests * introduce port parameter * update tests * remove leftover * remove "port" data_description key * missing key * apply review comments * apply more review comments * Add tests * apply review comment * apply review comment (part 2) * description update * fine tuning description * fix test patching --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
This commit is contained in:
parent
8141a246b0
commit
8728057b1b
7 changed files with 156 additions and 32 deletions
|
@ -6,8 +6,9 @@ from ipaddress import ip_address
|
|||
from typing import Any
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
from aioshelly.const import MODEL_1, MODEL_PLUS_2PM
|
||||
from aioshelly.const import DEFAULT_HTTP_PORT, MODEL_1, MODEL_PLUS_2PM
|
||||
from aioshelly.exceptions import (
|
||||
CustomPortNotSupported,
|
||||
DeviceConnectionError,
|
||||
FirmwareUnsupported,
|
||||
InvalidAuthError,
|
||||
|
@ -54,17 +55,18 @@ DISCOVERY_INFO_WITH_MAC = zeroconf.ZeroconfServiceInfo(
|
|||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("gen", "model"),
|
||||
("gen", "model", "port"),
|
||||
[
|
||||
(1, MODEL_1),
|
||||
(2, MODEL_PLUS_2PM),
|
||||
(3, MODEL_PLUS_2PM),
|
||||
(1, MODEL_1, DEFAULT_HTTP_PORT),
|
||||
(2, MODEL_PLUS_2PM, DEFAULT_HTTP_PORT),
|
||||
(3, MODEL_PLUS_2PM, 11200),
|
||||
],
|
||||
)
|
||||
async def test_form(
|
||||
hass: HomeAssistant,
|
||||
gen: int,
|
||||
model: str,
|
||||
port: int,
|
||||
mock_block_device: Mock,
|
||||
mock_rpc_device: Mock,
|
||||
) -> None:
|
||||
|
@ -72,12 +74,18 @@ async def test_form(
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
assert result["type"] == "form"
|
||||
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
||||
assert result["errors"] == {}
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.shelly.config_flow.get_info",
|
||||
return_value={"mac": "test-mac", "type": MODEL_1, "auth": False, "gen": gen},
|
||||
return_value={
|
||||
"mac": "test-mac",
|
||||
"type": MODEL_1,
|
||||
"auth": False,
|
||||
"gen": gen,
|
||||
"port": port,
|
||||
},
|
||||
), patch(
|
||||
"homeassistant.components.shelly.async_setup", return_value=True
|
||||
) as mock_setup, patch(
|
||||
|
@ -86,7 +94,7 @@ async def test_form(
|
|||
) as mock_setup_entry:
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{"host": "1.1.1.1"},
|
||||
{"host": "1.1.1.1", "port": port},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
@ -94,6 +102,7 @@ async def test_form(
|
|||
assert result2["title"] == "Test name"
|
||||
assert result2["data"] == {
|
||||
"host": "1.1.1.1",
|
||||
"port": port,
|
||||
"model": model,
|
||||
"sleep_period": 0,
|
||||
"gen": gen,
|
||||
|
@ -102,6 +111,33 @@ async def test_form(
|
|||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_form_gen1_custom_port(
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
) -> None:
|
||||
"""Test we get the form."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
||||
assert result["errors"] == {}
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.shelly.config_flow.get_info",
|
||||
return_value={"mac": "test-mac", "type": MODEL_1, "gen": 1},
|
||||
), patch(
|
||||
"aioshelly.block_device.BlockDevice.create",
|
||||
side_effect=CustomPortNotSupported,
|
||||
):
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{"host": "1.1.1.1", "port": "1100"},
|
||||
)
|
||||
|
||||
assert result2["type"] == data_entry_flow.FlowResultType.FORM
|
||||
assert result2["errors"]["base"] == "custom_port_not_supported"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("gen", "model", "user_input", "username"),
|
||||
[
|
||||
|
@ -168,6 +204,7 @@ async def test_form_auth(
|
|||
assert result3["title"] == "Test name"
|
||||
assert result3["data"] == {
|
||||
"host": "1.1.1.1",
|
||||
"port": DEFAULT_HTTP_PORT,
|
||||
"model": model,
|
||||
"sleep_period": 0,
|
||||
"gen": gen,
|
||||
|
@ -757,6 +794,7 @@ async def test_zeroconf_require_auth(
|
|||
assert result2["title"] == "Test name"
|
||||
assert result2["data"] == {
|
||||
"host": "1.1.1.1",
|
||||
"port": DEFAULT_HTTP_PORT,
|
||||
"model": MODEL_1,
|
||||
"sleep_period": 0,
|
||||
"gen": 1,
|
||||
|
@ -1126,7 +1164,7 @@ async def test_sleeping_device_gen2_with_new_firmware(
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
assert result["type"] == "form"
|
||||
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
||||
assert result["errors"] == {}
|
||||
|
||||
with patch(
|
||||
|
@ -1144,6 +1182,7 @@ async def test_sleeping_device_gen2_with_new_firmware(
|
|||
|
||||
assert result["data"] == {
|
||||
"host": "1.1.1.1",
|
||||
"port": DEFAULT_HTTP_PORT,
|
||||
"model": MODEL_PLUS_2PM,
|
||||
"sleep_period": 666,
|
||||
"gen": 2,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue