Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions homeassistant/components/mqtt/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1904,8 +1904,12 @@ def validate_light_platform_config(user_data: dict[str, Any]) -> dict[str, str]:

MQTT_DEVICE_PLATFORM_FIELDS = {
ATTR_NAME: PlatformField(selector=TEXT_SELECTOR, required=True),
ATTR_SW_VERSION: PlatformField(selector=TEXT_SELECTOR, required=False),
ATTR_HW_VERSION: PlatformField(selector=TEXT_SELECTOR, required=False),
ATTR_SW_VERSION: PlatformField(
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_ID: PlatformField(selector=TEXT_SELECTOR, required=False),
ATTR_CONFIGURATION_URL: PlatformField(
Expand Down Expand Up @@ -2725,6 +2729,19 @@ def get_suggested_values_from_component(
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(
self, user_input: dict[str, Any] | None = None
) -> SubentryFlowResult:
Expand Down Expand Up @@ -2754,15 +2771,25 @@ async def async_step_device(
reconfig=True,
)
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:
self._subentry_data[CONF_DEVICE] = cast(MqttDeviceData, user_input)
self._subentry_data[CONF_DEVICE] = cast(MqttDeviceData, new_device_data)
if self.source == SOURCE_RECONFIGURE:
return await self.async_step_summary_menu()
return await self.async_step_entity()
data_schema = self.add_suggested_values_to_schema(
data_schema, device_data if user_input is None else user_input
)
data_schema = self.add_suggested_values_to_schema(
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(
step_id=CONF_DEVICE,
data_schema=data_schema,
Expand Down
15 changes: 11 additions & 4 deletions homeassistant/components/mqtt/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,27 @@
"data": {
"name": "[%key:common::config_flow::data::name%]",
"configuration_url": "Configuration URL",
"sw_version": "Software version",
"hw_version": "Hardware version",
"model": "Model",
"model_id": "Model ID"
},
"data_description": {
"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.",
"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_id": "E.g. '123NK2PRO'."
},
"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": {
"name": "MQTT settings",
"data": {
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/tibber/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"documentation": "https://www.home-assistant.io/integrations/tibber",
"iot_class": "cloud_polling",
"loggers": ["tibber"],
"requirements": ["pyTibber==0.31.2"]
"requirements": ["pyTibber==0.31.6"]
}
2 changes: 1 addition & 1 deletion homeassistant/components/tibber/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ async def async_setup_entry(
except TimeoutError as err:
_LOGGER.error("Timeout connecting to Tibber home: %s ", err)
raise PlatformNotReady from err
except aiohttp.ClientError as err:
except (tibber.RetryableHttpExceptionError, aiohttp.ClientError) as err:
_LOGGER.error("Error connecting to Tibber home: %s ", err)
raise PlatformNotReady from err

Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion requirements_test_all.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/components/mqtt/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4073,7 +4073,7 @@ async def test_subentry_reconfigure_update_device_properties(
result["flow_id"],
user_input={
"name": "Beer notifier",
"sw_version": "1.1",
"advanced_settings": {"sw_version": "1.1"},
"model": "Beer bottle XL",
"model_id": "bn003",
"configuration_url": "https://example.com",
Expand Down
Loading