mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Move MQTT device sw and hw version to collapsed section in subentry flow (#147685)
Move MQTT device sw and hw version to collapsed section
This commit is contained in:
parent
a65eb57539
commit
862b7460b5
@ -1904,8 +1904,12 @@ ENTITY_CONFIG_VALIDATOR: dict[
|
|||||||
|
|
||||||
MQTT_DEVICE_PLATFORM_FIELDS = {
|
MQTT_DEVICE_PLATFORM_FIELDS = {
|
||||||
ATTR_NAME: PlatformField(selector=TEXT_SELECTOR, required=True),
|
ATTR_NAME: PlatformField(selector=TEXT_SELECTOR, required=True),
|
||||||
ATTR_SW_VERSION: PlatformField(selector=TEXT_SELECTOR, required=False),
|
ATTR_SW_VERSION: PlatformField(
|
||||||
ATTR_HW_VERSION: PlatformField(selector=TEXT_SELECTOR, required=False),
|
selector=TEXT_SELECTOR, required=False, section="advanced_settings"
|
||||||
|
),
|
||||||
|
ATTR_HW_VERSION: PlatformField(
|
||||||
|
selector=TEXT_SELECTOR, required=False, section="advanced_settings"
|
||||||
|
),
|
||||||
ATTR_MODEL: PlatformField(selector=TEXT_SELECTOR, required=False),
|
ATTR_MODEL: PlatformField(selector=TEXT_SELECTOR, required=False),
|
||||||
ATTR_MODEL_ID: PlatformField(selector=TEXT_SELECTOR, required=False),
|
ATTR_MODEL_ID: PlatformField(selector=TEXT_SELECTOR, required=False),
|
||||||
ATTR_CONFIGURATION_URL: PlatformField(
|
ATTR_CONFIGURATION_URL: PlatformField(
|
||||||
@ -2725,6 +2729,19 @@ class MQTTSubentryFlowHandler(ConfigSubentryFlow):
|
|||||||
for field_key, value in data_schema.schema.items()
|
for field_key, value in data_schema.schema.items()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def get_suggested_values_from_device_data(
|
||||||
|
self, data_schema: vol.Schema
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Get suggestions from device data based on the data schema."""
|
||||||
|
device_data = self._subentry_data["device"]
|
||||||
|
return {
|
||||||
|
field_key: self.get_suggested_values_from_device_data(value.schema)
|
||||||
|
if isinstance(value, section)
|
||||||
|
else device_data.get(field_key)
|
||||||
|
for field_key, value in data_schema.schema.items()
|
||||||
|
}
|
||||||
|
|
||||||
async def async_step_user(
|
async def async_step_user(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> SubentryFlowResult:
|
) -> SubentryFlowResult:
|
||||||
@ -2754,15 +2771,25 @@ class MQTTSubentryFlowHandler(ConfigSubentryFlow):
|
|||||||
reconfig=True,
|
reconfig=True,
|
||||||
)
|
)
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
_, errors = validate_user_input(user_input, MQTT_DEVICE_PLATFORM_FIELDS)
|
new_device_data, errors = validate_user_input(
|
||||||
|
user_input, MQTT_DEVICE_PLATFORM_FIELDS
|
||||||
|
)
|
||||||
|
if "mqtt_settings" in user_input:
|
||||||
|
new_device_data["mqtt_settings"] = user_input["mqtt_settings"]
|
||||||
if not errors:
|
if not errors:
|
||||||
self._subentry_data[CONF_DEVICE] = cast(MqttDeviceData, user_input)
|
self._subentry_data[CONF_DEVICE] = cast(MqttDeviceData, new_device_data)
|
||||||
if self.source == SOURCE_RECONFIGURE:
|
if self.source == SOURCE_RECONFIGURE:
|
||||||
return await self.async_step_summary_menu()
|
return await self.async_step_summary_menu()
|
||||||
return await self.async_step_entity()
|
return await self.async_step_entity()
|
||||||
data_schema = self.add_suggested_values_to_schema(
|
data_schema = self.add_suggested_values_to_schema(
|
||||||
data_schema, device_data if user_input is None else user_input
|
data_schema, device_data if user_input is None else user_input
|
||||||
)
|
)
|
||||||
|
elif self.source == SOURCE_RECONFIGURE:
|
||||||
|
data_schema = self.add_suggested_values_to_schema(
|
||||||
|
data_schema,
|
||||||
|
self.get_suggested_values_from_device_data(data_schema),
|
||||||
|
)
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id=CONF_DEVICE,
|
step_id=CONF_DEVICE,
|
||||||
data_schema=data_schema,
|
data_schema=data_schema,
|
||||||
|
@ -134,20 +134,27 @@
|
|||||||
"data": {
|
"data": {
|
||||||
"name": "[%key:common::config_flow::data::name%]",
|
"name": "[%key:common::config_flow::data::name%]",
|
||||||
"configuration_url": "Configuration URL",
|
"configuration_url": "Configuration URL",
|
||||||
"sw_version": "Software version",
|
|
||||||
"hw_version": "Hardware version",
|
|
||||||
"model": "Model",
|
"model": "Model",
|
||||||
"model_id": "Model ID"
|
"model_id": "Model ID"
|
||||||
},
|
},
|
||||||
"data_description": {
|
"data_description": {
|
||||||
"name": "The name of the manually added MQTT device.",
|
"name": "The name of the manually added MQTT device.",
|
||||||
"configuration_url": "A link to the webpage that can manage the configuration of this device. Can be either a 'http://', 'https://' or an internal 'homeassistant://' URL.",
|
"configuration_url": "A link to the webpage that can manage the configuration of this device. Can be either a 'http://', 'https://' or an internal 'homeassistant://' URL.",
|
||||||
"sw_version": "The software version of the device. E.g. '2025.1.0'.",
|
|
||||||
"hw_version": "The hardware version of the device. E.g. 'v1.0 rev a'.",
|
|
||||||
"model": "E.g. 'Cleanmaster Pro'.",
|
"model": "E.g. 'Cleanmaster Pro'.",
|
||||||
"model_id": "E.g. '123NK2PRO'."
|
"model_id": "E.g. '123NK2PRO'."
|
||||||
},
|
},
|
||||||
"sections": {
|
"sections": {
|
||||||
|
"advanced_settings": {
|
||||||
|
"name": "Advanced device settings",
|
||||||
|
"data": {
|
||||||
|
"sw_version": "Software version",
|
||||||
|
"hw_version": "Hardware version"
|
||||||
|
},
|
||||||
|
"data_description": {
|
||||||
|
"sw_version": "The software version of the device. E.g. '2025.1.0'.",
|
||||||
|
"hw_version": "The hardware version of the device. E.g. 'v1.0 rev a'."
|
||||||
|
}
|
||||||
|
},
|
||||||
"mqtt_settings": {
|
"mqtt_settings": {
|
||||||
"name": "MQTT settings",
|
"name": "MQTT settings",
|
||||||
"data": {
|
"data": {
|
||||||
|
@ -4073,7 +4073,7 @@ async def test_subentry_reconfigure_update_device_properties(
|
|||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
user_input={
|
user_input={
|
||||||
"name": "Beer notifier",
|
"name": "Beer notifier",
|
||||||
"sw_version": "1.1",
|
"advanced_settings": {"sw_version": "1.1"},
|
||||||
"model": "Beer bottle XL",
|
"model": "Beer bottle XL",
|
||||||
"model_id": "bn003",
|
"model_id": "bn003",
|
||||||
"configuration_url": "https://example.com",
|
"configuration_url": "https://example.com",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user