Skip to content

Commit 0d07025

Browse files
authored
Clarify text in config flow (#116)
* Update config flow texts * Update tests
1 parent 8189bfa commit 0d07025

File tree

5 files changed

+73
-72
lines changed

5 files changed

+73
-72
lines changed

custom_components/ta_cmi/config_flow.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,10 @@ async def async_step_devices(
195195
await fetch_device(dev)
196196

197197
except ApiError as err:
198-
if "Unknown" not in str(err):
198+
if "Device not supported" in str(err):
199+
errors["base"] = "invalid_device"
200+
_LOGGER.warning("Invalid device: %s", dev.id)
201+
elif "Unknown" not in str(err):
199202
errors["base"] = "device_error"
200203
_LOGGER.warning(
201204
"Error while communicating with a device (%s): %s", dev.id, err
@@ -207,9 +210,6 @@ async def async_step_devices(
207210
except RateLimitError:
208211
errors["base"] = "rate_limit"
209212
break
210-
except InvalidDeviceError:
211-
errors["base"] = "invalid_device"
212-
_LOGGER.warning("Invalid device: %s", dev.id)
213213
except Exception as err: # pylint: disable=broad-except
214214
_LOGGER.exception("Unexpected exception: %s", err)
215215
errors["base"] = "unknown"

custom_components/ta_cmi/strings.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
},
1313
"devices": {
1414
"title": "Set up Nodes",
15-
"description": "Select devices to monitor from the list below",
1615
"data": {
17-
"devices": "Connected devices",
16+
"devices": "Select devices to monitor from the list below",
1817
"edit_channels": "Edit channels?",
1918
"fetchmode": "Fetch all channels. (Otherwise only defined channels)"
2019
}
@@ -36,7 +35,7 @@
3635
"rate_limit": "C.M.I rate limit reached. Try again in one minute.",
3736
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
3837
"device_error": "Error while communicating with a device. See logs for details.",
39-
"invalid_device" : "Invalid device connected to the CMI. See logs for details.",
38+
"invalid_device" : "Invalid device connected to the CMI. It was ignored. See logs for details.",
4039
"unknown": "[%key:common::config_flow::error::unknown%]",
4140
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]"
4241
}
@@ -55,7 +54,7 @@
5554
"rate_limit": "C.M.I rate limit reached. Try again in one minute.",
5655
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
5756
"device_error": "Error while communicating with a device. See logs for details.",
58-
"invalid_device" : "Invalid device connected to the CMI. See logs for details.",
57+
"invalid_device" : "Invalid device connected to the CMI. It was ignored. See logs for details.",
5958
"unknown": "[%key:common::config_flow::error::unknown%]",
6059
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]"
6160
}

custom_components/ta_cmi/translations/de.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
},
1313
"devices": {
1414
"title": "Knoten einrichten",
15-
"description": "Geräte zum Abfragen aus der Liste auswählen",
1615
"data": {
17-
"devices": "Verbundene Geräte",
16+
"devices": "Geräte zum Abfragen aus der Liste auswählen",
1817
"edit_channels": "Kanäle bearbeiten?",
1918
"fetchmode": "Alle Kanäle abrufen. (Sonst nur konfigurierte Kanäle)"
2019
}
@@ -36,7 +35,7 @@
3635
"rate_limit": "Maximalanzahl an Abfragen pro Minute erreicht. Probiere es in einer Minute erneut.",
3736
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
3837
"device_error": "Fehler bei der Kommunikation mit einem Gerät. Details siehe Logs.",
39-
"invalid_device" : "Ungültiges Gerät mit der C.M.I. verbunden. Details siehe Logs.",
38+
"invalid_device" : "Ungültiges Gerät mit der C.M.I. verbunden. Es wurde ignoriert. Details siehe Logs.",
4039
"unknown": "[%key:common::config_flow::error::unknown%]",
4140
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]"
4241
}
@@ -55,7 +54,7 @@
5554
"rate_limit": "Maximalanzahl an Abfragen pro Minute erreicht. Probiere es in einer Minute erneut.",
5655
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
5756
"device_error": "Fehler bei der Kommunikation mit einem Gerät. Details siehe Logs.",
58-
"invalid_device" : "Ungültiges Gerät mit der C.M.I. verbunden. Details siehe Logs.",
57+
"invalid_device" : "Ungültiges Gerät mit der C.M.I. verbunden. Es wurde ignoriert. Details siehe Logs.",
5958
"unknown": "[%key:common::config_flow::error::unknown%]",
6059
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]"
6160
}
Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,62 @@
11
{
2-
"config": {
3-
"step": {
4-
"user": {
5-
"title": "Set up C.M.I",
6-
"data": {
7-
"host": "Base url of the C.M.I (http://IP)",
8-
"username": "Username",
9-
"password": "Password",
10-
"fetch_can_logging": "Use additional data sources for supported devices"
11-
}
12-
},
13-
"devices": {
14-
"title": "Set up Nodes",
15-
"description": "Select devices to monitor from the list below",
16-
"data": {
17-
"devices": "Connected devices",
18-
"edit_channels": "Edit channels?",
19-
"fetchmode": "Fetch all channels. (Otherwise only defined channels)"
20-
}
21-
},
22-
"channel": {
23-
"title": "Configure channel",
24-
"description": "Configure the channel to your needs",
25-
"data": {
26-
"node": "Node",
27-
"id": "ID of the channel",
28-
"type": "Input type",
29-
"name": "Name of the sensor",
30-
"device_class": "Override the device class (Optional)",
31-
"edit_more_channels": "Edit other channels?"
32-
}
2+
"config": {
3+
"step": {
4+
"user": {
5+
"title": "Set up C.M.I",
6+
"data": {
7+
"host": "Base url of the C.M.I (http://IP)",
8+
"username": "Username",
9+
"password": "Password",
10+
"fetch_can_logging": "Use additional data sources for supported devices"
3311
}
3412
},
35-
"error": {
36-
"rate_limit": "C.M.I rate limit reached. Try again in one minute.",
37-
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
38-
"device_error": "Error while communicating with a device. See logs for details.",
39-
"invalid_device" : "Invalid device connected to the CMI. See logs for details.",
40-
"unknown": "[%key:common::config_flow::error::unknown%]",
41-
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]"
13+
"devices": {
14+
"title": "Set up Nodes",
15+
"data": {
16+
"devices": "Select devices to monitor from the list below",
17+
"edit_channels": "Edit channels?",
18+
"fetchmode": "Fetch all channels. (Otherwise only defined channels)"
19+
}
20+
},
21+
"channel": {
22+
"title": "Configure channel",
23+
"description": "Configure the channel to your needs",
24+
"data": {
25+
"node": "Node",
26+
"id": "ID of the channel",
27+
"type": "Input type",
28+
"name": "Name of the sensor",
29+
"device_class": "Override the device class (Optional)",
30+
"edit_more_channels": "Edit other channels?"
31+
}
4232
}
4333
},
44-
"options": {
45-
"step": {
46-
"init": {
47-
"title": "Options",
48-
"data": {
49-
"scan_interval": "Update interval (minutes)",
50-
"host": "Base url of the C.M.I (http://IP)"
51-
}
34+
"error": {
35+
"rate_limit": "C.M.I rate limit reached. Try again in one minute.",
36+
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
37+
"device_error": "Error while communicating with a device. See logs for details.",
38+
"invalid_device" : "Invalid device connected to the CMI. It was ignored. See logs for details.",
39+
"unknown": "[%key:common::config_flow::error::unknown%]",
40+
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]"
41+
}
42+
},
43+
"options": {
44+
"step": {
45+
"init": {
46+
"title": "Options",
47+
"data": {
48+
"scan_interval": "Update interval (minutes)",
49+
"host": "Base url of the C.M.I (http://IP)"
5250
}
53-
},
54-
"error": {
55-
"rate_limit": "C.M.I rate limit reached. Try again in one minute.",
56-
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
57-
"device_error": "Error while communicating with a device. See logs for details.",
58-
"invalid_device" : "Invalid device connected to the CMI. See logs for details.",
59-
"unknown": "[%key:common::config_flow::error::unknown%]",
60-
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]"
6151
}
52+
},
53+
"error": {
54+
"rate_limit": "C.M.I rate limit reached. Try again in one minute.",
55+
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
56+
"device_error": "Error while communicating with a device. See logs for details.",
57+
"invalid_device" : "Invalid device connected to the CMI. It was ignored. See logs for details.",
58+
"unknown": "[%key:common::config_flow::error::unknown%]",
59+
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]"
6260
}
6361
}
62+
}

tests/test_config_flow.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135

136136
DUMMY_ENTRY_CHANGE_IP: dict[str, Any] = {
137137
CONF_SCAN_INTERVAL: 15,
138-
CONF_HOST: "http://localhost2"
138+
CONF_HOST: "http://localhost2",
139139
}
140140

141141
DUMMY_CONFIG_ENTRY_UPDATED: dict[str, Any] = {
@@ -295,7 +295,7 @@ async def test_step_user_unkown_device(hass: HomeAssistant) -> None:
295295

296296
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
297297
assert result["step_id"] == "devices"
298-
assert result["errors"] == {"base": "invalid_device"}
298+
assert result["errors"] == {"base": "unknown"}
299299

300300

301301
@pytest.mark.asyncio
@@ -402,7 +402,7 @@ async def test_step_devices_with_multiple_devices(hass: HomeAssistant) -> None:
402402

403403
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
404404
assert result["step_id"] == "devices"
405-
assert result["errors"] == {"base": "invalid_device"}
405+
assert result["errors"] == {"base": "unknown"}
406406

407407

408408
@pytest.mark.asyncio
@@ -574,6 +574,7 @@ async def test_options_flow_init_no_ip(hass: HomeAssistant) -> None:
574574
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
575575
assert dict(config_entry.options) == DUMMY_CONFIG_ENTRY_UPDATED
576576

577+
577578
@pytest.mark.asyncio
578579
async def test_options_flow_init(hass: HomeAssistant) -> None:
579580
"""Test config flow options with ip change."""
@@ -585,8 +586,8 @@ async def test_options_flow_init(hass: HomeAssistant) -> None:
585586
config_entry.add_to_hass(hass)
586587

587588
with patch("custom_components.ta_cmi.async_setup_entry", return_value=True), patch(
588-
"ta_cmi.cmi_api.CMIAPI._make_request_no_json",
589-
return_value="2;",
589+
"ta_cmi.cmi_api.CMIAPI._make_request_no_json",
590+
return_value="2;",
590591
), patch(
591592
"ta_cmi.cmi_api.CMIAPI._make_request_get", return_value=DUMMY_DEVICE_API_DATA
592593
), patch(
@@ -608,6 +609,7 @@ async def test_options_flow_init(hass: HomeAssistant) -> None:
608609
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
609610
assert dict(config_entry.options) == DUMMY_CONFIG_ENTRY_UPDATED_IP
610611

612+
611613
@pytest.mark.asyncio
612614
async def test_options_flow_ip_change_invalid_auth(hass: HomeAssistant) -> None:
613615
"""Test config flow options with ip change and invalid auth."""
@@ -640,6 +642,7 @@ async def test_options_flow_ip_change_invalid_auth(hass: HomeAssistant) -> None:
640642
assert result["errors"] == {"base": "invalid_auth"}
641643
assert dict(config_entry.options) == {}
642644

645+
643646
@pytest.mark.asyncio
644647
async def test_options_flow_ip_change_connection_error(hass: HomeAssistant) -> None:
645648
"""Test config flow options with ip change and connection error."""
@@ -672,6 +675,7 @@ async def test_options_flow_ip_change_connection_error(hass: HomeAssistant) -> N
672675
assert result["errors"] == {"base": "cannot_connect"}
673676
assert dict(config_entry.options) == {}
674677

678+
675679
@pytest.mark.asyncio
676680
async def test_options_flow_ip_change_unexpected_error(hass: HomeAssistant) -> None:
677681
"""Test config flow options with ip change and unexpected error."""
@@ -702,4 +706,4 @@ async def test_options_flow_ip_change_unexpected_error(hass: HomeAssistant) -> N
702706
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
703707
assert result["step_id"] == "init"
704708
assert result["errors"] == {"base": "unknown"}
705-
assert dict(config_entry.options) == {}
709+
assert dict(config_entry.options) == {}

0 commit comments

Comments
 (0)