Add initial MQTT subentry support for notify entities (#138461)

* Add initial MQTT subentry support for notify entities

* Fix componts assigment is reset on device config. Translation tweaks

* Rephrase

* Go to summary menu when components are set up already - add test

* Fix suggested device info on config flow

* Invert

* Simplify subentry config flow and omit menu

* Use constants instead of literals

* More constants

* Teak some translations

* Only show save when the the entry is dirty

* Do not trigger an entry reload twice

* Remove encoding, entity_category

* Remove icon from mqtt subentry flow

* Separate entity settings and MQTT specific settings

* Remove object_id and refactor

* Migrate translations

* Make subconfig flow test extensible

* Make sub reconfig flow tests extensible

* Rename entity_platform_config step to mqtt_platform_config

* Make component unique ID independent from the name

* Move code for update of component data to helper

* Follow up on code review

* Skip dirty stuff

* Fix rebase issues #1

* Do not allow reconfig for entity platform/name, default QoS and refactor tests

* Add entity platform and entity name label to basic entity config dialog

* Rename to exclude_from_reconfig and make reconfig option not optional
This commit is contained in:
Jan Bouwhuis
2025-03-14 14:00:07 +01:00
committed by GitHub
parent dcc63a6f2e
commit bd4d0ec4b8
9 changed files with 1544 additions and 22 deletions

View File

@@ -67,7 +67,12 @@ from homeassistant.components.websocket_api.auth import (
# pylint: disable-next=hass-component-root-import
from homeassistant.components.websocket_api.http import URL
from homeassistant.config import YAML_CONFIG_FILE
from homeassistant.config_entries import ConfigEntries, ConfigEntry, ConfigEntryState
from homeassistant.config_entries import (
ConfigEntries,
ConfigEntry,
ConfigEntryState,
ConfigSubentryData,
)
from homeassistant.const import BASE_PLATFORMS, HASSIO_USER_NAME
from homeassistant.core import (
Context,
@@ -946,6 +951,12 @@ def mqtt_config_entry_data() -> dict[str, Any] | None:
return None
@pytest.fixture
def mqtt_config_subentries_data() -> tuple[ConfigSubentryData] | None:
"""Fixture to allow overriding MQTT subentries data."""
return None
@pytest.fixture
def mqtt_config_entry_options() -> dict[str, Any] | None:
"""Fixture to allow overriding MQTT entry options."""
@@ -1032,6 +1043,7 @@ async def mqtt_mock(
mqtt_client_mock: MqttMockPahoClient,
mqtt_config_entry_data: dict[str, Any] | None,
mqtt_config_entry_options: dict[str, Any] | None,
mqtt_config_subentries_data: tuple[ConfigSubentryData] | None,
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> AsyncGenerator[MqttMockHAClient]:
"""Fixture to mock MQTT component."""
@@ -1044,6 +1056,7 @@ async def _mqtt_mock_entry(
mqtt_client_mock: MqttMockPahoClient,
mqtt_config_entry_data: dict[str, Any] | None,
mqtt_config_entry_options: dict[str, Any] | None,
mqtt_config_subentries_data: tuple[ConfigSubentryData] | None,
) -> AsyncGenerator[MqttMockHAClientGenerator]:
"""Fixture to mock a delayed setup of the MQTT config entry."""
# Local import to avoid processing MQTT modules when running a testcase
@@ -1060,6 +1073,7 @@ async def _mqtt_mock_entry(
entry = MockConfigEntry(
data=mqtt_config_entry_data,
options=mqtt_config_entry_options,
subentries_data=mqtt_config_subentries_data,
domain=mqtt.DOMAIN,
title="MQTT",
version=1,
@@ -1174,6 +1188,7 @@ async def mqtt_mock_entry(
mqtt_client_mock: MqttMockPahoClient,
mqtt_config_entry_data: dict[str, Any] | None,
mqtt_config_entry_options: dict[str, Any] | None,
mqtt_config_subentries_data: tuple[ConfigSubentryData] | None,
) -> AsyncGenerator[MqttMockHAClientGenerator]:
"""Set up an MQTT config entry."""
@@ -1190,7 +1205,11 @@ async def mqtt_mock_entry(
return await mqtt_mock_entry(_async_setup_config_entry)
async with _mqtt_mock_entry(
hass, mqtt_client_mock, mqtt_config_entry_data, mqtt_config_entry_options
hass,
mqtt_client_mock,
mqtt_config_entry_data,
mqtt_config_entry_options,
mqtt_config_subentries_data,
) as mqtt_mock_entry:
yield _setup_mqtt_entry