added support for multiple instances
Some checks failed
Validate / Validate (push) Has been cancelled

This commit is contained in:
2026-05-31 11:36:30 +02:00
parent 1f122f2235
commit 85eed58a06
6 changed files with 22 additions and 20 deletions

View File

@@ -35,12 +35,15 @@ class JackeryConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle the initial step."""
if self._async_current_entries():
return self.async_abort(reason="single_instance_allowed")
errors = {}
if user_input is not None:
# Check for duplicate device SN
new_sn = user_input.get("device_sn", "")
for entry in self._async_current_entries():
if entry.data.get("device_sn") == new_sn:
return self.async_abort(reason="already_configured")
# 检查 MQTT 集成是否已配置
if not await mqtt.async_wait_for_mqtt_client(self.hass):
errors["base"] = "mqtt_not_configured"
@@ -52,7 +55,7 @@ class JackeryConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
)
return self.async_create_entry(
title="Jackery",
title=f"Jackery {new_sn}",
data=user_input,
)