Use ZeroconfServiceInfo in rachio (#60054)

pull/60088/head
epenet 2021-11-21 14:55:54 +01:00 committed by GitHub
parent 435eb97495
commit 8ec30aa9ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 7 deletions

View File

@ -7,8 +7,10 @@ from requests.exceptions import ConnectTimeout
import voluptuous as vol
from homeassistant import config_entries, core, exceptions
from homeassistant.components import zeroconf
from homeassistant.const import CONF_API_KEY
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from .const import (
CONF_MANUAL_RUN_MINS,
@ -78,13 +80,14 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
step_id="user", data_schema=DATA_SCHEMA, errors=errors
)
async def async_step_homekit(self, discovery_info):
async def async_step_homekit(
self, discovery_info: zeroconf.ZeroconfServiceInfo
) -> FlowResult:
"""Handle HomeKit discovery."""
self._async_abort_entries_match()
properties = {
key.lower(): value for (key, value) in discovery_info["properties"].items()
}
await self.async_set_unique_id(properties["id"])
await self.async_set_unique_id(
discovery_info[zeroconf.ATTR_PROPERTIES][zeroconf.ATTR_PROPERTIES_ID]
)
return await self.async_step_user()
@staticmethod

View File

@ -2,6 +2,7 @@
from unittest.mock import MagicMock, patch
from homeassistant import config_entries
from homeassistant.components import zeroconf
from homeassistant.components.rachio.const import (
CONF_CUSTOM_URL,
CONF_MANUAL_RUN_MINS,
@ -111,7 +112,9 @@ async def test_form_homekit(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_HOMEKIT},
data={"properties": {"id": "AA:BB:CC:DD:EE:FF"}},
data=zeroconf.ZeroconfServiceInfo(
properties={zeroconf.ATTR_PROPERTIES_ID: "AA:BB:CC:DD:EE:FF"}
),
)
assert result["type"] == "form"
assert result["errors"] == {}
@ -128,7 +131,9 @@ async def test_form_homekit(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_HOMEKIT},
data={"properties": {"id": "AA:BB:CC:DD:EE:FF"}},
data=zeroconf.ZeroconfServiceInfo(
properties={zeroconf.ATTR_PROPERTIES_ID: "AA:BB:CC:DD:EE:FF"}
),
)
assert result["type"] == "abort"
assert result["reason"] == "already_configured"