added support for multiple instances
Some checks failed
Validate / Validate (push) Has been cancelled
Some checks failed
Validate / Validate (push) Has been cancelled
This commit is contained in:
@@ -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,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user