From 50ff16df4834a9b9efaedb3f84919b971c170aa8 Mon Sep 17 00:00:00 2001 From: Necroneco Date: Tue, 16 Jul 2024 16:59:28 +0800 Subject: [PATCH 1/2] fix `StopIteration` error --- custom_components/ds_air/config_flow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/ds_air/config_flow.py b/custom_components/ds_air/config_flow.py index b2e37f4..e0d85db 100644 --- a/custom_components/ds_air/config_flow.py +++ b/custom_components/ds_air/config_flow.py @@ -186,7 +186,7 @@ async def async_step_bind_sensors(self, user_input: dict[str, Any] | None = None return self.async_create_entry(title="", data={"link": self._config_data}) cur_climate: str = self._climates[self._cur] cur_links = self.config_entry.options.get("link", []) - cur_link = next(link for link in cur_links if link["climate"] == cur_climate) + cur_link = next((link for link in cur_links if link["climate"] == cur_climate), None) cur_sensor_temp = cur_link.get("sensor_temp") if cur_link else None cur_sensor_humi = cur_link.get("sensor_humi") if cur_link else None return self.async_show_form( From e78ba05a6e9067d3aaabf10b9cc2bcaeb1336205 Mon Sep 17 00:00:00 2001 From: mypal Date: Mon, 12 Aug 2024 16:44:31 +0800 Subject: [PATCH 2/2] fix: sensor link is optional --- custom_components/ds_air/config_flow.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/custom_components/ds_air/config_flow.py b/custom_components/ds_air/config_flow.py index e0d85db..d70f9d9 100644 --- a/custom_components/ds_air/config_flow.py +++ b/custom_components/ds_air/config_flow.py @@ -99,14 +99,20 @@ def __init__(self, config_entry: config_entries.ConfigEntry) -> None: self._climates = list(map(lambda state: state.alias, Service.get_aircons())) sensors = hass.states.async_all("sensor") self._sensors_temp = { - state.entity_id: f"{state.attributes.get(ATTR_FRIENDLY_NAME, state.entity_id)} ({state.entity_id})" - for state in sensors - if state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TEMPERATURE + None: 'None', + **{ + state.entity_id: f"{state.attributes.get(ATTR_FRIENDLY_NAME, state.entity_id)} ({state.entity_id})" + for state in sensors + if state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TEMPERATURE + } } self._sensors_humi = { - state.entity_id: f"{state.attributes.get(ATTR_FRIENDLY_NAME, state.entity_id)} ({state.entity_id})" - for state in sensors - if state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.HUMIDITY + None: 'None', + **{ + state.entity_id: f"{state.attributes.get(ATTR_FRIENDLY_NAME, state.entity_id)} ({state.entity_id})" + for state in sensors + if state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.HUMIDITY + } } self._len = len(self._climates) self._cur = -1