Enable SkyConnect config flow and use correct case in USB matching (#81522)
* Ensure `USBCallbackMatcher` uses the appropriate case for each field * Enable the config flow for the SkyConnect integration * Update unit test
This commit is contained in:
parent
3788a950e6
commit
604cd46ec9
5 changed files with 38 additions and 14 deletions
|
@ -1,16 +1,29 @@
|
|||
"""The Home Assistant Sky Connect integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import cast
|
||||
|
||||
from homeassistant.components import usb
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a Home Assistant Sky Connect config entry."""
|
||||
matcher = usb.USBCallbackMatcher(
|
||||
domain=DOMAIN,
|
||||
vid=entry.data["vid"].upper(),
|
||||
pid=entry.data["pid"].upper(),
|
||||
serial_number=entry.data["serial_number"].lower(),
|
||||
manufacturer=entry.data["manufacturer"].lower(),
|
||||
description=entry.data["description"].lower(),
|
||||
)
|
||||
|
||||
if not usb.async_is_plugged_in(hass, matcher):
|
||||
# The USB dongle is not plugged in
|
||||
raise ConfigEntryNotReady
|
||||
|
||||
usb_info = usb.UsbServiceInfo(
|
||||
device=entry.data["device"],
|
||||
vid=entry.data["vid"],
|
||||
|
@ -19,9 +32,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
manufacturer=entry.data["manufacturer"],
|
||||
description=entry.data["description"],
|
||||
)
|
||||
if not usb.async_is_plugged_in(hass, cast(usb.USBCallbackMatcher, entry.data)):
|
||||
# The USB dongle is not plugged in
|
||||
raise ConfigEntryNotReady
|
||||
|
||||
await hass.config_entries.flow.async_init(
|
||||
"zha",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"domain": "homeassistant_sky_connect",
|
||||
"name": "Home Assistant Sky Connect",
|
||||
"config_flow": false,
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/homeassistant_sky_connect",
|
||||
"dependencies": ["hardware", "usb"],
|
||||
"codeowners": ["@home-assistant/core"],
|
||||
|
|
|
@ -161,6 +161,7 @@ FLOWS = {
|
|||
"hlk_sw16",
|
||||
"home_connect",
|
||||
"home_plus_control",
|
||||
"homeassistant_sky_connect",
|
||||
"homekit",
|
||||
"homekit_controller",
|
||||
"homematicip_cloud",
|
||||
|
|
|
@ -4,6 +4,12 @@ To update, run python3 -m script.hassfest
|
|||
"""
|
||||
|
||||
USB = [
|
||||
{
|
||||
"domain": "homeassistant_sky_connect",
|
||||
"vid": "10C4",
|
||||
"pid": "EA60",
|
||||
"description": "*skyconnect v1.0*",
|
||||
},
|
||||
{
|
||||
"domain": "insteon",
|
||||
"vid": "10BF",
|
||||
|
|
|
@ -13,12 +13,12 @@ from homeassistant.core import HomeAssistant
|
|||
from tests.common import MockConfigEntry
|
||||
|
||||
CONFIG_ENTRY_DATA = {
|
||||
"device": "bla_device",
|
||||
"vid": "bla_vid",
|
||||
"pid": "bla_pid",
|
||||
"serial_number": "bla_serial_number",
|
||||
"manufacturer": "bla_manufacturer",
|
||||
"description": "bla_description",
|
||||
"device": "/dev/serial/by-id/usb-Nabu_Casa_SkyConnect_v1.0_9e2adbd75b8beb119fe564a0f320645d-if00-port0",
|
||||
"vid": "10C4",
|
||||
"pid": "EA60",
|
||||
"serial_number": "3c0ed67c628beb11b1cd64a0f320645d",
|
||||
"manufacturer": "Nabu Casa",
|
||||
"description": "SkyConnect v1.0",
|
||||
}
|
||||
|
||||
|
||||
|
@ -67,6 +67,13 @@ async def test_setup_entry(
|
|||
await hass.async_block_till_done()
|
||||
assert len(mock_is_plugged_in.mock_calls) == 1
|
||||
|
||||
matcher = mock_is_plugged_in.mock_calls[0].args[1]
|
||||
assert matcher["vid"].isupper()
|
||||
assert matcher["pid"].isupper()
|
||||
assert matcher["serial_number"].islower()
|
||||
assert matcher["manufacturer"].islower()
|
||||
assert matcher["description"].islower()
|
||||
|
||||
# Finish setting up ZHA
|
||||
if num_entries > 0:
|
||||
zha_flows = hass.config_entries.flow.async_progress_by_handler("zha")
|
||||
|
@ -119,12 +126,12 @@ async def test_setup_zha(mock_zha_config_flow_setup, hass: HomeAssistant) -> Non
|
|||
"device": {
|
||||
"baudrate": 115200,
|
||||
"flow_control": "software",
|
||||
"path": "bla_device",
|
||||
"path": CONFIG_ENTRY_DATA["device"],
|
||||
},
|
||||
"radio_type": "ezsp",
|
||||
}
|
||||
assert config_entry.options == {}
|
||||
assert config_entry.title == "bla_description"
|
||||
assert config_entry.title == CONFIG_ENTRY_DATA["description"]
|
||||
|
||||
|
||||
async def test_setup_entry_wait_usb(hass: HomeAssistant) -> None:
|
||||
|
|
Loading…
Add table
Reference in a new issue