Enhance configuration flow to allow single instance only
- Implemented check to abort configuration if an instance already exists - Updated error messages in strings.json to reflect new abort reason
This commit is contained in:
@@ -40,6 +40,9 @@ class JackeryHomeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Handle the initial step."""
|
"""Handle the initial step."""
|
||||||
|
if self._async_current_entries():
|
||||||
|
return self.async_abort(reason="single_instance_allowed")
|
||||||
|
|
||||||
errors = {}
|
errors = {}
|
||||||
|
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
@@ -57,10 +60,6 @@ class JackeryHomeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
errors["base"] = "invalid_port"
|
errors["base"] = "invalid_port"
|
||||||
|
|
||||||
if not errors:
|
if not errors:
|
||||||
# 检查是否已经配置
|
|
||||||
await self.async_set_unique_id(DOMAIN)
|
|
||||||
self._abort_if_unique_id_configured()
|
|
||||||
|
|
||||||
_LOGGER.info(f"Creating JackeryHome config entry with topic_prefix: {user_input.get('topic_prefix', 'homeassistant/sensor')}")
|
_LOGGER.info(f"Creating JackeryHome config entry with topic_prefix: {user_input.get('topic_prefix', 'homeassistant/sensor')}")
|
||||||
|
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
|
|||||||
@@ -17,7 +17,8 @@
|
|||||||
"invalid_port": "端口号必须在 1-65535 范围内"
|
"invalid_port": "端口号必须在 1-65535 范围内"
|
||||||
},
|
},
|
||||||
"abort": {
|
"abort": {
|
||||||
"already_configured": "该集成已配置"
|
"already_configured": "该集成已配置",
|
||||||
|
"single_instance_allowed": "该集成已配置"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user