mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Use ZeroconfServiceInfo in shelly (#60098)
This commit is contained in:
parent
fa9465d003
commit
4555820987
@ -189,16 +189,17 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
self, discovery_info: zeroconf.ZeroconfServiceInfo
|
self, discovery_info: zeroconf.ZeroconfServiceInfo
|
||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Handle zeroconf discovery."""
|
"""Handle zeroconf discovery."""
|
||||||
|
host = discovery_info[zeroconf.ATTR_HOST]
|
||||||
try:
|
try:
|
||||||
self.info = await self._async_get_info(discovery_info["host"])
|
self.info = await self._async_get_info(host)
|
||||||
except HTTP_CONNECT_ERRORS:
|
except HTTP_CONNECT_ERRORS:
|
||||||
return self.async_abort(reason="cannot_connect")
|
return self.async_abort(reason="cannot_connect")
|
||||||
except aioshelly.exceptions.FirmwareUnsupported:
|
except aioshelly.exceptions.FirmwareUnsupported:
|
||||||
return self.async_abort(reason="unsupported_firmware")
|
return self.async_abort(reason="unsupported_firmware")
|
||||||
|
|
||||||
await self.async_set_unique_id(self.info["mac"])
|
await self.async_set_unique_id(self.info["mac"])
|
||||||
self._abort_if_unique_id_configured({CONF_HOST: discovery_info["host"]})
|
self._abort_if_unique_id_configured({CONF_HOST: host})
|
||||||
self.host = discovery_info["host"]
|
self.host = host
|
||||||
|
|
||||||
self.context["title_placeholders"] = {
|
self.context["title_placeholders"] = {
|
||||||
"name": discovery_info.get("name", "").split(".")[0]
|
"name": discovery_info.get("name", "").split(".")[0]
|
||||||
|
@ -8,6 +8,7 @@ import aioshelly
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import config_entries, data_entry_flow
|
from homeassistant import config_entries, data_entry_flow
|
||||||
|
from homeassistant.components import zeroconf
|
||||||
from homeassistant.components.shelly.const import DOMAIN
|
from homeassistant.components.shelly.const import DOMAIN
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
@ -16,11 +17,11 @@ MOCK_SETTINGS = {
|
|||||||
"name": "Test name",
|
"name": "Test name",
|
||||||
"device": {"mac": "test-mac", "hostname": "test-host", "type": "SHSW-1"},
|
"device": {"mac": "test-mac", "hostname": "test-host", "type": "SHSW-1"},
|
||||||
}
|
}
|
||||||
DISCOVERY_INFO = {
|
DISCOVERY_INFO = zeroconf.ZeroconfServiceInfo(
|
||||||
"host": "1.1.1.1",
|
host="1.1.1.1",
|
||||||
"name": "shelly1pm-12345",
|
name="shelly1pm-12345",
|
||||||
"properties": {"id": "shelly1pm-12345"},
|
properties={"id": "shelly1pm-12345"},
|
||||||
}
|
)
|
||||||
MOCK_CONFIG = {
|
MOCK_CONFIG = {
|
||||||
"wifi": {"ap": {"ssid": "Test name"}},
|
"wifi": {"ap": {"ssid": "Test name"}},
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user