Fix Konnected pro options (#38848)

pull/38966/head
Kit Klein 2020-08-17 03:47:21 -04:00 committed by GitHub
parent 49edd91f4e
commit 8d8c1335c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 41 deletions

View File

@ -71,7 +71,7 @@ KONN_PANEL_MODEL_NAMES = {
}
OPTIONS_IO_ANY = vol.In([CONF_IO_DIS, CONF_IO_BIN, CONF_IO_DIG, CONF_IO_SWI])
OPTIONS_IO_INPUT_ONLY = vol.In([CONF_IO_DIS, CONF_IO_BIN, CONF_IO_DIG])
OPTIONS_IO_INPUT_ONLY = vol.In([CONF_IO_DIS, CONF_IO_BIN])
OPTIONS_IO_OUTPUT_ONLY = vol.In([CONF_IO_DIS, CONF_IO_SWI])
@ -161,7 +161,7 @@ CONFIG_ENTRY_SCHEMA = vol.Schema(
class KonnectedFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for NEW_NAME."""
"""Handle a config flow for Konnected Panels."""
VERSION = 1
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_PUSH
@ -810,6 +810,10 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
step_id="options_misc",
data_schema=vol.Schema(
{
vol.Required(
CONF_DISCOVERY,
default=self.current_opt.get(CONF_DISCOVERY, True),
): bool,
vol.Required(
CONF_BLINK, default=self.current_opt.get(CONF_BLINK, True)
): bool,

View File

@ -59,7 +59,7 @@
},
"options_binary": {
"title": "Configure Binary Sensor",
"description": "Please select the options for the binary sensor attached to {zone}",
"description": "{zone} options",
"data": {
"type": "Binary Sensor Type",
"name": "Name (optional)",
@ -68,7 +68,7 @@
},
"options_digital": {
"title": "Configure Digital Sensor",
"description": "Please select the options for the digital sensor attached to {zone}",
"description": "{zone} options",
"data": {
"type": "Sensor Type",
"name": "Name (optional)",
@ -77,7 +77,7 @@
},
"options_switch": {
"title": "Configure Switchable Output",
"description": "Please select the output options for {zone}: state {state}",
"description": "{zone} options: state {state}",
"data": {
"name": "Name (optional)",
"activation": "Output when on",
@ -91,6 +91,7 @@
"title": "Configure Misc",
"description": "Please select the desired behavior for your panel",
"data": {
"discovery": "Respond to discovery requests on your network",
"blink": "Blink panel LED on when sending state change",
"override_api_host": "Override default Home Assistant API host panel URL",
"api_host": "Override API host URL (optional)"

View File

@ -41,7 +41,7 @@
"name": "Name (optional)",
"type": "Binary Sensor Type"
},
"description": "Please select the options for the binary sensor attached to {zone}",
"description": "{zone} options",
"title": "Configure Binary Sensor"
},
"options_digital": {
@ -50,7 +50,7 @@
"poll_interval": "Poll Interval (minutes) (optional)",
"type": "Sensor Type"
},
"description": "Please select the options for the digital sensor attached to {zone}",
"description": "{zone} options",
"title": "Configure Digital Sensor"
},
"options_io": {
@ -85,6 +85,7 @@
"data": {
"api_host": "Override API host URL (optional)",
"blink": "Blink panel LED on when sending state change",
"discovery": "Respond to discovery requests on your network",
"override_api_host": "Override default Home Assistant API host panel URL"
},
"description": "Please select the desired behavior for your panel",
@ -99,7 +100,7 @@
"pause": "Pause between pulses (ms) (optional)",
"repeat": "Times to repeat (-1=infinite) (optional)"
},
"description": "Please select the output options for {zone}: state {state}",
"description": "{zone} options: state {state}",
"title": "Configure Switchable Output"
}
}

View File

@ -312,7 +312,7 @@ async def test_ssdp_host_update(hass, mock_panel):
"10": "Binary Sensor",
"3": "Digital Sensor",
"7": "Digital Sensor",
"11": "Digital Sensor",
"11": "Binary Sensor",
"4": "Switchable Output",
"out1": "Switchable Output",
"alarm1": "Switchable Output",
@ -321,11 +321,11 @@ async def test_ssdp_host_update(hass, mock_panel):
{"zone": "2", "type": "door"},
{"zone": "6", "type": "window", "name": "winder", "inverse": True},
{"zone": "10", "type": "door"},
{"zone": "11", "type": "window"},
],
"sensors": [
{"zone": "3", "type": "dht"},
{"zone": "7", "type": "ds18b20", "name": "temper"},
{"zone": "11", "type": "dht"},
],
"switches": [
{"zone": "4"},
@ -391,11 +391,11 @@ async def test_import_existing_config(hass, mock_panel):
{"zone": "2", "type": "door"},
{"zone": 6, "type": "window", "name": "winder", "inverse": True},
{"zone": "10", "type": "door"},
{"zone": "11", "type": "window"},
],
"sensors": [
{"zone": "3", "type": "dht"},
{"zone": 7, "type": "ds18b20", "name": "temper"},
{"zone": "11", "type": "dht"},
],
"switches": [
{"zone": "4"},
@ -447,7 +447,7 @@ async def test_import_existing_config(hass, mock_panel):
"10": "Binary Sensor",
"3": "Digital Sensor",
"7": "Digital Sensor",
"11": "Digital Sensor",
"11": "Binary Sensor",
"4": "Switchable Output",
"8": "Switchable Output",
"out1": "Switchable Output",
@ -460,11 +460,11 @@ async def test_import_existing_config(hass, mock_panel):
{"zone": "2", "type": "door", "inverse": False},
{"zone": "6", "type": "window", "name": "winder", "inverse": True},
{"zone": "10", "type": "door", "inverse": False},
{"zone": "11", "type": "window", "inverse": False},
],
"sensors": [
{"zone": "3", "type": "dht", "poll_interval": 3},
{"zone": "7", "type": "ds18b20", "name": "temper", "poll_interval": 3},
{"zone": "11", "type": "dht", "poll_interval": 3},
],
"switches": [
{"activation": "high", "zone": "4"},
@ -788,7 +788,12 @@ async def test_option_flow(hass, mock_panel):
# make sure we enforce url format
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={"blink": True, "override_api_host": True, "api_host": "badhosturl"},
user_input={
"discovery": False,
"blink": True,
"override_api_host": True,
"api_host": "badhosturl",
},
)
assert result["type"] == "form"
@ -796,6 +801,7 @@ async def test_option_flow(hass, mock_panel):
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={
"discovery": False,
"blink": True,
"override_api_host": True,
"api_host": "http://overridehost:1111",
@ -810,6 +816,7 @@ async def test_option_flow(hass, mock_panel):
"6": "Binary Sensor",
"out": "Switchable Output",
},
"discovery": False,
"blink": True,
"api_host": "http://overridehost:1111",
"binary_sensors": [
@ -889,7 +896,7 @@ async def test_option_flow_pro(hass, mock_panel):
"8": "Switchable Output",
"9": "Disabled",
"10": "Binary Sensor",
"11": "Digital Sensor",
"11": "Binary Sensor",
"12": "Disabled",
"out1": "Switchable Output",
"alarm1": "Switchable Output",
@ -919,6 +926,13 @@ async def test_option_flow_pro(hass, mock_panel):
result["flow_id"], user_input={"type": "door"}
)
assert result["type"] == "form"
assert result["step_id"] == "options_binary"
# zone 11
result = await hass.config_entries.options.async_configure(
result["flow_id"], user_input={"type": "window"}
)
assert result["type"] == "form"
assert result["step_id"] == "options_digital"
# zone 3
@ -933,13 +947,6 @@ async def test_option_flow_pro(hass, mock_panel):
result["flow_id"], user_input={"type": "ds18b20", "name": "temper"}
)
assert result["type"] == "form"
assert result["step_id"] == "options_digital"
# zone 11
result = await hass.config_entries.options.async_configure(
result["flow_id"], user_input={"type": "dht"}
)
assert result["type"] == "form"
assert result["step_id"] == "options_switch"
# zone 4
@ -978,14 +985,15 @@ async def test_option_flow_pro(hass, mock_panel):
assert result["step_id"] == "options_misc"
result = await hass.config_entries.options.async_configure(
result["flow_id"], user_input={"blink": True, "override_api_host": False},
result["flow_id"],
user_input={"discovery": False, "blink": True, "override_api_host": False},
)
assert result["type"] == "create_entry"
assert result["data"] == {
"io": {
"10": "Binary Sensor",
"11": "Digital Sensor",
"11": "Binary Sensor",
"2": "Binary Sensor",
"3": "Digital Sensor",
"4": "Switchable Output",
@ -995,17 +1003,18 @@ async def test_option_flow_pro(hass, mock_panel):
"alarm1": "Switchable Output",
"out1": "Switchable Output",
},
"discovery": False,
"blink": True,
"api_host": "",
"binary_sensors": [
{"zone": "2", "type": "door", "inverse": False},
{"zone": "6", "type": "window", "name": "winder", "inverse": True},
{"zone": "10", "type": "door", "inverse": False},
{"zone": "11", "type": "window", "inverse": False},
],
"sensors": [
{"zone": "3", "type": "dht", "poll_interval": 3},
{"zone": "7", "type": "ds18b20", "name": "temper", "poll_interval": 3},
{"zone": "11", "type": "dht", "poll_interval": 3},
],
"switches": [
{"activation": "high", "zone": "4"},
@ -1141,14 +1150,17 @@ async def test_option_flow_import(hass, mock_panel):
schema = result["data_schema"]({})
assert schema["blink"] is True
assert schema["discovery"] is True
result = await hass.config_entries.options.async_configure(
result["flow_id"], user_input={"blink": False, "override_api_host": False},
result["flow_id"],
user_input={"discovery": True, "blink": False, "override_api_host": False},
)
# verify the updated fields
assert result["type"] == "create_entry"
assert result["data"] == {
"io": {"1": "Binary Sensor", "2": "Digital Sensor", "3": "Switchable Output"},
"discovery": True,
"blink": False,
"api_host": "",
"binary_sensors": [

View File

@ -224,9 +224,9 @@ async def test_create_and_setup_pro(hass, mock_panel):
"2": "Binary Sensor",
"6": "Binary Sensor",
"10": "Binary Sensor",
"11": "Binary Sensor",
"3": "Digital Sensor",
"7": "Digital Sensor",
"11": "Digital Sensor",
"4": "Switchable Output",
"8": "Switchable Output",
"out1": "Switchable Output",
@ -236,11 +236,11 @@ async def test_create_and_setup_pro(hass, mock_panel):
{"zone": "2", "type": "door"},
{"zone": "6", "type": "window", "name": "winder", "inverse": True},
{"zone": "10", "type": "door"},
{"zone": "11", "type": "window"},
],
"sensors": [
{"zone": "3", "type": "dht"},
{"zone": "3", "type": "dht", "poll_interval": 5},
{"zone": "7", "type": "ds18b20", "name": "temper"},
{"zone": "11", "type": "dht", "poll_interval": 5},
],
"switches": [
{"zone": "4"},
@ -294,17 +294,14 @@ async def test_create_and_setup_pro(hass, mock_panel):
# confirm the settings are sent to the panel
# pylint: disable=no-member
assert mock_panel.put_settings.call_args_list[0][1] == {
"sensors": [{"zone": "2"}, {"zone": "6"}, {"zone": "10"}],
"sensors": [{"zone": "2"}, {"zone": "6"}, {"zone": "10"}, {"zone": "11"}],
"actuators": [
{"trigger": 1, "zone": "4"},
{"trigger": 0, "zone": "8"},
{"trigger": 1, "zone": "out1"},
{"trigger": 1, "zone": "alarm1"},
],
"dht_sensors": [
{"poll_interval": 3, "zone": "3"},
{"poll_interval": 5, "zone": "11"},
],
"dht_sensors": [{"poll_interval": 5, "zone": "3"}],
"ds18b20_sensors": [{"zone": "7"}],
"auth_token": "11223344556677889900",
"blink": True,
@ -315,6 +312,12 @@ async def test_create_and_setup_pro(hass, mock_panel):
# confirm the device settings are saved in hass.data
assert device.stored_configuration == {
"binary_sensors": {
"11": {
"inverse": False,
"name": "Konnected 445566 Zone 11",
"state": None,
"type": "window",
},
"10": {
"inverse": False,
"name": "Konnected 445566 Zone 10",
@ -337,17 +340,11 @@ async def test_create_and_setup_pro(hass, mock_panel):
"sensors": [
{
"name": "Konnected 445566 Sensor 3",
"poll_interval": 3,
"poll_interval": 5,
"type": "dht",
"zone": "3",
},
{"name": "temper", "poll_interval": 3, "type": "ds18b20", "zone": "7"},
{
"name": "Konnected 445566 Sensor 11",
"poll_interval": 5,
"type": "dht",
"zone": "11",
},
],
"switches": [
{