diff --git a/homeassistant/components/isy994/config_flow.py b/homeassistant/components/isy994/config_flow.py index 866ec800402..dea4bce4eeb 100644 --- a/homeassistant/components/isy994/config_flow.py +++ b/homeassistant/components/isy994/config_flow.py @@ -203,7 +203,10 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): ) -> data_entry_flow.FlowResult: """Handle a discovered isy994 via dhcp.""" friendly_name = discovery_info.hostname - url = f"http://{discovery_info.ip}" + if friendly_name.startswith("polisy"): + url = f"http://{discovery_info.ip}:8080" + else: + url = f"http://{discovery_info.ip}" mac = discovery_info.macaddress isy_mac = ( f"{mac[0:2]}:{mac[2:4]}:{mac[4:6]}:{mac[6:8]}:{mac[8:10]}:{mac[10:12]}" diff --git a/homeassistant/components/isy994/manifest.json b/homeassistant/components/isy994/manifest.json index d92226a4277..d131a150fb3 100644 --- a/homeassistant/components/isy994/manifest.json +++ b/homeassistant/components/isy994/manifest.json @@ -13,7 +13,8 @@ ], "dhcp": [ { "registered_devices": true }, - { "hostname": "isy*", "macaddress": "0021B9*" } + { "hostname": "isy*", "macaddress": "0021B9*" }, + { "hostname": "polisy*", "macaddress": "000DB9*" } ], "iot_class": "local_push", "loggers": ["pyisy"] diff --git a/homeassistant/generated/dhcp.py b/homeassistant/generated/dhcp.py index d0ffb9b097a..4ebe47ded17 100644 --- a/homeassistant/generated/dhcp.py +++ b/homeassistant/generated/dhcp.py @@ -54,6 +54,7 @@ DHCP: list[dict[str, str | bool]] = [ {'domain': 'intellifire', 'hostname': 'zentrios-*'}, {'domain': 'isy994', 'registered_devices': True}, {'domain': 'isy994', 'hostname': 'isy*', 'macaddress': '0021B9*'}, + {'domain': 'isy994', 'hostname': 'polisy*', 'macaddress': '000DB9*'}, {'domain': 'lyric', 'hostname': 'lyric-*', 'macaddress': '48A2E6*'}, {'domain': 'lyric', 'hostname': 'lyric-*', 'macaddress': 'B82CA0*'}, {'domain': 'lyric', 'hostname': 'lyric-*', 'macaddress': '00D02D*'}, diff --git a/tests/components/isy994/test_config_flow.py b/tests/components/isy994/test_config_flow.py index b16f5c0070d..60e9fd964b6 100644 --- a/tests/components/isy994/test_config_flow.py +++ b/tests/components/isy994/test_config_flow.py @@ -44,6 +44,12 @@ MOCK_USER_INPUT = { CONF_PASSWORD: MOCK_PASSWORD, CONF_TLS_VER: MOCK_TLS_VERSION, } +MOCK_POLISY_USER_INPUT = { + CONF_HOST: f"http://{MOCK_HOSTNAME}:8080", + CONF_USERNAME: MOCK_USERNAME, + CONF_PASSWORD: MOCK_PASSWORD, + CONF_TLS_VER: MOCK_TLS_VERSION, +} MOCK_IMPORT_WITH_SSL = { CONF_HOST: f"https://{MOCK_HOSTNAME}", CONF_USERNAME: MOCK_USERNAME, @@ -69,6 +75,7 @@ MOCK_IMPORT_FULL_CONFIG = { MOCK_DEVICE_NAME = "Name of the device" MOCK_UUID = "ce:fb:72:31:b7:b9" MOCK_MAC = "cefb7231b7b9" +MOCK_POLISY_MAC = "000db9123456" MOCK_CONFIG_RESPONSE = """ @@ -95,6 +102,14 @@ PATCH_ASYNC_SETUP = f"{INTEGRATION}.async_setup" PATCH_ASYNC_SETUP_ENTRY = f"{INTEGRATION}.async_setup_entry" +def _get_schema_default(schema, key_name): + """Iterate schema to find a key.""" + for schema_key in schema: + if schema_key == key_name: + return schema_key.default() + raise KeyError(f"{key_name} not found in schema") + + async def test_form(hass: HomeAssistant): """Test we get the form.""" @@ -544,6 +559,46 @@ async def test_form_dhcp(hass: HomeAssistant): assert len(mock_setup_entry.mock_calls) == 1 +async def test_form_dhcp_with_polisy(hass: HomeAssistant): + """Test we can setup from dhcp with polisy.""" + + result = await hass.config_entries.flow.async_init( + DOMAIN, + context={"source": SOURCE_DHCP}, + data=dhcp.DhcpServiceInfo( + ip="1.2.3.4", + hostname="polisy", + macaddress=MOCK_POLISY_MAC, + ), + ) + assert result["type"] == data_entry_flow.RESULT_TYPE_FORM + assert result["step_id"] == "user" + assert result["errors"] == {} + assert ( + _get_schema_default(result["data_schema"].schema, CONF_HOST) + == "http://1.2.3.4:8080" + ) + + with patch(PATCH_CONNECTION, return_value=MOCK_CONFIG_RESPONSE), patch( + PATCH_ASYNC_SETUP, return_value=True + ) as mock_setup, patch( + PATCH_ASYNC_SETUP_ENTRY, + return_value=True, + ) as mock_setup_entry: + result2 = await hass.config_entries.flow.async_configure( + result["flow_id"], + MOCK_POLISY_USER_INPUT, + ) + await hass.async_block_till_done() + + assert result2["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY + assert result2["title"] == f"{MOCK_DEVICE_NAME} ({MOCK_HOSTNAME})" + assert result2["result"].unique_id == MOCK_UUID + assert result2["data"] == MOCK_POLISY_USER_INPUT + assert len(mock_setup.mock_calls) == 1 + assert len(mock_setup_entry.mock_calls) == 1 + + async def test_form_dhcp_existing_entry(hass: HomeAssistant): """Test we update the ip of an existing entry from dhcp."""