Skip to content

Commit bd4d0ec

Browse files
authored
Add initial MQTT subentry support for notify entities (home-assistant#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
1 parent dcc63a6 commit bd4d0ec

9 files changed

Lines changed: 1544 additions & 22 deletions

File tree

homeassistant/components/mqtt/__init__.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from homeassistant import config as conf_util
1414
from homeassistant.components import websocket_api
1515
from homeassistant.config_entries import ConfigEntry
16-
from homeassistant.const import CONF_DISCOVERY, SERVICE_RELOAD
16+
from homeassistant.const import CONF_DISCOVERY, CONF_PLATFORM, SERVICE_RELOAD
1717
from homeassistant.core import HomeAssistant, ServiceCall, callback
1818
from homeassistant.exceptions import (
1919
ConfigValidationError,
@@ -81,6 +81,7 @@
8181
ENTRY_OPTION_FIELDS,
8282
MQTT_CONNECTION_STATE,
8383
TEMPLATE_ERRORS,
84+
Platform,
8485
)
8586
from .models import (
8687
DATA_MQTT,
@@ -293,6 +294,21 @@ async def async_check_config_schema(
293294
) from exc
294295

295296

297+
def _platforms_in_use(hass: HomeAssistant, entry: ConfigEntry) -> set[str | Platform]:
298+
"""Return a set of platforms in use."""
299+
domains: set[str | Platform] = {
300+
entry.domain
301+
for entry in er.async_entries_for_config_entry(
302+
er.async_get(hass), entry.entry_id
303+
)
304+
}
305+
# Update with domains from subentries
306+
for subentry in entry.subentries.values():
307+
components = subentry.data["components"].values()
308+
domains.update(component[CONF_PLATFORM] for component in components)
309+
return domains
310+
311+
296312
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
297313
"""Set up the actions and websocket API for the MQTT component."""
298314

@@ -434,12 +450,7 @@ async def _setup_client() -> tuple[MqttData, dict[str, Any]]:
434450

435451
mqtt_data, conf = await _setup_client()
436452
platforms_used = platforms_from_config(mqtt_data.config)
437-
platforms_used.update(
438-
entry.domain
439-
for entry in er.async_entries_for_config_entry(
440-
er.async_get(hass), entry.entry_id
441-
)
442-
)
453+
platforms_used.update(_platforms_in_use(hass, entry))
443454
integration = async_get_loaded_integration(hass, DOMAIN)
444455
# Preload platforms we know we are going to use so
445456
# discovery can setup each platform synchronously

0 commit comments

Comments
 (0)