Fix incorrect Bang & Olufsen MDNS announcements (#122782)
This commit is contained in:
parent
bf38db0035
commit
20c4f84a4e
2 changed files with 28 additions and 1 deletions
|
@ -135,6 +135,15 @@ class BangOlufsenConfigFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||
except AddressValueError:
|
||||
return self.async_abort(reason="ipv6_address")
|
||||
|
||||
# Check connection to ensure valid address is received
|
||||
self._client = MozartClient(self._host)
|
||||
|
||||
async with self._client:
|
||||
try:
|
||||
await self._client.get_beolink_self(_request_timeout=3)
|
||||
except (ClientConnectorError, TimeoutError):
|
||||
return self.async_abort(reason="invalid_address")
|
||||
|
||||
self._model = discovery_info.hostname[:-16].replace("-", " ")
|
||||
self._serial_number = discovery_info.properties[ATTR_SERIAL_NUMBER]
|
||||
self._beolink_jid = f"{discovery_info.properties[ATTR_TYPE_NUMBER]}.{discovery_info.properties[ATTR_ITEM_NUMBER]}.{self._serial_number}@products.bang-olufsen.com"
|
||||
|
|
|
@ -132,7 +132,7 @@ async def test_config_flow_zeroconf(hass: HomeAssistant, mock_mozart_client) ->
|
|||
assert result_confirm["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result_confirm["data"] == TEST_DATA_CREATE_ENTRY
|
||||
|
||||
assert mock_mozart_client.get_beolink_self.call_count == 0
|
||||
assert mock_mozart_client.get_beolink_self.call_count == 1
|
||||
|
||||
|
||||
async def test_config_flow_zeroconf_not_mozart_device(hass: HomeAssistant) -> None:
|
||||
|
@ -159,3 +159,21 @@ async def test_config_flow_zeroconf_ipv6(hass: HomeAssistant) -> None:
|
|||
|
||||
assert result_user["type"] is FlowResultType.ABORT
|
||||
assert result_user["reason"] == "ipv6_address"
|
||||
|
||||
|
||||
async def test_config_flow_zeroconf_invalid_ip(
|
||||
hass: HomeAssistant, mock_mozart_client
|
||||
) -> None:
|
||||
"""Test zeroconf discovery with invalid IP address."""
|
||||
mock_mozart_client.get_beolink_self.side_effect = ClientConnectorError(
|
||||
Mock(), Mock()
|
||||
)
|
||||
|
||||
result_user = await hass.config_entries.flow.async_init(
|
||||
handler=DOMAIN,
|
||||
context={CONF_SOURCE: SOURCE_ZEROCONF},
|
||||
data=TEST_DATA_ZEROCONF,
|
||||
)
|
||||
|
||||
assert result_user["type"] is FlowResultType.ABORT
|
||||
assert result_user["reason"] == "invalid_address"
|
||||
|
|
Loading…
Add table
Reference in a new issue