diff --git a/homeassistant/components/mqtt/mixins.py b/homeassistant/components/mqtt/mixins.py index e90301875e4..1fbe4305dd6 100644 --- a/homeassistant/components/mqtt/mixins.py +++ b/homeassistant/components/mqtt/mixins.py @@ -290,24 +290,6 @@ class SetupEntity(Protocol): """Define setup_entities type.""" -async def async_get_platform_config_from_yaml( - hass: HomeAssistant, - platform_domain: str, - config_yaml: ConfigType | None = None, -) -> list[ConfigType]: - """Return a list of validated configurations for the domain.""" - platform_configs: Any | None - mqtt_data = get_mqtt_data(hass) - if config_yaml is None: - config_yaml = mqtt_data.config - if not config_yaml: - return [] - if not (platform_configs := config_yaml.get(platform_domain)): - return [] - assert isinstance(platform_configs, list) - return platform_configs - - async def async_setup_entry_helper( hass: HomeAssistant, domain: str, @@ -359,14 +341,7 @@ async def async_setup_entry_helper( return if domain not in config_yaml: return - await asyncio.gather( - *[ - async_setup(config) - for config in await async_get_platform_config_from_yaml( - hass, domain, config_yaml - ) - ] - ) + await asyncio.gather(*[async_setup(config) for config in config_yaml[domain]]) # discover manual configured MQTT items mqtt_data.reload_handlers[domain] = _async_setup_entities @@ -800,6 +775,7 @@ class MqttDiscoveryDeviceUpdate(ABC): self.hass, self._device_id, self._config_entry_id ) + @abstractmethod async def async_update(self, discovery_data: MQTTDiscoveryPayload) -> None: """Handle the update of platform specific parts, extend to the platform.""" diff --git a/tests/components/mqtt/test_init.py b/tests/components/mqtt/test_init.py index 219e11cfdfe..337407d6c6b 100644 --- a/tests/components/mqtt/test_init.py +++ b/tests/components/mqtt/test_init.py @@ -3062,3 +3062,16 @@ async def test_link_config_entry(hass, tmp_path, caplog): # reload manual configured items and assert again await help_test_reload_with_config(hass, caplog, tmp_path, config_manual) assert _check_entities() == 2 + + +@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR]) +@pytest.mark.parametrize( + "config_manual", + [ + {"mqtt": {"sensor": []}}, + {"mqtt": {"broker": "test"}}, + ], +) +async def test_setup_manual_entity_from_yaml(hass: HomeAssistant, config_manual): + """Test setup with empty platform keys.""" + await help_test_setup_manual_entity_from_yaml(hass, config_manual)