Simplify zwave_js USB discovery add-on form (#60845)
parent
bf6ca2527d
commit
c8781bbe3b
|
@ -301,6 +301,7 @@ class ConfigFlow(BaseZwaveJSFlow, config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.use_addon = False
|
self.use_addon = False
|
||||||
self._title: str | None = None
|
self._title: str | None = None
|
||||||
|
self._usb_discovery = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def flow_manager(self) -> config_entries.ConfigEntriesFlowManager:
|
def flow_manager(self) -> config_entries.ConfigEntriesFlowManager:
|
||||||
|
@ -387,6 +388,8 @@ class ConfigFlow(BaseZwaveJSFlow, config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
data_schema=vol.Schema({}),
|
data_schema=vol.Schema({}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self._usb_discovery = True
|
||||||
|
|
||||||
return await self.async_step_on_supervisor({CONF_USE_ADDON: True})
|
return await self.async_step_on_supervisor({CONF_USE_ADDON: True})
|
||||||
|
|
||||||
async def async_step_manual(
|
async def async_step_manual(
|
||||||
|
@ -504,6 +507,7 @@ class ConfigFlow(BaseZwaveJSFlow, config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
self.s2_access_control_key = user_input[CONF_S2_ACCESS_CONTROL_KEY]
|
self.s2_access_control_key = user_input[CONF_S2_ACCESS_CONTROL_KEY]
|
||||||
self.s2_authenticated_key = user_input[CONF_S2_AUTHENTICATED_KEY]
|
self.s2_authenticated_key = user_input[CONF_S2_AUTHENTICATED_KEY]
|
||||||
self.s2_unauthenticated_key = user_input[CONF_S2_UNAUTHENTICATED_KEY]
|
self.s2_unauthenticated_key = user_input[CONF_S2_UNAUTHENTICATED_KEY]
|
||||||
|
if not self._usb_discovery:
|
||||||
self.usb_path = user_input[CONF_USB_PATH]
|
self.usb_path = user_input[CONF_USB_PATH]
|
||||||
|
|
||||||
new_addon_config = {
|
new_addon_config = {
|
||||||
|
@ -534,21 +538,21 @@ class ConfigFlow(BaseZwaveJSFlow, config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
CONF_ADDON_S2_UNAUTHENTICATED_KEY, self.s2_unauthenticated_key or ""
|
CONF_ADDON_S2_UNAUTHENTICATED_KEY, self.s2_unauthenticated_key or ""
|
||||||
)
|
)
|
||||||
|
|
||||||
data_schema = vol.Schema(
|
schema = {
|
||||||
{
|
|
||||||
vol.Required(CONF_USB_PATH, default=usb_path): str,
|
|
||||||
vol.Optional(CONF_S0_LEGACY_KEY, default=s0_legacy_key): str,
|
vol.Optional(CONF_S0_LEGACY_KEY, default=s0_legacy_key): str,
|
||||||
vol.Optional(
|
vol.Optional(
|
||||||
CONF_S2_ACCESS_CONTROL_KEY, default=s2_access_control_key
|
CONF_S2_ACCESS_CONTROL_KEY, default=s2_access_control_key
|
||||||
): str,
|
): str,
|
||||||
vol.Optional(
|
vol.Optional(CONF_S2_AUTHENTICATED_KEY, default=s2_authenticated_key): str,
|
||||||
CONF_S2_AUTHENTICATED_KEY, default=s2_authenticated_key
|
|
||||||
): str,
|
|
||||||
vol.Optional(
|
vol.Optional(
|
||||||
CONF_S2_UNAUTHENTICATED_KEY, default=s2_unauthenticated_key
|
CONF_S2_UNAUTHENTICATED_KEY, default=s2_unauthenticated_key
|
||||||
): str,
|
): str,
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
if not self._usb_discovery:
|
||||||
|
schema = {vol.Required(CONF_USB_PATH, default=usb_path): str, **schema}
|
||||||
|
|
||||||
|
data_schema = vol.Schema(schema)
|
||||||
|
|
||||||
return self.async_show_form(step_id="configure_addon", data_schema=data_schema)
|
return self.async_show_form(step_id="configure_addon", data_schema=data_schema)
|
||||||
|
|
||||||
|
|
|
@ -475,7 +475,6 @@ async def test_usb_discovery(
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{
|
{
|
||||||
"usb_path": "/test",
|
|
||||||
"s0_legacy_key": "new123",
|
"s0_legacy_key": "new123",
|
||||||
"s2_access_control_key": "new456",
|
"s2_access_control_key": "new456",
|
||||||
"s2_authenticated_key": "new789",
|
"s2_authenticated_key": "new789",
|
||||||
|
@ -488,7 +487,7 @@ async def test_usb_discovery(
|
||||||
"core_zwave_js",
|
"core_zwave_js",
|
||||||
{
|
{
|
||||||
"options": {
|
"options": {
|
||||||
"device": "/test",
|
"device": USB_DISCOVERY_INFO["device"],
|
||||||
"s0_legacy_key": "new123",
|
"s0_legacy_key": "new123",
|
||||||
"s2_access_control_key": "new456",
|
"s2_access_control_key": "new456",
|
||||||
"s2_authenticated_key": "new789",
|
"s2_authenticated_key": "new789",
|
||||||
|
@ -516,7 +515,7 @@ async def test_usb_discovery(
|
||||||
assert result["title"] == TITLE
|
assert result["title"] == TITLE
|
||||||
assert result["data"] == {
|
assert result["data"] == {
|
||||||
"url": "ws://host1:3001",
|
"url": "ws://host1:3001",
|
||||||
"usb_path": "/test",
|
"usb_path": USB_DISCOVERY_INFO["device"],
|
||||||
"s0_legacy_key": "new123",
|
"s0_legacy_key": "new123",
|
||||||
"s2_access_control_key": "new456",
|
"s2_access_control_key": "new456",
|
||||||
"s2_authenticated_key": "new789",
|
"s2_authenticated_key": "new789",
|
||||||
|
@ -557,7 +556,6 @@ async def test_usb_discovery_addon_not_running(
|
||||||
# Make sure the discovered usb device is preferred.
|
# Make sure the discovered usb device is preferred.
|
||||||
data_schema = result["data_schema"]
|
data_schema = result["data_schema"]
|
||||||
assert data_schema({}) == {
|
assert data_schema({}) == {
|
||||||
"usb_path": USB_DISCOVERY_INFO["device"],
|
|
||||||
"s0_legacy_key": "",
|
"s0_legacy_key": "",
|
||||||
"s2_access_control_key": "",
|
"s2_access_control_key": "",
|
||||||
"s2_authenticated_key": "",
|
"s2_authenticated_key": "",
|
||||||
|
@ -567,7 +565,6 @@ async def test_usb_discovery_addon_not_running(
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{
|
{
|
||||||
"usb_path": USB_DISCOVERY_INFO["device"],
|
|
||||||
"s0_legacy_key": "new123",
|
"s0_legacy_key": "new123",
|
||||||
"s2_access_control_key": "new456",
|
"s2_access_control_key": "new456",
|
||||||
"s2_authenticated_key": "new789",
|
"s2_authenticated_key": "new789",
|
||||||
|
|
Loading…
Reference in New Issue