修复多网关下相同分机编号的实体冲突#3
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the ds_air integration to support multiple gateways by incorporating the gateway ID into device unique IDs and registering the gateway itself in the device registry. The review feedback highlights critical backward compatibility issues where existing sensor bindings using climate aliases will fail to load or pre-populate in the options flow. Additionally, the reviewer suggests adding defensive null checks for device aliases to prevent potential runtime errors, and improving the usability of multi-gateway setups by dynamically naming gateway devices and appending host IPs to integration titles.
| climate_id = i.get("climate") | ||
| if climate := climate_by_unique_id.get(climate_id): |
There was a problem hiding this comment.
对于已经配置了传感器绑定的现有用户,其绑定关系中存储的是空调的 alias(名称)而不是新的 unique_id。升级到此版本后,由于 climate_by_unique_id.get(climate_id) 会返回 None,这些已有的绑定关系将会静默失效。建议在此处增加一个基于 alias 匹配的兼容逻辑,以确保向后兼容性。
| climate_id = i.get("climate") | |
| if climate := climate_by_unique_id.get(climate_id): | |
| climate_id = i.get("climate") | |
| climate = climate_by_unique_id.get(climate_id) | |
| if not climate: | |
| climate = next((c for c in climates if c._device_info.alias == climate_id), None) | |
| if climate: |
There was a problem hiding this comment.
当前为了避免代码过度复杂化,没有加向后兼容的逻辑。如果后续讨论认为有这个必要,可以再加入完整的向后兼容代码。
| cur_link = next( | ||
| (link for link in cur_links if link["climate"] == cur_climate), None | ||
| (link for link in cur_links if link.get("climate") == cur_climate), None | ||
| ) |
There was a problem hiding this comment.
与气候实体绑定类似,在编辑选项(OptionsFlow)时,cur_links 中已有的绑定关系可能仍使用空调的 alias。如果不做兼容处理,选项表单将无法正确回显(pre-populate)已有的传感器绑定。建议在此处增加对 alias 的兼容匹配。
service = self.hass.data[DOMAIN][self._config_entry.entry_id]
aircon = next((ac for ac in service.get_aircons() if ac.unique_id == cur_climate), None)
cur_link = next(
(
link for link in cur_links
if link.get("climate") == cur_climate
or (aircon and link.get("climate") == aircon.alias)
),
None
)There was a problem hiding this comment.
当前为了避免代码过度复杂化,没有加向后兼容的逻辑。如果后续讨论认为有这个必要,可以再加入完整的向后兼容代码。
| return self.async_create_entry( | ||
| title=get_default_gateway_name(), | ||
| data=self.user_input, | ||
| ) |
There was a problem hiding this comment.
There was a problem hiding this comment.
使用IP地址作为实体名称有些奇怪,实际上最好的方案是用金制空气APP中的名称或者MAC地址,不过相关方法目前没有实现。我也想过改成“智能网关”作为默认名,不过还涉及到一些本地化的修改,就暂时没动。
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
我觉得兼容还是有必要的,我实测了一下直接切到这个版本,原有实体就失效了,清理一遍很麻烦的,希望能无感升级。建议加上迁移逻辑 |
|
上游今天把这些PR合并了,但是没有包含你最后一个提交(dbd6ea1),建议单开一个PR给上游。这个迁移流程我测试过了,没有问题。 |
背景
当前 DS-AIR 实体的 unique_id 主要依赖 room_id / unit_id。多个网关同时接入时,不同网关下
可能存在相同的分机编号,Home Assistant 会把它们识别为同一设备或实体,导致第二个网关的部
分空调/传感器无法正常创建。
改动
关下 room_id / unit_id 重复冲突
告
注意
Home Assistant 视为新实体;但新接入和多网关场景下可以正确区分不同网关的设备。
测试
在我自己的HA实例上测试没有发现问题。HA版本2026.5.4。
