Fire event_mqtt_reloaded only after reload is completed (#74226)
This commit is contained in:
parent
1bdd93cc77
commit
f05b4a0ca0
20 changed files with 96 additions and 123 deletions
|
@ -28,14 +28,12 @@ from homeassistant.data_entry_flow import BaseServiceInfo
|
||||||
from homeassistant.exceptions import TemplateError, Unauthorized
|
from homeassistant.exceptions import TemplateError, Unauthorized
|
||||||
from homeassistant.helpers import config_validation as cv, event, template
|
from homeassistant.helpers import config_validation as cv, event, template
|
||||||
from homeassistant.helpers.device_registry import DeviceEntry
|
from homeassistant.helpers.device_registry import DeviceEntry
|
||||||
from homeassistant.helpers.dispatcher import (
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
async_dispatcher_connect,
|
|
||||||
async_dispatcher_send,
|
|
||||||
)
|
|
||||||
from homeassistant.helpers.reload import (
|
from homeassistant.helpers.reload import (
|
||||||
async_integration_yaml_config,
|
async_integration_yaml_config,
|
||||||
async_setup_reload_service,
|
async_reload_integration_platforms,
|
||||||
)
|
)
|
||||||
|
from homeassistant.helpers.service import async_register_admin_service
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
# Loading the config flow file will register the flow
|
# Loading the config flow file will register the flow
|
||||||
|
@ -78,10 +76,10 @@ from .const import ( # noqa: F401
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
MQTT_CONNECTED,
|
MQTT_CONNECTED,
|
||||||
MQTT_DISCONNECTED,
|
MQTT_DISCONNECTED,
|
||||||
MQTT_RELOADED,
|
|
||||||
PLATFORMS,
|
PLATFORMS,
|
||||||
RELOADABLE_PLATFORMS,
|
RELOADABLE_PLATFORMS,
|
||||||
)
|
)
|
||||||
|
from .mixins import async_discover_yaml_entities
|
||||||
from .models import ( # noqa: F401
|
from .models import ( # noqa: F401
|
||||||
MqttCommandTemplate,
|
MqttCommandTemplate,
|
||||||
MqttValueTemplate,
|
MqttValueTemplate,
|
||||||
|
@ -241,7 +239,9 @@ async def _async_config_entry_updated(hass: HomeAssistant, entry: ConfigEntry) -
|
||||||
await _async_setup_discovery(hass, mqtt_client.conf, entry)
|
await _async_setup_discovery(hass, mqtt_client.conf, entry)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry( # noqa: C901
|
||||||
|
hass: HomeAssistant, entry: ConfigEntry
|
||||||
|
) -> bool:
|
||||||
"""Load a config entry."""
|
"""Load a config entry."""
|
||||||
# Merge basic configuration, and add missing defaults for basic options
|
# Merge basic configuration, and add missing defaults for basic options
|
||||||
_merge_basic_config(hass, entry, hass.data.get(DATA_MQTT_CONFIG, {}))
|
_merge_basic_config(hass, entry, hass.data.get(DATA_MQTT_CONFIG, {}))
|
||||||
|
@ -378,16 +378,32 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
hass.data[DATA_CONFIG_ENTRY_LOCK] = asyncio.Lock()
|
hass.data[DATA_CONFIG_ENTRY_LOCK] = asyncio.Lock()
|
||||||
hass.data[CONFIG_ENTRY_IS_SETUP] = set()
|
hass.data[CONFIG_ENTRY_IS_SETUP] = set()
|
||||||
|
|
||||||
# Setup reload service. Once support for legacy config is removed in 2022.9, we
|
async def async_setup_reload_service() -> None:
|
||||||
# should no longer call async_setup_reload_service but instead implement a custom
|
"""Create the reload service for the MQTT domain."""
|
||||||
# service
|
if hass.services.has_service(DOMAIN, SERVICE_RELOAD):
|
||||||
await async_setup_reload_service(hass, DOMAIN, RELOADABLE_PLATFORMS)
|
return
|
||||||
|
|
||||||
async def _async_reload_platforms(_: Event | None) -> None:
|
async def _reload_config(call: ServiceCall) -> None:
|
||||||
"""Discover entities for a platform."""
|
"""Reload the platforms."""
|
||||||
|
# Reload the legacy yaml platform
|
||||||
|
await async_reload_integration_platforms(hass, DOMAIN, RELOADABLE_PLATFORMS)
|
||||||
|
|
||||||
|
# Reload the modern yaml platforms
|
||||||
config_yaml = await async_integration_yaml_config(hass, DOMAIN) or {}
|
config_yaml = await async_integration_yaml_config(hass, DOMAIN) or {}
|
||||||
hass.data[DATA_MQTT_UPDATED_CONFIG] = config_yaml.get(DOMAIN, {})
|
hass.data[DATA_MQTT_UPDATED_CONFIG] = config_yaml.get(DOMAIN, {})
|
||||||
async_dispatcher_send(hass, MQTT_RELOADED)
|
await asyncio.gather(
|
||||||
|
*(
|
||||||
|
[
|
||||||
|
async_discover_yaml_entities(hass, component)
|
||||||
|
for component in RELOADABLE_PLATFORMS
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Fire event
|
||||||
|
hass.bus.async_fire(f"event_{DOMAIN}_reloaded", context=call.context)
|
||||||
|
|
||||||
|
async_register_admin_service(hass, DOMAIN, SERVICE_RELOAD, _reload_config)
|
||||||
|
|
||||||
async def async_forward_entry_setup_and_setup_discovery(config_entry):
|
async def async_forward_entry_setup_and_setup_discovery(config_entry):
|
||||||
"""Forward the config entry setup to the platforms and set up discovery."""
|
"""Forward the config entry setup to the platforms and set up discovery."""
|
||||||
|
@ -411,11 +427,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
if conf.get(CONF_DISCOVERY):
|
if conf.get(CONF_DISCOVERY):
|
||||||
await _async_setup_discovery(hass, conf, entry)
|
await _async_setup_discovery(hass, conf, entry)
|
||||||
# Setup reload service after all platforms have loaded
|
# Setup reload service after all platforms have loaded
|
||||||
entry.async_on_unload(
|
await async_setup_reload_service()
|
||||||
hass.bus.async_listen("event_mqtt_reloaded", _async_reload_platforms)
|
|
||||||
)
|
|
||||||
|
|
||||||
hass.async_create_task(async_forward_entry_setup_and_setup_discovery(entry))
|
|
||||||
|
|
||||||
if DATA_MQTT_RELOAD_NEEDED in hass.data:
|
if DATA_MQTT_RELOAD_NEEDED in hass.data:
|
||||||
hass.data.pop(DATA_MQTT_RELOAD_NEEDED)
|
hass.data.pop(DATA_MQTT_RELOAD_NEEDED)
|
||||||
|
@ -426,6 +438,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
blocking=False,
|
blocking=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
hass.async_create_task(async_forward_entry_setup_and_setup_discovery(entry))
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,8 @@ from .debug_info import log_messages
|
||||||
from .mixins import (
|
from .mixins import (
|
||||||
MQTT_ENTITY_COMMON_SCHEMA,
|
MQTT_ENTITY_COMMON_SCHEMA,
|
||||||
MqttEntity,
|
MqttEntity,
|
||||||
|
async_discover_yaml_entities,
|
||||||
async_setup_entry_helper,
|
async_setup_entry_helper,
|
||||||
async_setup_platform_discovery,
|
|
||||||
async_setup_platform_helper,
|
async_setup_platform_helper,
|
||||||
warn_for_legacy_schema,
|
warn_for_legacy_schema,
|
||||||
)
|
)
|
||||||
|
@ -147,9 +147,7 @@ async def async_setup_entry(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up MQTT alarm control panel through configuration.yaml and dynamically through MQTT discovery."""
|
"""Set up MQTT alarm control panel through configuration.yaml and dynamically through MQTT discovery."""
|
||||||
# load and initialize platform config from configuration.yaml
|
# load and initialize platform config from configuration.yaml
|
||||||
config_entry.async_on_unload(
|
await async_discover_yaml_entities(hass, alarm.DOMAIN)
|
||||||
await async_setup_platform_discovery(hass, alarm.DOMAIN)
|
|
||||||
)
|
|
||||||
# setup for discovery
|
# setup for discovery
|
||||||
setup = functools.partial(
|
setup = functools.partial(
|
||||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||||
|
|
|
@ -41,8 +41,8 @@ from .mixins import (
|
||||||
MQTT_ENTITY_COMMON_SCHEMA,
|
MQTT_ENTITY_COMMON_SCHEMA,
|
||||||
MqttAvailability,
|
MqttAvailability,
|
||||||
MqttEntity,
|
MqttEntity,
|
||||||
|
async_discover_yaml_entities,
|
||||||
async_setup_entry_helper,
|
async_setup_entry_helper,
|
||||||
async_setup_platform_discovery,
|
|
||||||
async_setup_platform_helper,
|
async_setup_platform_helper,
|
||||||
warn_for_legacy_schema,
|
warn_for_legacy_schema,
|
||||||
)
|
)
|
||||||
|
@ -102,9 +102,7 @@ async def async_setup_entry(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up MQTT binary sensor through configuration.yaml and dynamically through MQTT discovery."""
|
"""Set up MQTT binary sensor through configuration.yaml and dynamically through MQTT discovery."""
|
||||||
# load and initialize platform config from configuration.yaml
|
# load and initialize platform config from configuration.yaml
|
||||||
config_entry.async_on_unload(
|
await async_discover_yaml_entities(hass, binary_sensor.DOMAIN)
|
||||||
await async_setup_platform_discovery(hass, binary_sensor.DOMAIN)
|
|
||||||
)
|
|
||||||
# setup for discovery
|
# setup for discovery
|
||||||
setup = functools.partial(
|
setup = functools.partial(
|
||||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||||
|
|
|
@ -25,8 +25,8 @@ from .const import (
|
||||||
from .mixins import (
|
from .mixins import (
|
||||||
MQTT_ENTITY_COMMON_SCHEMA,
|
MQTT_ENTITY_COMMON_SCHEMA,
|
||||||
MqttEntity,
|
MqttEntity,
|
||||||
|
async_discover_yaml_entities,
|
||||||
async_setup_entry_helper,
|
async_setup_entry_helper,
|
||||||
async_setup_platform_discovery,
|
|
||||||
async_setup_platform_helper,
|
async_setup_platform_helper,
|
||||||
warn_for_legacy_schema,
|
warn_for_legacy_schema,
|
||||||
)
|
)
|
||||||
|
@ -82,9 +82,7 @@ async def async_setup_entry(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up MQTT button through configuration.yaml and dynamically through MQTT discovery."""
|
"""Set up MQTT button through configuration.yaml and dynamically through MQTT discovery."""
|
||||||
# load and initialize platform config from configuration.yaml
|
# load and initialize platform config from configuration.yaml
|
||||||
config_entry.async_on_unload(
|
await async_discover_yaml_entities(hass, button.DOMAIN)
|
||||||
await async_setup_platform_discovery(hass, button.DOMAIN)
|
|
||||||
)
|
|
||||||
# setup for discovery
|
# setup for discovery
|
||||||
setup = functools.partial(
|
setup = functools.partial(
|
||||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||||
|
|
|
@ -22,8 +22,8 @@ from .debug_info import log_messages
|
||||||
from .mixins import (
|
from .mixins import (
|
||||||
MQTT_ENTITY_COMMON_SCHEMA,
|
MQTT_ENTITY_COMMON_SCHEMA,
|
||||||
MqttEntity,
|
MqttEntity,
|
||||||
|
async_discover_yaml_entities,
|
||||||
async_setup_entry_helper,
|
async_setup_entry_helper,
|
||||||
async_setup_platform_discovery,
|
|
||||||
async_setup_platform_helper,
|
async_setup_platform_helper,
|
||||||
warn_for_legacy_schema,
|
warn_for_legacy_schema,
|
||||||
)
|
)
|
||||||
|
@ -80,9 +80,7 @@ async def async_setup_entry(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up MQTT camera through configuration.yaml and dynamically through MQTT discovery."""
|
"""Set up MQTT camera through configuration.yaml and dynamically through MQTT discovery."""
|
||||||
# load and initialize platform config from configuration.yaml
|
# load and initialize platform config from configuration.yaml
|
||||||
config_entry.async_on_unload(
|
await async_discover_yaml_entities(hass, camera.DOMAIN)
|
||||||
await async_setup_platform_discovery(hass, camera.DOMAIN)
|
|
||||||
)
|
|
||||||
# setup for discovery
|
# setup for discovery
|
||||||
setup = functools.partial(
|
setup = functools.partial(
|
||||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||||
|
|
|
@ -50,8 +50,8 @@ from .debug_info import log_messages
|
||||||
from .mixins import (
|
from .mixins import (
|
||||||
MQTT_ENTITY_COMMON_SCHEMA,
|
MQTT_ENTITY_COMMON_SCHEMA,
|
||||||
MqttEntity,
|
MqttEntity,
|
||||||
|
async_discover_yaml_entities,
|
||||||
async_setup_entry_helper,
|
async_setup_entry_helper,
|
||||||
async_setup_platform_discovery,
|
|
||||||
async_setup_platform_helper,
|
async_setup_platform_helper,
|
||||||
warn_for_legacy_schema,
|
warn_for_legacy_schema,
|
||||||
)
|
)
|
||||||
|
@ -391,9 +391,7 @@ async def async_setup_entry(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up MQTT climate device through configuration.yaml and dynamically through MQTT discovery."""
|
"""Set up MQTT climate device through configuration.yaml and dynamically through MQTT discovery."""
|
||||||
# load and initialize platform config from configuration.yaml
|
# load and initialize platform config from configuration.yaml
|
||||||
config_entry.async_on_unload(
|
await async_discover_yaml_entities(hass, climate.DOMAIN)
|
||||||
await async_setup_platform_discovery(hass, climate.DOMAIN)
|
|
||||||
)
|
|
||||||
# setup for discovery
|
# setup for discovery
|
||||||
setup = functools.partial(
|
setup = functools.partial(
|
||||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||||
|
|
|
@ -64,7 +64,6 @@ DOMAIN = "mqtt"
|
||||||
|
|
||||||
MQTT_CONNECTED = "mqtt_connected"
|
MQTT_CONNECTED = "mqtt_connected"
|
||||||
MQTT_DISCONNECTED = "mqtt_disconnected"
|
MQTT_DISCONNECTED = "mqtt_disconnected"
|
||||||
MQTT_RELOADED = "mqtt_reloaded"
|
|
||||||
|
|
||||||
PAYLOAD_EMPTY_JSON = "{}"
|
PAYLOAD_EMPTY_JSON = "{}"
|
||||||
PAYLOAD_NONE = "None"
|
PAYLOAD_NONE = "None"
|
||||||
|
@ -105,8 +104,8 @@ RELOADABLE_PLATFORMS = [
|
||||||
Platform.LIGHT,
|
Platform.LIGHT,
|
||||||
Platform.LOCK,
|
Platform.LOCK,
|
||||||
Platform.NUMBER,
|
Platform.NUMBER,
|
||||||
Platform.SELECT,
|
|
||||||
Platform.SCENE,
|
Platform.SCENE,
|
||||||
|
Platform.SELECT,
|
||||||
Platform.SENSOR,
|
Platform.SENSOR,
|
||||||
Platform.SIREN,
|
Platform.SIREN,
|
||||||
Platform.SWITCH,
|
Platform.SWITCH,
|
||||||
|
|
|
@ -46,8 +46,8 @@ from .debug_info import log_messages
|
||||||
from .mixins import (
|
from .mixins import (
|
||||||
MQTT_ENTITY_COMMON_SCHEMA,
|
MQTT_ENTITY_COMMON_SCHEMA,
|
||||||
MqttEntity,
|
MqttEntity,
|
||||||
|
async_discover_yaml_entities,
|
||||||
async_setup_entry_helper,
|
async_setup_entry_helper,
|
||||||
async_setup_platform_discovery,
|
|
||||||
async_setup_platform_helper,
|
async_setup_platform_helper,
|
||||||
warn_for_legacy_schema,
|
warn_for_legacy_schema,
|
||||||
)
|
)
|
||||||
|
@ -242,9 +242,7 @@ async def async_setup_entry(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up MQTT cover through configuration.yaml and dynamically through MQTT discovery."""
|
"""Set up MQTT cover through configuration.yaml and dynamically through MQTT discovery."""
|
||||||
# load and initialize platform config from configuration.yaml
|
# load and initialize platform config from configuration.yaml
|
||||||
config_entry.async_on_unload(
|
await async_discover_yaml_entities(hass, cover.DOMAIN)
|
||||||
await async_setup_platform_discovery(hass, cover.DOMAIN)
|
|
||||||
)
|
|
||||||
# setup for discovery
|
# setup for discovery
|
||||||
setup = functools.partial(
|
setup = functools.partial(
|
||||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||||
|
|
|
@ -50,8 +50,8 @@ from .debug_info import log_messages
|
||||||
from .mixins import (
|
from .mixins import (
|
||||||
MQTT_ENTITY_COMMON_SCHEMA,
|
MQTT_ENTITY_COMMON_SCHEMA,
|
||||||
MqttEntity,
|
MqttEntity,
|
||||||
|
async_discover_yaml_entities,
|
||||||
async_setup_entry_helper,
|
async_setup_entry_helper,
|
||||||
async_setup_platform_discovery,
|
|
||||||
async_setup_platform_helper,
|
async_setup_platform_helper,
|
||||||
warn_for_legacy_schema,
|
warn_for_legacy_schema,
|
||||||
)
|
)
|
||||||
|
@ -232,7 +232,7 @@ async def async_setup_entry(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up MQTT fan through configuration.yaml and dynamically through MQTT discovery."""
|
"""Set up MQTT fan through configuration.yaml and dynamically through MQTT discovery."""
|
||||||
# load and initialize platform config from configuration.yaml
|
# load and initialize platform config from configuration.yaml
|
||||||
config_entry.async_on_unload(await async_setup_platform_discovery(hass, fan.DOMAIN))
|
await async_discover_yaml_entities(hass, fan.DOMAIN)
|
||||||
# setup for discovery
|
# setup for discovery
|
||||||
setup = functools.partial(
|
setup = functools.partial(
|
||||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||||
|
|
|
@ -45,8 +45,8 @@ from .debug_info import log_messages
|
||||||
from .mixins import (
|
from .mixins import (
|
||||||
MQTT_ENTITY_COMMON_SCHEMA,
|
MQTT_ENTITY_COMMON_SCHEMA,
|
||||||
MqttEntity,
|
MqttEntity,
|
||||||
|
async_discover_yaml_entities,
|
||||||
async_setup_entry_helper,
|
async_setup_entry_helper,
|
||||||
async_setup_platform_discovery,
|
|
||||||
async_setup_platform_helper,
|
async_setup_platform_helper,
|
||||||
warn_for_legacy_schema,
|
warn_for_legacy_schema,
|
||||||
)
|
)
|
||||||
|
@ -187,9 +187,7 @@ async def async_setup_entry(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up MQTT humidifier through configuration.yaml and dynamically through MQTT discovery."""
|
"""Set up MQTT humidifier through configuration.yaml and dynamically through MQTT discovery."""
|
||||||
# load and initialize platform config from configuration.yaml
|
# load and initialize platform config from configuration.yaml
|
||||||
config_entry.async_on_unload(
|
await async_discover_yaml_entities(hass, humidifier.DOMAIN)
|
||||||
await async_setup_platform_discovery(hass, humidifier.DOMAIN)
|
|
||||||
)
|
|
||||||
# setup for discovery
|
# setup for discovery
|
||||||
setup = functools.partial(
|
setup = functools.partial(
|
||||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||||
|
|
|
@ -13,8 +13,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from ..mixins import (
|
from ..mixins import (
|
||||||
|
async_discover_yaml_entities,
|
||||||
async_setup_entry_helper,
|
async_setup_entry_helper,
|
||||||
async_setup_platform_discovery,
|
|
||||||
async_setup_platform_helper,
|
async_setup_platform_helper,
|
||||||
warn_for_legacy_schema,
|
warn_for_legacy_schema,
|
||||||
)
|
)
|
||||||
|
@ -111,9 +111,7 @@ async def async_setup_entry(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up MQTT lights configured under the light platform key (deprecated)."""
|
"""Set up MQTT lights configured under the light platform key (deprecated)."""
|
||||||
# load and initialize platform config from configuration.yaml
|
# load and initialize platform config from configuration.yaml
|
||||||
config_entry.async_on_unload(
|
await async_discover_yaml_entities(hass, light.DOMAIN)
|
||||||
await async_setup_platform_discovery(hass, light.DOMAIN)
|
|
||||||
)
|
|
||||||
# setup for discovery
|
# setup for discovery
|
||||||
setup = functools.partial(
|
setup = functools.partial(
|
||||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||||
|
|
|
@ -28,8 +28,8 @@ from .debug_info import log_messages
|
||||||
from .mixins import (
|
from .mixins import (
|
||||||
MQTT_ENTITY_COMMON_SCHEMA,
|
MQTT_ENTITY_COMMON_SCHEMA,
|
||||||
MqttEntity,
|
MqttEntity,
|
||||||
|
async_discover_yaml_entities,
|
||||||
async_setup_entry_helper,
|
async_setup_entry_helper,
|
||||||
async_setup_platform_discovery,
|
|
||||||
async_setup_platform_helper,
|
async_setup_platform_helper,
|
||||||
warn_for_legacy_schema,
|
warn_for_legacy_schema,
|
||||||
)
|
)
|
||||||
|
@ -103,9 +103,7 @@ async def async_setup_entry(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up MQTT lock through configuration.yaml and dynamically through MQTT discovery."""
|
"""Set up MQTT lock through configuration.yaml and dynamically through MQTT discovery."""
|
||||||
# load and initialize platform config from configuration.yaml
|
# load and initialize platform config from configuration.yaml
|
||||||
config_entry.async_on_unload(
|
await async_discover_yaml_entities(hass, lock.DOMAIN)
|
||||||
await async_setup_platform_discovery(hass, lock.DOMAIN)
|
|
||||||
)
|
|
||||||
# setup for discovery
|
# setup for discovery
|
||||||
setup = functools.partial(
|
setup = functools.partial(
|
||||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||||
|
|
|
@ -26,7 +26,7 @@ from homeassistant.const import (
|
||||||
CONF_UNIQUE_ID,
|
CONF_UNIQUE_ID,
|
||||||
CONF_VALUE_TEMPLATE,
|
CONF_VALUE_TEMPLATE,
|
||||||
)
|
)
|
||||||
from homeassistant.core import CALLBACK_TYPE, Event, HomeAssistant, callback
|
from homeassistant.core import Event, HomeAssistant, callback
|
||||||
from homeassistant.helpers import (
|
from homeassistant.helpers import (
|
||||||
config_validation as cv,
|
config_validation as cv,
|
||||||
device_registry as dr,
|
device_registry as dr,
|
||||||
|
@ -69,7 +69,6 @@ from .const import (
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
MQTT_CONNECTED,
|
MQTT_CONNECTED,
|
||||||
MQTT_DISCONNECTED,
|
MQTT_DISCONNECTED,
|
||||||
MQTT_RELOADED,
|
|
||||||
)
|
)
|
||||||
from .debug_info import log_message, log_messages
|
from .debug_info import log_message, log_messages
|
||||||
from .discovery import (
|
from .discovery import (
|
||||||
|
@ -261,12 +260,9 @@ class SetupEntity(Protocol):
|
||||||
"""Define setup_entities type."""
|
"""Define setup_entities type."""
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform_discovery(
|
async def async_discover_yaml_entities(
|
||||||
hass: HomeAssistant, platform_domain: str
|
hass: HomeAssistant, platform_domain: str
|
||||||
) -> CALLBACK_TYPE:
|
) -> None:
|
||||||
"""Set up platform discovery for manual config."""
|
|
||||||
|
|
||||||
async def _async_discover_entities() -> None:
|
|
||||||
"""Discover entities for a platform."""
|
"""Discover entities for a platform."""
|
||||||
if DATA_MQTT_UPDATED_CONFIG in hass.data:
|
if DATA_MQTT_UPDATED_CONFIG in hass.data:
|
||||||
# The platform has been reloaded
|
# The platform has been reloaded
|
||||||
|
@ -286,10 +282,6 @@ async def async_setup_platform_discovery(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
unsub = async_dispatcher_connect(hass, MQTT_RELOADED, _async_discover_entities)
|
|
||||||
await _async_discover_entities()
|
|
||||||
return unsub
|
|
||||||
|
|
||||||
|
|
||||||
async def async_get_platform_config_from_yaml(
|
async def async_get_platform_config_from_yaml(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
|
|
@ -41,8 +41,8 @@ from .debug_info import log_messages
|
||||||
from .mixins import (
|
from .mixins import (
|
||||||
MQTT_ENTITY_COMMON_SCHEMA,
|
MQTT_ENTITY_COMMON_SCHEMA,
|
||||||
MqttEntity,
|
MqttEntity,
|
||||||
|
async_discover_yaml_entities,
|
||||||
async_setup_entry_helper,
|
async_setup_entry_helper,
|
||||||
async_setup_platform_discovery,
|
|
||||||
async_setup_platform_helper,
|
async_setup_platform_helper,
|
||||||
warn_for_legacy_schema,
|
warn_for_legacy_schema,
|
||||||
)
|
)
|
||||||
|
@ -135,9 +135,7 @@ async def async_setup_entry(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up MQTT number through configuration.yaml and dynamically through MQTT discovery."""
|
"""Set up MQTT number through configuration.yaml and dynamically through MQTT discovery."""
|
||||||
# load and initialize platform config from configuration.yaml
|
# load and initialize platform config from configuration.yaml
|
||||||
config_entry.async_on_unload(
|
await async_discover_yaml_entities(hass, number.DOMAIN)
|
||||||
await async_setup_platform_discovery(hass, number.DOMAIN)
|
|
||||||
)
|
|
||||||
# setup for discovery
|
# setup for discovery
|
||||||
setup = functools.partial(
|
setup = functools.partial(
|
||||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||||
|
|
|
@ -22,8 +22,8 @@ from .mixins import (
|
||||||
CONF_OBJECT_ID,
|
CONF_OBJECT_ID,
|
||||||
MQTT_AVAILABILITY_SCHEMA,
|
MQTT_AVAILABILITY_SCHEMA,
|
||||||
MqttEntity,
|
MqttEntity,
|
||||||
|
async_discover_yaml_entities,
|
||||||
async_setup_entry_helper,
|
async_setup_entry_helper,
|
||||||
async_setup_platform_discovery,
|
|
||||||
async_setup_platform_helper,
|
async_setup_platform_helper,
|
||||||
warn_for_legacy_schema,
|
warn_for_legacy_schema,
|
||||||
)
|
)
|
||||||
|
@ -79,9 +79,7 @@ async def async_setup_entry(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up MQTT scene through configuration.yaml and dynamically through MQTT discovery."""
|
"""Set up MQTT scene through configuration.yaml and dynamically through MQTT discovery."""
|
||||||
# load and initialize platform config from configuration.yaml
|
# load and initialize platform config from configuration.yaml
|
||||||
config_entry.async_on_unload(
|
await async_discover_yaml_entities(hass, scene.DOMAIN)
|
||||||
await async_setup_platform_discovery(hass, scene.DOMAIN)
|
|
||||||
)
|
|
||||||
# setup for discovery
|
# setup for discovery
|
||||||
setup = functools.partial(
|
setup = functools.partial(
|
||||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||||
|
|
|
@ -30,8 +30,8 @@ from .debug_info import log_messages
|
||||||
from .mixins import (
|
from .mixins import (
|
||||||
MQTT_ENTITY_COMMON_SCHEMA,
|
MQTT_ENTITY_COMMON_SCHEMA,
|
||||||
MqttEntity,
|
MqttEntity,
|
||||||
|
async_discover_yaml_entities,
|
||||||
async_setup_entry_helper,
|
async_setup_entry_helper,
|
||||||
async_setup_platform_discovery,
|
|
||||||
async_setup_platform_helper,
|
async_setup_platform_helper,
|
||||||
warn_for_legacy_schema,
|
warn_for_legacy_schema,
|
||||||
)
|
)
|
||||||
|
@ -94,9 +94,7 @@ async def async_setup_entry(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up MQTT select through configuration.yaml and dynamically through MQTT discovery."""
|
"""Set up MQTT select through configuration.yaml and dynamically through MQTT discovery."""
|
||||||
# load and initialize platform config from configuration.yaml
|
# load and initialize platform config from configuration.yaml
|
||||||
config_entry.async_on_unload(
|
await async_discover_yaml_entities(hass, select.DOMAIN)
|
||||||
await async_setup_platform_discovery(hass, select.DOMAIN)
|
|
||||||
)
|
|
||||||
# setup for discovery
|
# setup for discovery
|
||||||
setup = functools.partial(
|
setup = functools.partial(
|
||||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||||
|
|
|
@ -41,8 +41,8 @@ from .mixins import (
|
||||||
MQTT_ENTITY_COMMON_SCHEMA,
|
MQTT_ENTITY_COMMON_SCHEMA,
|
||||||
MqttAvailability,
|
MqttAvailability,
|
||||||
MqttEntity,
|
MqttEntity,
|
||||||
|
async_discover_yaml_entities,
|
||||||
async_setup_entry_helper,
|
async_setup_entry_helper,
|
||||||
async_setup_platform_discovery,
|
|
||||||
async_setup_platform_helper,
|
async_setup_platform_helper,
|
||||||
warn_for_legacy_schema,
|
warn_for_legacy_schema,
|
||||||
)
|
)
|
||||||
|
@ -147,9 +147,7 @@ async def async_setup_entry(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up MQTT sensor through configuration.yaml and dynamically through MQTT discovery."""
|
"""Set up MQTT sensor through configuration.yaml and dynamically through MQTT discovery."""
|
||||||
# load and initialize platform config from configuration.yaml
|
# load and initialize platform config from configuration.yaml
|
||||||
config_entry.async_on_unload(
|
await async_discover_yaml_entities(hass, sensor.DOMAIN)
|
||||||
await async_setup_platform_discovery(hass, sensor.DOMAIN)
|
|
||||||
)
|
|
||||||
# setup for discovery
|
# setup for discovery
|
||||||
setup = functools.partial(
|
setup = functools.partial(
|
||||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||||
|
|
|
@ -51,8 +51,8 @@ from .debug_info import log_messages
|
||||||
from .mixins import (
|
from .mixins import (
|
||||||
MQTT_ENTITY_COMMON_SCHEMA,
|
MQTT_ENTITY_COMMON_SCHEMA,
|
||||||
MqttEntity,
|
MqttEntity,
|
||||||
|
async_discover_yaml_entities,
|
||||||
async_setup_entry_helper,
|
async_setup_entry_helper,
|
||||||
async_setup_platform_discovery,
|
|
||||||
async_setup_platform_helper,
|
async_setup_platform_helper,
|
||||||
warn_for_legacy_schema,
|
warn_for_legacy_schema,
|
||||||
)
|
)
|
||||||
|
@ -143,9 +143,7 @@ async def async_setup_entry(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up MQTT siren through configuration.yaml and dynamically through MQTT discovery."""
|
"""Set up MQTT siren through configuration.yaml and dynamically through MQTT discovery."""
|
||||||
# load and initialize platform config from configuration.yaml
|
# load and initialize platform config from configuration.yaml
|
||||||
config_entry.async_on_unload(
|
await async_discover_yaml_entities(hass, siren.DOMAIN)
|
||||||
await async_setup_platform_discovery(hass, siren.DOMAIN)
|
|
||||||
)
|
|
||||||
# setup for discovery
|
# setup for discovery
|
||||||
setup = functools.partial(
|
setup = functools.partial(
|
||||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||||
|
|
|
@ -37,8 +37,8 @@ from .debug_info import log_messages
|
||||||
from .mixins import (
|
from .mixins import (
|
||||||
MQTT_ENTITY_COMMON_SCHEMA,
|
MQTT_ENTITY_COMMON_SCHEMA,
|
||||||
MqttEntity,
|
MqttEntity,
|
||||||
|
async_discover_yaml_entities,
|
||||||
async_setup_entry_helper,
|
async_setup_entry_helper,
|
||||||
async_setup_platform_discovery,
|
|
||||||
async_setup_platform_helper,
|
async_setup_platform_helper,
|
||||||
warn_for_legacy_schema,
|
warn_for_legacy_schema,
|
||||||
)
|
)
|
||||||
|
@ -97,9 +97,7 @@ async def async_setup_entry(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up MQTT switch through configuration.yaml and dynamically through MQTT discovery."""
|
"""Set up MQTT switch through configuration.yaml and dynamically through MQTT discovery."""
|
||||||
# load and initialize platform config from configuration.yaml
|
# load and initialize platform config from configuration.yaml
|
||||||
config_entry.async_on_unload(
|
await async_discover_yaml_entities(hass, switch.DOMAIN)
|
||||||
await async_setup_platform_discovery(hass, switch.DOMAIN)
|
|
||||||
)
|
|
||||||
# setup for discovery
|
# setup for discovery
|
||||||
setup = functools.partial(
|
setup = functools.partial(
|
||||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||||
|
|
|
@ -12,8 +12,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from ..mixins import (
|
from ..mixins import (
|
||||||
|
async_discover_yaml_entities,
|
||||||
async_setup_entry_helper,
|
async_setup_entry_helper,
|
||||||
async_setup_platform_discovery,
|
|
||||||
async_setup_platform_helper,
|
async_setup_platform_helper,
|
||||||
)
|
)
|
||||||
from .schema import CONF_SCHEMA, LEGACY, MQTT_VACUUM_SCHEMA, STATE
|
from .schema import CONF_SCHEMA, LEGACY, MQTT_VACUUM_SCHEMA, STATE
|
||||||
|
@ -91,9 +91,7 @@ async def async_setup_entry(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up MQTT vacuum through configuration.yaml and dynamically through MQTT discovery."""
|
"""Set up MQTT vacuum through configuration.yaml and dynamically through MQTT discovery."""
|
||||||
# load and initialize platform config from configuration.yaml
|
# load and initialize platform config from configuration.yaml
|
||||||
config_entry.async_on_unload(
|
await async_discover_yaml_entities(hass, vacuum.DOMAIN)
|
||||||
await async_setup_platform_discovery(hass, vacuum.DOMAIN)
|
|
||||||
)
|
|
||||||
# setup for discovery
|
# setup for discovery
|
||||||
setup = functools.partial(
|
setup = functools.partial(
|
||||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue