Fix Daikin discovery (#36704)
This commit is contained in:
parent
871afd2bf2
commit
c1cf3679aa
7 changed files with 24 additions and 10 deletions
|
@ -72,6 +72,8 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
|
||||||
# For backwards compat, set unique ID
|
# For backwards compat, set unique ID
|
||||||
if entry.unique_id is None:
|
if entry.unique_id is None:
|
||||||
hass.config_entries.async_update_entry(entry, unique_id=conf[KEY_MAC])
|
hass.config_entries.async_update_entry(entry, unique_id=conf[KEY_MAC])
|
||||||
|
elif ".local" in entry.unique_id:
|
||||||
|
hass.config_entries.async_update_entry(entry, unique_id=conf[KEY_MAC])
|
||||||
daikin_api = await daikin_api_setup(
|
daikin_api = await daikin_api_setup(
|
||||||
hass,
|
hass,
|
||||||
conf[CONF_HOST],
|
conf[CONF_HOST],
|
||||||
|
|
|
@ -6,12 +6,13 @@ from uuid import uuid4
|
||||||
from aiohttp import ClientError, web_exceptions
|
from aiohttp import ClientError, web_exceptions
|
||||||
from async_timeout import timeout
|
from async_timeout import timeout
|
||||||
from pydaikin.daikin_base import Appliance
|
from pydaikin.daikin_base import Appliance
|
||||||
|
from pydaikin.discovery import Discovery
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD
|
||||||
|
|
||||||
from .const import CONF_KEY, CONF_UUID, KEY_HOSTNAME, KEY_IP, KEY_MAC, TIMEOUT
|
from .const import CONF_KEY, CONF_UUID, KEY_IP, KEY_MAC, TIMEOUT
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -128,7 +129,8 @@ class FlowHandler(config_entries.ConfigFlow):
|
||||||
async def async_step_zeroconf(self, discovery_info):
|
async def async_step_zeroconf(self, discovery_info):
|
||||||
"""Prepare configuration for a discovered Daikin device."""
|
"""Prepare configuration for a discovered Daikin device."""
|
||||||
_LOGGER.debug("Zeroconf discovery_info: %s", discovery_info)
|
_LOGGER.debug("Zeroconf discovery_info: %s", discovery_info)
|
||||||
await self.async_set_unique_id(discovery_info[KEY_HOSTNAME])
|
devices = Discovery.poll(discovery_info[CONF_HOST])
|
||||||
|
await self.async_set_unique_id(next(iter(devices.values()))[KEY_MAC])
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
self.host = discovery_info[CONF_HOST]
|
self.host = discovery_info[CONF_HOST]
|
||||||
return await self.async_step_user()
|
return await self.async_step_user()
|
||||||
|
|
|
@ -64,6 +64,5 @@ CONF_UUID = "uuid"
|
||||||
|
|
||||||
KEY_MAC = "mac"
|
KEY_MAC = "mac"
|
||||||
KEY_IP = "ip"
|
KEY_IP = "ip"
|
||||||
KEY_HOSTNAME = "hostname"
|
|
||||||
|
|
||||||
TIMEOUT = 60
|
TIMEOUT = 60
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"name": "Daikin AC",
|
"name": "Daikin AC",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/daikin",
|
"documentation": "https://www.home-assistant.io/integrations/daikin",
|
||||||
"requirements": ["pydaikin==2.1.1"],
|
"requirements": ["pydaikin==2.1.2"],
|
||||||
"codeowners": ["@fredrike"],
|
"codeowners": ["@fredrike"],
|
||||||
"zeroconf": ["_dkapi._tcp.local."],
|
"zeroconf": ["_dkapi._tcp.local."],
|
||||||
"quality_scale": "platinum"
|
"quality_scale": "platinum"
|
||||||
|
|
|
@ -1269,7 +1269,7 @@ pycsspeechtts==1.0.3
|
||||||
# pycups==1.9.73
|
# pycups==1.9.73
|
||||||
|
|
||||||
# homeassistant.components.daikin
|
# homeassistant.components.daikin
|
||||||
pydaikin==2.1.1
|
pydaikin==2.1.2
|
||||||
|
|
||||||
# homeassistant.components.danfoss_air
|
# homeassistant.components.danfoss_air
|
||||||
pydanfossair==0.1.0
|
pydanfossair==0.1.0
|
||||||
|
|
|
@ -551,7 +551,7 @@ pycoolmasternet==0.0.4
|
||||||
pycountry==19.8.18
|
pycountry==19.8.18
|
||||||
|
|
||||||
# homeassistant.components.daikin
|
# homeassistant.components.daikin
|
||||||
pydaikin==2.1.1
|
pydaikin==2.1.2
|
||||||
|
|
||||||
# homeassistant.components.deconz
|
# homeassistant.components.deconz
|
||||||
pydeconz==71
|
pydeconz==71
|
||||||
|
|
|
@ -6,7 +6,7 @@ from aiohttp import ClientError
|
||||||
from aiohttp.web_exceptions import HTTPForbidden
|
from aiohttp.web_exceptions import HTTPForbidden
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.daikin.const import KEY_HOSTNAME, KEY_IP, KEY_MAC
|
from homeassistant.components.daikin.const import KEY_IP, KEY_MAC
|
||||||
from homeassistant.config_entries import (
|
from homeassistant.config_entries import (
|
||||||
SOURCE_DISCOVERY,
|
SOURCE_DISCOVERY,
|
||||||
SOURCE_IMPORT,
|
SOURCE_IMPORT,
|
||||||
|
@ -25,7 +25,6 @@ from tests.common import MockConfigEntry
|
||||||
|
|
||||||
MAC = "AABBCCDDEEFF"
|
MAC = "AABBCCDDEEFF"
|
||||||
HOST = "127.0.0.1"
|
HOST = "127.0.0.1"
|
||||||
HOSTNAME = "DaikinUNIQUE.local"
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -42,6 +41,16 @@ def mock_daikin():
|
||||||
yield Appliance
|
yield Appliance
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def mock_daikin_discovery():
|
||||||
|
"""Mock pydaikin Discovery."""
|
||||||
|
with patch("homeassistant.components.daikin.config_flow.Discovery") as Discovery:
|
||||||
|
Discovery.poll = PropertyMock(
|
||||||
|
return_value={"127.0.01": {"mac": "AABBCCDDEEFF", "id": "test"}}
|
||||||
|
)
|
||||||
|
yield Discovery
|
||||||
|
|
||||||
|
|
||||||
async def test_user(hass, mock_daikin):
|
async def test_user(hass, mock_daikin):
|
||||||
"""Test user config."""
|
"""Test user config."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -113,10 +122,12 @@ async def test_device_abort(hass, mock_daikin, s_effect, reason):
|
||||||
"source, data, unique_id",
|
"source, data, unique_id",
|
||||||
[
|
[
|
||||||
(SOURCE_DISCOVERY, {KEY_IP: HOST, KEY_MAC: MAC}, MAC),
|
(SOURCE_DISCOVERY, {KEY_IP: HOST, KEY_MAC: MAC}, MAC),
|
||||||
(SOURCE_ZEROCONF, {CONF_HOST: HOST, KEY_HOSTNAME: HOSTNAME}, HOSTNAME),
|
(SOURCE_ZEROCONF, {CONF_HOST: HOST}, MAC),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_discovery_zeroconf(hass, mock_daikin, source, data, unique_id):
|
async def test_discovery_zeroconf(
|
||||||
|
hass, mock_daikin, mock_daikin_discovery, source, data, unique_id
|
||||||
|
):
|
||||||
"""Test discovery/zeroconf step."""
|
"""Test discovery/zeroconf step."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
"daikin", context={"source": source}, data=data,
|
"daikin", context={"source": source}, data=data,
|
||||||
|
|
Loading…
Add table
Reference in a new issue