Remove legacy YAML support from MQTT (#82102)

This commit is contained in:
Jan Bouwhuis 2022-11-17 22:55:31 +01:00 committed by GitHub
parent f82c4c7633
commit 7c2e7863d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
46 changed files with 54 additions and 1613 deletions

View File

@ -192,7 +192,7 @@ async def _async_setup_discovery(
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Start the MQTT protocol service."""
"""Set up the MQTT protocol service."""
mqtt_data = get_mqtt_data(hass, True)
conf: ConfigType | None = config.get(DOMAIN)
@ -464,9 +464,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def _reload_config(call: ServiceCall) -> None:
"""Reload the platforms."""
# Reload the legacy yaml platform
await async_reload_integration_platforms(hass, DOMAIN, RELOADABLE_PLATFORMS)
# Reload the modern yaml platforms
mqtt_platforms = async_get_platforms(hass, DOMAIN)
tasks = [

View File

@ -45,7 +45,6 @@ from .mixins import (
MQTT_ENTITY_COMMON_SCHEMA,
MqttEntity,
async_setup_entry_helper,
async_setup_platform_helper,
warn_for_legacy_schema,
)
from .models import MqttCommandTemplate, MqttValueTemplate, ReceiveMessage
@ -114,31 +113,14 @@ PLATFORM_SCHEMA_MODERN = MQTT_BASE_SCHEMA.extend(
).extend(MQTT_ENTITY_COMMON_SCHEMA.schema)
# Configuring MQTT alarm control panels under the alarm_control_panel platform key is deprecated in HA Core 2022.6
# Setup for the legacy YAML format was removed in HA Core 2022.12
PLATFORM_SCHEMA = vol.All(
cv.PLATFORM_SCHEMA.extend(PLATFORM_SCHEMA_MODERN.schema),
warn_for_legacy_schema(alarm.DOMAIN),
)
DISCOVERY_SCHEMA = PLATFORM_SCHEMA_MODERN.extend({}, extra=vol.REMOVE_EXTRA)
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up MQTT alarm control panel configured under the alarm_control_panel key (deprecated)."""
# Deprecated in HA Core 2022.6
await async_setup_platform_helper(
hass,
alarm.DOMAIN,
discovery_info or config,
async_add_entities,
_async_setup_entity,
)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,

View File

@ -43,7 +43,6 @@ from .mixins import (
MqttAvailability,
MqttEntity,
async_setup_entry_helper,
async_setup_platform_helper,
warn_for_legacy_schema,
)
from .models import MqttValueTemplate, ReceiveMessage
@ -71,31 +70,14 @@ PLATFORM_SCHEMA_MODERN = MQTT_RO_SCHEMA.extend(
).extend(MQTT_ENTITY_COMMON_SCHEMA.schema)
# Configuring MQTT Binary sensors under the binary_sensor platform key is deprecated in HA Core 2022.6
# Setup for the legacy YAML format was removed in HA Core 2022.12
PLATFORM_SCHEMA = vol.All(
cv.PLATFORM_SCHEMA.extend(PLATFORM_SCHEMA_MODERN.schema),
warn_for_legacy_schema(binary_sensor.DOMAIN),
)
DISCOVERY_SCHEMA = PLATFORM_SCHEMA_MODERN.extend({}, extra=vol.REMOVE_EXTRA)
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up MQTT binary sensor configured under the fan platform key (deprecated)."""
# Deprecated in HA Core 2022.6
await async_setup_platform_helper(
hass,
binary_sensor.DOMAIN,
discovery_info or config,
async_add_entities,
_async_setup_entity,
)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,

View File

@ -26,7 +26,6 @@ from .mixins import (
MQTT_ENTITY_COMMON_SCHEMA,
MqttEntity,
async_setup_entry_helper,
async_setup_platform_helper,
warn_for_legacy_schema,
)
from .models import MqttCommandTemplate
@ -48,8 +47,8 @@ PLATFORM_SCHEMA_MODERN = MQTT_BASE_SCHEMA.extend(
).extend(MQTT_ENTITY_COMMON_SCHEMA.schema)
# Configuring MQTT Buttons under the button platform key is deprecated in HA Core 2022.6
# Setup for the legacy YAML format was removed in HA Core 2022.12
PLATFORM_SCHEMA = vol.All(
cv.PLATFORM_SCHEMA.extend(PLATFORM_SCHEMA_MODERN.schema),
warn_for_legacy_schema(button.DOMAIN),
)
@ -57,23 +56,6 @@ PLATFORM_SCHEMA = vol.All(
DISCOVERY_SCHEMA = PLATFORM_SCHEMA_MODERN.extend({}, extra=vol.REMOVE_EXTRA)
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up MQTT button configured under the fan platform key (deprecated)."""
# Deprecated in HA Core 2022.6
await async_setup_platform_helper(
hass,
button.DOMAIN,
discovery_info or config,
async_add_entities,
_async_setup_entity,
)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,

View File

@ -24,7 +24,6 @@ from .mixins import (
MQTT_ENTITY_COMMON_SCHEMA,
MqttEntity,
async_setup_entry_helper,
async_setup_platform_helper,
warn_for_legacy_schema,
)
from .models import ReceiveMessage
@ -58,31 +57,14 @@ PLATFORM_SCHEMA_MODERN = vol.All(
)
# Configuring MQTT Camera under the camera platform key is deprecated in HA Core 2022.6
# Setup for the legacy YAML format was removed in HA Core 2022.12
PLATFORM_SCHEMA = vol.All(
cv.PLATFORM_SCHEMA.extend(PLATFORM_SCHEMA_BASE.schema),
warn_for_legacy_schema(camera.DOMAIN),
)
DISCOVERY_SCHEMA = PLATFORM_SCHEMA_BASE.extend({}, extra=vol.REMOVE_EXTRA)
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up MQTT camera configured under the camera platform key (deprecated)."""
# Deprecated in HA Core 2022.6
await async_setup_platform_helper(
hass,
camera.DOMAIN,
discovery_info or config,
async_add_entities,
_async_setup_entity,
)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,

View File

@ -53,7 +53,6 @@ from .mixins import (
MQTT_ENTITY_COMMON_SCHEMA,
MqttEntity,
async_setup_entry_helper,
async_setup_platform_helper,
warn_for_legacy_schema,
)
from .models import (
@ -309,9 +308,8 @@ PLATFORM_SCHEMA_MODERN = vol.All(
)
# Configuring MQTT Climate under the climate platform key is deprecated in HA Core 2022.6
# Setup for the legacy YAML format was removed in HA Core 2022.12
PLATFORM_SCHEMA = vol.All(
cv.PLATFORM_SCHEMA.extend(_PLATFORM_SCHEMA_BASE.schema),
valid_preset_mode_configuration,
warn_for_legacy_schema(climate.DOMAIN),
)
@ -334,23 +332,6 @@ DISCOVERY_SCHEMA = vol.All(
)
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up MQTT climate configured under the fan platform key (deprecated)."""
# The use of PLATFORM_SCHEMA is deprecated in HA Core 2022.6
await async_setup_platform_helper(
hass,
climate.DOMAIN,
discovery_info or config,
async_add_entities,
_async_setup_entity,
)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,

View File

@ -32,7 +32,6 @@ CONF_TLS_INSECURE = "tls_insecure"
CONF_TLS_VERSION = "tls_version"
DATA_MQTT = "mqtt"
MQTT_DATA_DEVICE_TRACKER_LEGACY = "mqtt_device_tracker_legacy"
DEFAULT_PREFIX = "homeassistant"
DEFAULT_BIRTH_WILL_TOPIC = DEFAULT_PREFIX + "/status"

View File

@ -48,7 +48,6 @@ from .mixins import (
MQTT_ENTITY_COMMON_SCHEMA,
MqttEntity,
async_setup_entry_helper,
async_setup_platform_helper,
warn_for_legacy_schema,
)
from .models import MqttCommandTemplate, MqttValueTemplate, ReceiveMessage
@ -206,9 +205,8 @@ PLATFORM_SCHEMA_MODERN = vol.All(
)
# Configuring MQTT Covers under the cover platform key is deprecated in HA Core 2022.6
# Setup for the legacy YAML format was removed in HA Core 2022.12
PLATFORM_SCHEMA = vol.All(
cv.PLATFORM_SCHEMA.extend(_PLATFORM_SCHEMA_BASE.schema),
validate_options,
warn_for_legacy_schema(cover.DOMAIN),
)
@ -219,23 +217,6 @@ DISCOVERY_SCHEMA = vol.All(
)
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up MQTT covers configured under the fan platform key (deprecated)."""
# Deprecated in HA Core 2022.6
await async_setup_platform_helper(
hass,
cover.DOMAIN,
discovery_info or config,
async_add_entities,
_async_setup_entity,
)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,

View File

@ -6,23 +6,15 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from ..const import MQTT_DATA_DEVICE_TRACKER_LEGACY
from ..mixins import warn_for_legacy_schema
from .schema_discovery import PLATFORM_SCHEMA_MODERN # noqa: F401
from .schema_discovery import async_setup_entry_from_discovery
from .schema_yaml import (
PLATFORM_SCHEMA_YAML,
MQTTLegacyDeviceTrackerData,
async_setup_scanner_from_yaml,
from .schema_discovery import ( # noqa: F401
PLATFORM_SCHEMA_MODERN,
async_setup_entry_from_discovery,
)
# Configuring MQTT Device Trackers under the device_tracker platform key is deprecated in HA Core 2022.6
PLATFORM_SCHEMA = vol.All(
PLATFORM_SCHEMA_YAML, warn_for_legacy_schema(device_tracker.DOMAIN)
)
# Legacy setup
async_setup_scanner = async_setup_scanner_from_yaml
# Setup for the legacy YAML format was removed in HA Core 2022.12
PLATFORM_SCHEMA = vol.All(warn_for_legacy_schema(device_tracker.DOMAIN))
async def async_setup_entry(
@ -32,13 +24,3 @@ async def async_setup_entry(
) -> None:
"""Set up MQTT device_tracker through configuration.yaml and dynamically through MQTT discovery."""
await async_setup_entry_from_discovery(hass, config_entry, async_add_entities)
# (re)load legacy service
if MQTT_DATA_DEVICE_TRACKER_LEGACY in hass.data:
yaml_device_tracker_data: MQTTLegacyDeviceTrackerData = hass.data[
MQTT_DATA_DEVICE_TRACKER_LEGACY
]
await async_setup_scanner_from_yaml(
hass,
config=yaml_device_tracker_data.config,
async_see=yaml_device_tracker_data.async_see,
)

View File

@ -1,111 +0,0 @@
"""Support for tracking MQTT enabled devices defined in YAML."""
from __future__ import annotations
from collections.abc import Callable, Coroutine
import dataclasses
import logging
from typing import Any
import voluptuous as vol
from homeassistant.components.device_tracker import (
PLATFORM_SCHEMA,
SOURCE_TYPES,
AsyncSeeCallback,
SourceType,
)
from homeassistant.const import CONF_DEVICES, STATE_HOME, STATE_NOT_HOME
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from ... import mqtt
from ..client import async_subscribe
from ..config import SCHEMA_BASE
from ..const import CONF_QOS, MQTT_DATA_DEVICE_TRACKER_LEGACY
from ..models import ReceiveMessage
from ..util import mqtt_config_entry_enabled, valid_subscribe_topic
_LOGGER = logging.getLogger(__name__)
CONF_PAYLOAD_HOME = "payload_home"
CONF_PAYLOAD_NOT_HOME = "payload_not_home"
CONF_SOURCE_TYPE = "source_type"
PLATFORM_SCHEMA_YAML = PLATFORM_SCHEMA.extend(SCHEMA_BASE).extend(
{
vol.Required(CONF_DEVICES): {cv.string: valid_subscribe_topic},
vol.Optional(CONF_PAYLOAD_HOME, default=STATE_HOME): cv.string,
vol.Optional(CONF_PAYLOAD_NOT_HOME, default=STATE_NOT_HOME): cv.string,
vol.Optional(CONF_SOURCE_TYPE): vol.In(SOURCE_TYPES),
}
)
@dataclasses.dataclass
class MQTTLegacyDeviceTrackerData:
"""Class to hold device tracker data."""
async_see: Callable[..., Coroutine[Any, Any, None]]
config: ConfigType
async def async_setup_scanner_from_yaml(
hass: HomeAssistant,
config: ConfigType,
async_see: AsyncSeeCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> bool:
"""Set up the MQTT tracker."""
devices: dict[str, str] = config[CONF_DEVICES]
qos: int = config[CONF_QOS]
payload_home: str = config[CONF_PAYLOAD_HOME]
payload_not_home: str = config[CONF_PAYLOAD_NOT_HOME]
source_type: SourceType | str | None = config.get(CONF_SOURCE_TYPE)
config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
subscriptions: list[Callable] = []
hass.data[MQTT_DATA_DEVICE_TRACKER_LEGACY] = MQTTLegacyDeviceTrackerData(
async_see, config
)
if not mqtt_config_entry_enabled(hass):
_LOGGER.info(
"MQTT device trackers will be not available until the config entry is enabled",
)
return False
@callback
def _entry_unload(*_: Any) -> None:
"""Handle the unload of the config entry."""
# Unsubscribe from mqtt
for unsubscribe in subscriptions:
unsubscribe()
for dev_id, topic in devices.items():
@callback
def async_message_received(msg: ReceiveMessage, dev_id: str = dev_id) -> None:
"""Handle received MQTT message."""
if msg.payload == payload_home:
location_name = STATE_HOME
elif msg.payload == payload_not_home:
location_name = STATE_NOT_HOME
else:
location_name = str(msg.payload)
see_args: dict[str, Any] = {
"dev_id": dev_id,
"location_name": location_name,
}
if source_type:
see_args["source_type"] = source_type
hass.async_create_task(async_see(**see_args))
subscriptions.append(
await async_subscribe(hass, topic, async_message_received, qos)
)
config_entry.async_on_unload(_entry_unload)
return True

View File

@ -53,7 +53,6 @@ from .mixins import (
MQTT_ENTITY_COMMON_SCHEMA,
MqttEntity,
async_setup_entry_helper,
async_setup_platform_helper,
warn_for_legacy_schema,
)
from .models import (
@ -185,10 +184,8 @@ _PLATFORM_SCHEMA_BASE = MQTT_RW_SCHEMA.extend(
).extend(MQTT_ENTITY_COMMON_SCHEMA.schema)
# Configuring MQTT Fans under the fan platform key is deprecated in HA Core 2022.6
# Setup for the legacy YAML format was removed in HA Core 2022.12
PLATFORM_SCHEMA = vol.All(
cv.PLATFORM_SCHEMA.extend(_PLATFORM_SCHEMA_BASE.schema),
valid_speed_range_configuration,
valid_preset_mode_configuration,
warn_for_legacy_schema(fan.DOMAIN),
)
@ -225,23 +222,6 @@ DISCOVERY_SCHEMA = vol.All(
)
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up MQTT fans configured under the fan platform key (deprecated)."""
# Deprecated in HA Core 2022.6
await async_setup_platform_helper(
hass,
fan.DOMAIN,
discovery_info or config,
async_add_entities,
_async_setup_entity,
)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,

View File

@ -49,7 +49,6 @@ from .mixins import (
MQTT_ENTITY_COMMON_SCHEMA,
MqttEntity,
async_setup_entry_helper,
async_setup_platform_helper,
warn_for_legacy_schema,
)
from .models import (
@ -151,10 +150,8 @@ _PLATFORM_SCHEMA_BASE = MQTT_RW_SCHEMA.extend(
).extend(MQTT_ENTITY_COMMON_SCHEMA.schema)
# Configuring MQTT Humidifiers under the humidifier platform key is deprecated in HA Core 2022.6
# Setup for the legacy YAML format was removed in HA Core 2022.12
PLATFORM_SCHEMA = vol.All(
cv.PLATFORM_SCHEMA.extend(_PLATFORM_SCHEMA_BASE.schema),
valid_humidity_range_configuration,
valid_mode_configuration,
warn_for_legacy_schema(humidifier.DOMAIN),
)
@ -171,23 +168,6 @@ DISCOVERY_SCHEMA = vol.All(
)
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up MQTT humidifier configured under the fan platform key (deprecated)."""
# Deprecated in HA Core 2022.6
await async_setup_platform_helper(
hass,
humidifier.DOMAIN,
discovery_info or config,
async_add_entities,
_async_setup_entity,
)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,

View File

@ -9,15 +9,10 @@ import voluptuous as vol
from homeassistant.components import light
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.helpers.typing import ConfigType
from ..mixins import (
async_setup_entry_helper,
async_setup_platform_helper,
warn_for_legacy_schema,
)
from ..mixins import async_setup_entry_helper, warn_for_legacy_schema
from .schema import CONF_SCHEMA, MQTT_LIGHT_SCHEMA_SCHEMA
from .schema_basic import (
DISCOVERY_SCHEMA_BASIC,
@ -78,9 +73,8 @@ DISCOVERY_SCHEMA = vol.All(
)
# Configuring MQTT Lights under the light platform key is deprecated in HA Core 2022.6
# Setup for the legacy YAML format was removed in HA Core 2022.12
PLATFORM_SCHEMA = vol.All(
cv.PLATFORM_SCHEMA.extend(MQTT_LIGHT_SCHEMA_SCHEMA.schema, extra=vol.ALLOW_EXTRA),
validate_mqtt_light,
warn_for_legacy_schema(light.DOMAIN),
)
@ -90,23 +84,6 @@ PLATFORM_SCHEMA_MODERN = vol.All(
)
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up MQTT light through configuration.yaml (deprecated)."""
# Deprecated in HA Core 2022.6
await async_setup_platform_helper(
hass,
light.DOMAIN,
discovery_info or config,
async_add_entities,
_async_setup_entity,
)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,

View File

@ -30,7 +30,6 @@ from .mixins import (
MQTT_ENTITY_COMMON_SCHEMA,
MqttEntity,
async_setup_entry_helper,
async_setup_platform_helper,
warn_for_legacy_schema,
)
from .models import MqttValueTemplate, ReceiveMessage, ReceivePayloadType
@ -72,31 +71,14 @@ PLATFORM_SCHEMA_MODERN = MQTT_RW_SCHEMA.extend(
).extend(MQTT_ENTITY_COMMON_SCHEMA.schema)
# Configuring MQTT Locks under the lock platform key is deprecated in HA Core 2022.6
# Setup for the legacy YAML format was removed in HA Core 2022.12
PLATFORM_SCHEMA = vol.All(
cv.PLATFORM_SCHEMA.extend(PLATFORM_SCHEMA_MODERN.schema),
warn_for_legacy_schema(lock.DOMAIN),
)
DISCOVERY_SCHEMA = PLATFORM_SCHEMA_MODERN.extend({}, extra=vol.REMOVE_EXTRA)
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up MQTT locks configured under the lock platform key (deprecated)."""
# Deprecated in HA Core 2022.6
await async_setup_platform_helper(
hass,
lock.DOMAIN,
discovery_info or config,
async_add_entities,
_async_setup_entity,
)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,

View File

@ -240,10 +240,11 @@ def warn_for_legacy_schema(domain: str) -> Callable[[ConfigType], ConfigType]:
"""Return a validator."""
nonlocal warned
# Logged error and repair can be removed from HA 2023.6
if domain in warned:
return config
_LOGGER.warning(
_LOGGER.error(
"Manually configured MQTT %s(s) found under platform key '%s', "
"please move to the mqtt integration key, see "
"https://www.home-assistant.io/integrations/%s.mqtt/#new_format",
@ -259,7 +260,7 @@ def warn_for_legacy_schema(domain: str) -> Callable[[ConfigType], ConfigType]:
f"deprecated_yaml_{domain}",
breaks_in_ha_version="2022.12.0", # Warning first added in 2022.6.0
is_fixable=False,
severity=IssueSeverity.WARNING,
severity=IssueSeverity.ERROR,
translation_key="deprecated_yaml",
translation_placeholders={
"more_info_url": f"https://www.home-assistant.io/integrations/{domain}.mqtt/#new_format",
@ -366,33 +367,6 @@ async def async_setup_entry_helper(
await _async_setup_entities()
async def async_setup_platform_helper(
hass: HomeAssistant,
platform_domain: str,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
async_setup_entities: SetupEntity,
) -> None:
"""Help to set up the platform for manual configured MQTT entities."""
mqtt_data = get_mqtt_data(hass)
if mqtt_data.reload_entry:
_LOGGER.debug(
"MQTT integration is %s, skipping setup of manually configured MQTT items while unloading the config entry",
platform_domain,
)
return
if not (entry_status := mqtt_config_entry_enabled(hass)):
_LOGGER.warning(
"MQTT integration is %s, skipping setup of manually configured MQTT %s",
"not setup" if entry_status is None else "disabled",
platform_domain,
)
return
# Ensure we set config_entry when entries are set up to enable clean up
config_entry: ConfigEntry = hass.config_entries.async_entries(DOMAIN)[0]
await async_setup_entities(hass, async_add_entities, config, config_entry)
def init_entity_id_from_config(
hass: HomeAssistant, entity: Entity, config: ConfigType, entity_id_format: str
) -> None:

View File

@ -45,7 +45,6 @@ from .mixins import (
MQTT_ENTITY_COMMON_SCHEMA,
MqttEntity,
async_setup_entry_helper,
async_setup_platform_helper,
warn_for_legacy_schema,
)
from .models import (
@ -109,9 +108,8 @@ PLATFORM_SCHEMA_MODERN = vol.All(
)
# Configuring MQTT Number under the number platform key is deprecated in HA Core 2022.6
# Setup for the legacy YAML format was removed in HA Core 2022.12
PLATFORM_SCHEMA = vol.All(
cv.PLATFORM_SCHEMA.extend(_PLATFORM_SCHEMA_BASE.schema),
validate_config,
warn_for_legacy_schema(number.DOMAIN),
)
@ -121,23 +119,6 @@ DISCOVERY_SCHEMA = vol.All(
)
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up MQTT number configured under the number platform key (deprecated)."""
# Deprecated in HA Core 2022.6
await async_setup_platform_helper(
hass,
number.DOMAIN,
discovery_info or config,
async_add_entities,
_async_setup_entity,
)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,

View File

@ -24,7 +24,6 @@ from .mixins import (
MQTT_AVAILABILITY_SCHEMA,
MqttEntity,
async_setup_entry_helper,
async_setup_platform_helper,
warn_for_legacy_schema,
)
from .util import valid_publish_topic
@ -47,31 +46,14 @@ PLATFORM_SCHEMA_MODERN = MQTT_BASE_SCHEMA.extend(
).extend(MQTT_AVAILABILITY_SCHEMA.schema)
# Configuring MQTT Scenes under the scene platform key is deprecated in HA Core 2022.6
# Setup for the legacy YAML format was removed in HA Core 2022.12
PLATFORM_SCHEMA = vol.All(
cv.PLATFORM_SCHEMA.extend(PLATFORM_SCHEMA_MODERN.schema),
warn_for_legacy_schema(scene.DOMAIN),
)
DISCOVERY_SCHEMA = PLATFORM_SCHEMA_MODERN.extend({}, extra=vol.REMOVE_EXTRA)
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up MQTT scene configured under the scene platform key (deprecated)."""
# Deprecated in HA Core 2022.6
await async_setup_platform_helper(
hass,
scene.DOMAIN,
discovery_info or config,
async_add_entities,
_async_setup_entity,
)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,

View File

@ -32,7 +32,6 @@ from .mixins import (
MQTT_ENTITY_COMMON_SCHEMA,
MqttEntity,
async_setup_entry_helper,
async_setup_platform_helper,
warn_for_legacy_schema,
)
from .models import (
@ -70,30 +69,12 @@ PLATFORM_SCHEMA_MODERN = MQTT_RW_SCHEMA.extend(
# Configuring MQTT Select under the select platform key is deprecated in HA Core 2022.6
PLATFORM_SCHEMA = vol.All(
cv.PLATFORM_SCHEMA.extend(PLATFORM_SCHEMA_MODERN.schema),
warn_for_legacy_schema(select.DOMAIN),
)
DISCOVERY_SCHEMA = vol.All(PLATFORM_SCHEMA_MODERN.extend({}, extra=vol.REMOVE_EXTRA))
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up MQTT select configured under the select platform key (deprecated)."""
# Deprecated in HA Core 2022.6
await async_setup_platform_helper(
hass,
select.DOMAIN,
discovery_info or config,
async_add_entities,
_async_setup_entity,
)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,

View File

@ -45,7 +45,6 @@ from .mixins import (
MqttAvailability,
MqttEntity,
async_setup_entry_helper,
async_setup_platform_helper,
warn_for_legacy_schema,
)
from .models import (
@ -117,9 +116,6 @@ PLATFORM_SCHEMA_MODERN = vol.All(
# Configuring MQTT Sensors under the sensor platform key is deprecated in HA Core 2022.6
PLATFORM_SCHEMA = vol.All(
cv.deprecated(CONF_LAST_RESET_TOPIC),
cv.PLATFORM_SCHEMA.extend(_PLATFORM_SCHEMA_BASE.schema),
validate_options,
warn_for_legacy_schema(sensor.DOMAIN),
)
@ -130,23 +126,6 @@ DISCOVERY_SCHEMA = vol.All(
)
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up MQTT sensors configured under the fan platform key (deprecated)."""
# Deprecated in HA Core 2022.6
await async_setup_platform_helper(
hass,
sensor.DOMAIN,
discovery_info or config,
async_add_entities,
_async_setup_entity,
)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,

View File

@ -53,7 +53,6 @@ from .mixins import (
MQTT_ENTITY_COMMON_SCHEMA,
MqttEntity,
async_setup_entry_helper,
async_setup_platform_helper,
warn_for_legacy_schema,
)
from .models import (
@ -99,8 +98,8 @@ PLATFORM_SCHEMA_MODERN = MQTT_RW_SCHEMA.extend(
).extend(MQTT_ENTITY_COMMON_SCHEMA.schema)
# Configuring MQTT Sirens under the siren platform key is deprecated in HA Core 2022.6
# Setup for the legacy YAML format was removed in HA Core 2022.12
PLATFORM_SCHEMA = vol.All(
cv.PLATFORM_SCHEMA.extend(PLATFORM_SCHEMA_MODERN.schema),
warn_for_legacy_schema(siren.DOMAIN),
)
@ -126,23 +125,6 @@ SUPPORTED_ATTRIBUTES = {
_LOGGER = logging.getLogger(__name__)
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up MQTT sirens configured under the fan platform key (deprecated)."""
# Deprecated in HA Core 2022.6
await async_setup_platform_helper(
hass,
siren.DOMAIN,
discovery_info or config,
async_add_entities,
_async_setup_entity,
)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,

View File

@ -41,7 +41,6 @@ from .mixins import (
MQTT_ENTITY_COMMON_SCHEMA,
MqttEntity,
async_setup_entry_helper,
async_setup_platform_helper,
warn_for_legacy_schema,
)
from .models import MqttValueTemplate, ReceiveMessage
@ -68,31 +67,14 @@ PLATFORM_SCHEMA_MODERN = MQTT_RW_SCHEMA.extend(
).extend(MQTT_ENTITY_COMMON_SCHEMA.schema)
# Configuring MQTT Switches under the switch platform key is deprecated in HA Core 2022.6
# Setup for the legacy YAML format was removed in HA Core 2022.12
PLATFORM_SCHEMA = vol.All(
cv.PLATFORM_SCHEMA.extend(PLATFORM_SCHEMA_MODERN.schema),
warn_for_legacy_schema(switch.DOMAIN),
)
DISCOVERY_SCHEMA = PLATFORM_SCHEMA_MODERN.extend({}, extra=vol.REMOVE_EXTRA)
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up MQTT switch configured under the fan platform key (deprecated)."""
# Deprecated in HA Core 2022.6
await async_setup_platform_helper(
hass,
switch.DOMAIN,
discovery_info or config,
async_add_entities,
_async_setup_entity,
)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,

View File

@ -11,9 +11,8 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from ..const import CONF_SCHEMA
from ..mixins import async_setup_entry_helper, async_setup_platform_helper
from .schema import LEGACY, MQTT_VACUUM_SCHEMA, STATE
from ..mixins import async_setup_entry_helper, warn_for_legacy_schema
from .schema import CONF_SCHEMA, LEGACY, MQTT_VACUUM_SCHEMA, STATE
from .schema_legacy import (
DISCOVERY_SCHEMA_LEGACY,
PLATFORM_SCHEMA_LEGACY,
@ -58,8 +57,9 @@ DISCOVERY_SCHEMA = vol.All(
)
# Configuring MQTT Vacuums under the vacuum platform key is deprecated in HA Core 2022.6
# Setup for the legacy YAML format was removed in HA Core 2022.12
PLATFORM_SCHEMA = vol.All(
MQTT_VACUUM_SCHEMA.extend({}, extra=vol.ALLOW_EXTRA), validate_mqtt_vacuum
warn_for_legacy_schema(vacuum.DOMAIN),
)
PLATFORM_SCHEMA_MODERN = vol.All(
@ -67,23 +67,6 @@ PLATFORM_SCHEMA_MODERN = vol.All(
)
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up MQTT vacuum through configuration.yaml."""
# Deprecated in HA Core 2022.6
await async_setup_platform_helper(
hass,
vacuum.DOMAIN,
discovery_info or config,
async_add_entities,
_async_setup_entity,
)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,

View File

@ -54,7 +54,6 @@ from .test_common import (
help_test_entity_id_update_subscriptions,
help_test_publishing_with_custom_encoding,
help_test_reloadable,
help_test_reloadable_late,
help_test_setting_attribute_via_mqtt_json_message,
help_test_setting_attribute_with_template,
help_test_setting_blocked_attribute_via_mqtt_json_message,
@ -117,11 +116,6 @@ DEFAULT_CONFIG_REMOTE_CODE_TEXT = {
}
}
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
DEFAULT_CONFIG_LEGACY = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
DEFAULT_CONFIG_LEGACY[alarm_control_panel.DOMAIN]["platform"] = mqtt.DOMAIN
@pytest.fixture(autouse=True)
def alarm_control_panel_platform_only():
@ -991,15 +985,6 @@ async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_pa
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup."""
domain = alarm_control_panel.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain]
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity."""
platform = alarm_control_panel.DOMAIN
@ -1014,16 +999,3 @@ async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_setup_with_legacy_schema(hass, mqtt_mock_entry_with_yaml_config):
"""Test a setup with deprecated yaml platform schema."""
domain = alarm_control_panel.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain])
config["name"] = "test"
assert await async_setup_component(hass, domain, {domain: config})
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
assert hass.states.get(f"{domain}.test") is not None

View File

@ -39,7 +39,6 @@ from .test_common import (
help_test_entity_id_update_subscriptions,
help_test_reload_with_config,
help_test_reloadable,
help_test_reloadable_late,
help_test_setting_attribute_via_mqtt_json_message,
help_test_setting_attribute_with_template,
help_test_setup_manual_entity_from_yaml,
@ -64,11 +63,6 @@ DEFAULT_CONFIG = {
}
}
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
DEFAULT_CONFIG_LEGACY = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
DEFAULT_CONFIG_LEGACY[binary_sensor.DOMAIN]["platform"] = mqtt.DOMAIN
@pytest.fixture(autouse=True)
def binary_sensor_platform_only():
@ -117,14 +111,15 @@ async def test_setting_sensor_value_expires(
"""Test the expiration of the value."""
assert await async_setup_component(
hass,
binary_sensor.DOMAIN,
mqtt.DOMAIN,
{
binary_sensor.DOMAIN: {
"platform": "mqtt",
"name": "test",
"state_topic": "test-topic",
"expire_after": 4,
"force_update": True,
mqtt.DOMAIN: {
binary_sensor.DOMAIN: {
"name": "test",
"state_topic": "test-topic",
"expire_after": 4,
"force_update": True,
}
}
},
)
@ -1016,15 +1011,6 @@ async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_pa
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup."""
domain = binary_sensor.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain]
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
@pytest.mark.parametrize(
"payload1, state1, payload2, state2",
[("ON", "on", "OFF", "off"), ("OFF", "off", "ON", "on")],
@ -1138,16 +1124,3 @@ async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_setup_with_legacy_schema(hass, mqtt_mock_entry_with_yaml_config):
"""Test a setup with deprecated yaml platform schema."""
domain = binary_sensor.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain])
config["name"] = "test"
assert await async_setup_component(hass, domain, {domain: config})
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
assert hass.states.get(f"{domain}.test") is not None

View File

@ -31,7 +31,6 @@ from .test_common import (
help_test_entity_id_update_discovery_update,
help_test_publishing_with_custom_encoding,
help_test_reloadable,
help_test_reloadable_late,
help_test_setting_attribute_via_mqtt_json_message,
help_test_setting_attribute_with_template,
help_test_setting_blocked_attribute_via_mqtt_json_message,
@ -46,11 +45,6 @@ DEFAULT_CONFIG = {
mqtt.DOMAIN: {button.DOMAIN: {"name": "test", "command_topic": "test-topic"}}
}
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
DEFAULT_CONFIG_LEGACY = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
DEFAULT_CONFIG_LEGACY[button.DOMAIN]["platform"] = mqtt.DOMAIN
@pytest.fixture(autouse=True)
def button_platform_only():
@ -484,15 +478,6 @@ async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_pa
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup."""
domain = button.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain]
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity."""
platform = button.DOMAIN
@ -507,16 +492,3 @@ async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_setup_with_legacy_schema(hass, mqtt_mock_entry_with_yaml_config):
"""Test a setup with deprecated yaml platform schema."""
domain = button.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain])
config["name"] = "test"
assert await async_setup_component(hass, domain, {domain: config})
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
assert hass.states.get(f"{domain}.test") is not None

View File

@ -1,6 +1,5 @@
"""The tests for mqtt camera component."""
from base64 import b64encode
import copy
from http import HTTPStatus
import json
from unittest.mock import patch
@ -30,7 +29,6 @@ from .test_common import (
help_test_entity_id_update_discovery_update,
help_test_entity_id_update_subscriptions,
help_test_reloadable,
help_test_reloadable_late,
help_test_setting_attribute_via_mqtt_json_message,
help_test_setting_attribute_with_template,
help_test_setting_blocked_attribute_via_mqtt_json_message,
@ -45,11 +43,6 @@ from tests.common import async_fire_mqtt_message
DEFAULT_CONFIG = {mqtt.DOMAIN: {camera.DOMAIN: {"name": "test", "topic": "test_topic"}}}
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
DEFAULT_CONFIG_LEGACY = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
DEFAULT_CONFIG_LEGACY[camera.DOMAIN]["platform"] = mqtt.DOMAIN
@pytest.fixture(autouse=True)
def camera_platform_only():
@ -386,15 +379,6 @@ async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_pa
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup."""
domain = camera.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain]
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity."""
platform = camera.DOMAIN
@ -409,16 +393,3 @@ async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_setup_with_legacy_schema(hass, mqtt_mock_entry_with_yaml_config):
"""Test a setup with deprecated yaml platform schema."""
domain = camera.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain])
config["name"] = "test"
assert await async_setup_component(hass, domain, {domain: config})
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
assert hass.states.get(f"{domain}.test") is not None

View File

@ -46,7 +46,6 @@ from .test_common import (
help_test_entity_id_update_subscriptions,
help_test_publishing_with_custom_encoding,
help_test_reloadable,
help_test_reloadable_late,
help_test_setting_attribute_via_mqtt_json_message,
help_test_setting_attribute_with_template,
help_test_setting_blocked_attribute_via_mqtt_json_message,
@ -88,11 +87,6 @@ DEFAULT_CONFIG = {
}
}
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
DEFAULT_CONFIG_LEGACY = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
DEFAULT_CONFIG_LEGACY[climate.DOMAIN]["platform"] = mqtt.DOMAIN
@pytest.fixture(autouse=True)
def climate_platform_only():
@ -1406,15 +1400,6 @@ async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_pa
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup."""
domain = climate.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain]
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity."""
platform = climate.DOMAIN
@ -1429,16 +1414,3 @@ async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_setup_with_legacy_schema(hass, mqtt_mock_entry_with_yaml_config):
"""Test a setup with deprecated yaml platform schema."""
domain = climate.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain])
config["name"] = "test"
assert await async_setup_component(hass, domain, {domain: config})
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
assert hass.states.get(f"{domain}.test") is not None

View File

@ -1705,103 +1705,16 @@ async def help_test_reloadable(
old_config_2 = copy.deepcopy(config)
old_config_2["name"] = "test_old_2"
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
old_config_3 = copy.deepcopy(config)
old_config_3["name"] = "test_old_3"
old_config_3["platform"] = mqtt.DOMAIN
old_config_4 = copy.deepcopy(config)
old_config_4["name"] = "test_old_4"
old_config_4["platform"] = mqtt.DOMAIN
old_config = {
mqtt.DOMAIN: {domain: [old_config_1, old_config_2]},
domain: [old_config_3, old_config_4],
}
assert await async_setup_component(hass, domain, old_config)
assert await async_setup_component(hass, mqtt.DOMAIN, old_config)
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
assert hass.states.get(f"{domain}.test_old_1")
assert hass.states.get(f"{domain}.test_old_2")
assert hass.states.get(f"{domain}.test_old_3")
assert hass.states.get(f"{domain}.test_old_4")
assert len(hass.states.async_all(domain)) == 4
# Create temporary fixture for configuration.yaml based on the supplied config and
# test a reload with this new config
new_config_1 = copy.deepcopy(config)
new_config_1["name"] = "test_new_1"
new_config_2 = copy.deepcopy(config)
new_config_2["name"] = "test_new_2"
new_config_extra = copy.deepcopy(config)
new_config_extra["name"] = "test_new_5"
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
new_config_3 = copy.deepcopy(config)
new_config_3["name"] = "test_new_3"
new_config_3["platform"] = mqtt.DOMAIN
new_config_4 = copy.deepcopy(config)
new_config_4["name"] = "test_new_4"
new_config_4["platform"] = mqtt.DOMAIN
new_config_extra_legacy = copy.deepcopy(config)
new_config_extra_legacy["name"] = "test_new_6"
new_config_extra_legacy["platform"] = mqtt.DOMAIN
new_config = {
mqtt.DOMAIN: {domain: [new_config_1, new_config_2, new_config_extra]},
domain: [new_config_3, new_config_4, new_config_extra_legacy],
}
await help_test_reload_with_config(hass, caplog, tmp_path, new_config)
assert len(hass.states.async_all(domain)) == 6
assert hass.states.get(f"{domain}.test_new_1")
assert hass.states.get(f"{domain}.test_new_2")
assert hass.states.get(f"{domain}.test_new_3")
assert hass.states.get(f"{domain}.test_new_4")
assert hass.states.get(f"{domain}.test_new_5")
assert hass.states.get(f"{domain}.test_new_6")
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def help_test_reloadable_late(hass, caplog, tmp_path, domain, config):
"""Test reloading an MQTT platform when config entry is setup is late."""
# Create and test an old config of 2 entities based on the config supplied
# using the deprecated platform schema
old_config_1 = copy.deepcopy(config)
old_config_1["name"] = "test_old_1"
old_config_2 = copy.deepcopy(config)
old_config_2["name"] = "test_old_2"
old_yaml_config_file = tmp_path / "configuration.yaml"
old_yaml_config = yaml.dump({domain: [old_config_1, old_config_2]})
old_yaml_config_file.write_text(old_yaml_config)
assert old_yaml_config_file.read_text() == old_yaml_config
assert await async_setup_component(
hass, domain, {domain: [old_config_1, old_config_2]}
)
await hass.async_block_till_done()
# No MQTT config entry, there should be a warning and no entities
assert (
"MQTT integration is not setup, skipping setup of manually "
f"configured MQTT {domain}"
) in caplog.text
assert len(hass.states.async_all(domain)) == 0
# User sets up a config entry, should succeed and entities will setup
entry = MockConfigEntry(domain=mqtt.DOMAIN, data={mqtt.CONF_BROKER: "test-broker"})
entry.add_to_hass(hass)
with patch.object(hass_config, "YAML_CONFIG_FILE", old_yaml_config_file):
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert len(hass.states.async_all(domain)) == 2
# Create temporary fixture for configuration.yaml based on the supplied config and
@ -1810,14 +1723,14 @@ async def help_test_reloadable_late(hass, caplog, tmp_path, domain, config):
new_config_1["name"] = "test_new_1"
new_config_2 = copy.deepcopy(config)
new_config_2["name"] = "test_new_2"
new_config_3 = copy.deepcopy(config)
new_config_3["name"] = "test_new_3"
new_config_extra = copy.deepcopy(config)
new_config_extra["name"] = "test_new_3"
new_config = {
domain: [new_config_1, new_config_2, new_config_3],
mqtt.DOMAIN: {domain: [new_config_1, new_config_2, new_config_extra]},
}
await help_test_reload_with_config(hass, caplog, tmp_path, new_config)
await hass.async_block_till_done()
assert len(hass.states.async_all(domain)) == 3

View File

@ -1,6 +1,5 @@
"""The tests for the MQTT cover platform."""
import copy
from unittest.mock import patch
import pytest
@ -67,7 +66,6 @@ from .test_common import (
help_test_entity_id_update_subscriptions,
help_test_publishing_with_custom_encoding,
help_test_reloadable,
help_test_reloadable_late,
help_test_setting_attribute_via_mqtt_json_message,
help_test_setting_attribute_with_template,
help_test_setting_blocked_attribute_via_mqtt_json_message,
@ -84,11 +82,6 @@ DEFAULT_CONFIG = {
mqtt.DOMAIN: {cover.DOMAIN: {"name": "test", "state_topic": "test-topic"}}
}
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
DEFAULT_CONFIG_LEGACY = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
DEFAULT_CONFIG_LEGACY[cover.DOMAIN]["platform"] = mqtt.DOMAIN
@pytest.fixture(autouse=True)
def cover_platform_only():
@ -3368,15 +3361,6 @@ async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_pa
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup."""
domain = cover.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain]
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
@pytest.mark.parametrize(
"topic,value,attribute,attribute_value",
[
@ -3424,16 +3408,3 @@ async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_setup_with_legacy_schema(hass, mqtt_mock_entry_with_yaml_config):
"""Test a setup with deprecated yaml platform schema."""
domain = cover.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain])
config["name"] = "test"
assert await async_setup_component(hass, domain, {domain: config})
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
assert hass.states.get(f"{domain}.test") is not None

View File

@ -1,405 +0,0 @@
"""The tests for the MQTT device tracker platform using configuration.yaml with legacy schema."""
import json
from unittest.mock import patch
import pytest
from homeassistant.components import device_tracker
from homeassistant.components.device_tracker import SourceType
from homeassistant.config_entries import ConfigEntryDisabler
from homeassistant.const import CONF_PLATFORM, STATE_HOME, STATE_NOT_HOME, Platform
from homeassistant.setup import async_setup_component
from .test_common import (
MockConfigEntry,
help_test_entry_reload_with_new_config,
help_test_unload_config_entry,
)
from tests.common import async_fire_mqtt_message
@pytest.fixture(autouse=True)
def device_tracker_platform_only():
"""Only setup the device_tracker platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.DEVICE_TRACKER]):
yield
# Deprecated in HA Core 2022.6
async def test_legacy_ensure_device_tracker_platform_validation(
hass, mqtt_mock_entry_with_yaml_config
):
"""Test if platform validation was done."""
async def mock_setup_scanner(hass, config, see, discovery_info=None):
"""Check that Qos was added by validation."""
assert "qos" in config
with patch(
"homeassistant.components.mqtt.device_tracker.async_setup_scanner",
autospec=True,
side_effect=mock_setup_scanner,
) as mock_sp:
dev_id = "paulus"
topic = "/location/paulus"
assert await async_setup_component(
hass,
device_tracker.DOMAIN,
{
device_tracker.DOMAIN: {
CONF_PLATFORM: "mqtt",
"devices": {dev_id: topic},
}
},
)
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
assert mock_sp.call_count == 1
# Deprecated in HA Core 2022.6
async def test_legacy_new_message(
hass, mock_device_tracker_conf, mqtt_mock_entry_no_yaml_config
):
"""Test new message."""
await mqtt_mock_entry_no_yaml_config()
dev_id = "paulus"
entity_id = f"{device_tracker.DOMAIN}.{dev_id}"
topic = "/location/paulus"
location = "work"
hass.config.components = {"mqtt", "zone"}
assert await async_setup_component(
hass,
device_tracker.DOMAIN,
{device_tracker.DOMAIN: {CONF_PLATFORM: "mqtt", "devices": {dev_id: topic}}},
)
async_fire_mqtt_message(hass, topic, location)
await hass.async_block_till_done()
assert hass.states.get(entity_id).state == location
# Deprecated in HA Core 2022.6
async def test_legacy_single_level_wildcard_topic(
hass, mock_device_tracker_conf, mqtt_mock_entry_no_yaml_config
):
"""Test single level wildcard topic."""
await mqtt_mock_entry_no_yaml_config()
dev_id = "paulus"
entity_id = f"{device_tracker.DOMAIN}.{dev_id}"
subscription = "/location/+/paulus"
topic = "/location/room/paulus"
location = "work"
hass.config.components = {"mqtt", "zone"}
assert await async_setup_component(
hass,
device_tracker.DOMAIN,
{
device_tracker.DOMAIN: {
CONF_PLATFORM: "mqtt",
"devices": {dev_id: subscription},
}
},
)
async_fire_mqtt_message(hass, topic, location)
await hass.async_block_till_done()
assert hass.states.get(entity_id).state == location
# Deprecated in HA Core 2022.6
async def test_legacy_multi_level_wildcard_topic(
hass, mock_device_tracker_conf, mqtt_mock_entry_no_yaml_config
):
"""Test multi level wildcard topic."""
await mqtt_mock_entry_no_yaml_config()
dev_id = "paulus"
entity_id = f"{device_tracker.DOMAIN}.{dev_id}"
subscription = "/location/#"
topic = "/location/room/paulus"
location = "work"
hass.config.components = {"mqtt", "zone"}
assert await async_setup_component(
hass,
device_tracker.DOMAIN,
{
device_tracker.DOMAIN: {
CONF_PLATFORM: "mqtt",
"devices": {dev_id: subscription},
}
},
)
async_fire_mqtt_message(hass, topic, location)
await hass.async_block_till_done()
assert hass.states.get(entity_id).state == location
# Deprecated in HA Core 2022.6
async def test_legacy_single_level_wildcard_topic_not_matching(
hass, mock_device_tracker_conf, mqtt_mock_entry_no_yaml_config
):
"""Test not matching single level wildcard topic."""
await mqtt_mock_entry_no_yaml_config()
dev_id = "paulus"
entity_id = f"{device_tracker.DOMAIN}.{dev_id}"
subscription = "/location/+/paulus"
topic = "/location/paulus"
location = "work"
hass.config.components = {"mqtt", "zone"}
assert await async_setup_component(
hass,
device_tracker.DOMAIN,
{
device_tracker.DOMAIN: {
CONF_PLATFORM: "mqtt",
"devices": {dev_id: subscription},
}
},
)
async_fire_mqtt_message(hass, topic, location)
await hass.async_block_till_done()
assert hass.states.get(entity_id) is None
# Deprecated in HA Core 2022.6
async def test_legacy_multi_level_wildcard_topic_not_matching(
hass, mock_device_tracker_conf, mqtt_mock_entry_no_yaml_config
):
"""Test not matching multi level wildcard topic."""
await mqtt_mock_entry_no_yaml_config()
dev_id = "paulus"
entity_id = f"{device_tracker.DOMAIN}.{dev_id}"
subscription = "/location/#"
topic = "/somewhere/room/paulus"
location = "work"
hass.config.components = {"mqtt", "zone"}
assert await async_setup_component(
hass,
device_tracker.DOMAIN,
{
device_tracker.DOMAIN: {
CONF_PLATFORM: "mqtt",
"devices": {dev_id: subscription},
}
},
)
async_fire_mqtt_message(hass, topic, location)
await hass.async_block_till_done()
assert hass.states.get(entity_id) is None
# Deprecated in HA Core 2022.6
async def test_legacy_matching_custom_payload_for_home_and_not_home(
hass, mock_device_tracker_conf, mqtt_mock_entry_no_yaml_config
):
"""Test custom payload_home sets state to home and custom payload_not_home sets state to not_home."""
await mqtt_mock_entry_no_yaml_config()
dev_id = "paulus"
entity_id = f"{device_tracker.DOMAIN}.{dev_id}"
topic = "/location/paulus"
payload_home = "present"
payload_not_home = "not present"
hass.config.components = {"mqtt", "zone"}
assert await async_setup_component(
hass,
device_tracker.DOMAIN,
{
device_tracker.DOMAIN: {
CONF_PLATFORM: "mqtt",
"devices": {dev_id: topic},
"payload_home": payload_home,
"payload_not_home": payload_not_home,
}
},
)
async_fire_mqtt_message(hass, topic, payload_home)
await hass.async_block_till_done()
assert hass.states.get(entity_id).state == STATE_HOME
async_fire_mqtt_message(hass, topic, payload_not_home)
await hass.async_block_till_done()
assert hass.states.get(entity_id).state == STATE_NOT_HOME
# Deprecated in HA Core 2022.6
async def test_legacy_not_matching_custom_payload_for_home_and_not_home(
hass, mock_device_tracker_conf, mqtt_mock_entry_no_yaml_config
):
"""Test not matching payload does not set state to home or not_home."""
await mqtt_mock_entry_no_yaml_config()
dev_id = "paulus"
entity_id = f"{device_tracker.DOMAIN}.{dev_id}"
topic = "/location/paulus"
payload_home = "present"
payload_not_home = "not present"
payload_not_matching = "test"
hass.config.components = {"mqtt", "zone"}
assert await async_setup_component(
hass,
device_tracker.DOMAIN,
{
device_tracker.DOMAIN: {
CONF_PLATFORM: "mqtt",
"devices": {dev_id: topic},
"payload_home": payload_home,
"payload_not_home": payload_not_home,
}
},
)
async_fire_mqtt_message(hass, topic, payload_not_matching)
await hass.async_block_till_done()
assert hass.states.get(entity_id).state != STATE_HOME
assert hass.states.get(entity_id).state != STATE_NOT_HOME
# Deprecated in HA Core 2022.6
async def test_legacy_matching_source_type(
hass, mock_device_tracker_conf, mqtt_mock_entry_no_yaml_config
):
"""Test setting source type."""
await mqtt_mock_entry_no_yaml_config()
dev_id = "paulus"
entity_id = f"{device_tracker.DOMAIN}.{dev_id}"
topic = "/location/paulus"
source_type = SourceType.BLUETOOTH
location = "work"
hass.config.components = {"mqtt", "zone"}
assert await async_setup_component(
hass,
device_tracker.DOMAIN,
{
device_tracker.DOMAIN: {
CONF_PLATFORM: "mqtt",
"devices": {dev_id: topic},
"source_type": source_type,
}
},
)
async_fire_mqtt_message(hass, topic, location)
await hass.async_block_till_done()
assert hass.states.get(entity_id).attributes["source_type"] == SourceType.BLUETOOTH
# Deprecated in HA Core 2022.6
async def test_unload_entry(
hass, mock_device_tracker_conf, mqtt_mock_entry_no_yaml_config, tmp_path
):
"""Test unloading the config entry."""
# setup through configuration.yaml
await mqtt_mock_entry_no_yaml_config()
dev_id = "jan"
entity_id = f"{device_tracker.DOMAIN}.{dev_id}"
topic = "/location/jan"
location = "home"
hass.config.components = {"mqtt", "zone"}
assert await async_setup_component(
hass,
device_tracker.DOMAIN,
{device_tracker.DOMAIN: {CONF_PLATFORM: "mqtt", "devices": {dev_id: topic}}},
)
async_fire_mqtt_message(hass, topic, location)
await hass.async_block_till_done()
assert hass.states.get(entity_id).state == location
# setup through discovery
dev_id = "piet"
subscription = "/location/#"
domain = device_tracker.DOMAIN
discovery_config = {
"devices": {dev_id: subscription},
"state_topic": "some-state",
"name": "piet",
}
async_fire_mqtt_message(
hass, f"homeassistant/{domain}/bla/config", json.dumps(discovery_config)
)
await hass.async_block_till_done()
# check that both entities were created
config_setup_entity = hass.states.get(f"{domain}.jan")
assert config_setup_entity
discovery_setup_entity = hass.states.get(f"{domain}.piet")
assert discovery_setup_entity
await help_test_unload_config_entry(hass, tmp_path, {})
await hass.async_block_till_done()
# check that both entities were unsubscribed and that the location was not processed
async_fire_mqtt_message(hass, "some-state", "not_home")
async_fire_mqtt_message(hass, "location/jan", "not_home")
await hass.async_block_till_done()
config_setup_entity = hass.states.get(f"{domain}.jan")
assert config_setup_entity.state == location
# the discovered tracker is an entity which state is removed at unload
discovery_setup_entity = hass.states.get(f"{domain}.piet")
assert discovery_setup_entity is None
# Deprecated in HA Core 2022.6
async def test_reload_entry_legacy(
hass, mock_device_tracker_conf, mqtt_mock_entry_no_yaml_config, tmp_path
):
"""Test reloading the config entry with manual MQTT items."""
# setup through configuration.yaml
await mqtt_mock_entry_no_yaml_config()
entity_id = f"{device_tracker.DOMAIN}.jan"
topic = "location/jan"
location = "home"
config = {
device_tracker.DOMAIN: {CONF_PLATFORM: "mqtt", "devices": {"jan": topic}},
}
hass.config.components = {"mqtt", "zone"}
assert await async_setup_component(hass, device_tracker.DOMAIN, config)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, topic, location)
await hass.async_block_till_done()
assert hass.states.get(entity_id).state == location
await help_test_entry_reload_with_new_config(hass, tmp_path, config)
await hass.async_block_till_done()
location = "not_home"
async_fire_mqtt_message(hass, topic, location)
await hass.async_block_till_done()
assert hass.states.get(entity_id).state == location
# Deprecated in HA Core 2022.6
async def test_setup_with_disabled_entry(
hass, mock_device_tracker_conf, caplog
) -> None:
"""Test setting up the platform with a disabled config entry."""
# Try to setup the platform with a disabled config entry
config_entry = MockConfigEntry(
domain="mqtt", data={}, disabled_by=ConfigEntryDisabler.USER
)
config_entry.add_to_hass(hass)
topic = "location/jan"
config = {
device_tracker.DOMAIN: {CONF_PLATFORM: "mqtt", "devices": {"jan": topic}},
}
hass.config.components = {"mqtt", "zone"}
await async_setup_component(hass, device_tracker.DOMAIN, config)
await hass.async_block_till_done()
assert (
"MQTT device trackers will be not available until the config entry is enabled"
in caplog.text
)

View File

@ -52,7 +52,6 @@ from .test_common import (
help_test_entity_id_update_subscriptions,
help_test_publishing_with_custom_encoding,
help_test_reloadable,
help_test_reloadable_late,
help_test_setting_attribute_via_mqtt_json_message,
help_test_setting_attribute_with_template,
help_test_setting_blocked_attribute_via_mqtt_json_message,
@ -76,11 +75,6 @@ DEFAULT_CONFIG = {
}
}
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
DEFAULT_CONFIG_LEGACY = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
DEFAULT_CONFIG_LEGACY[fan.DOMAIN]["platform"] = mqtt.DOMAIN
@pytest.fixture(autouse=True)
def fan_platform_only():
@ -1941,15 +1935,6 @@ async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_pa
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup."""
domain = fan.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain]
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity."""
platform = fan.DOMAIN
@ -1964,16 +1949,3 @@ async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_setup_with_legacy_schema(hass, mqtt_mock_entry_with_yaml_config):
"""Test a setup with deprecated yaml platform schema."""
domain = fan.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain])
config["name"] = "test"
assert await async_setup_component(hass, domain, {domain: config})
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
assert hass.states.get(f"{domain}.test") is not None

View File

@ -54,7 +54,6 @@ from .test_common import (
help_test_entity_id_update_subscriptions,
help_test_publishing_with_custom_encoding,
help_test_reloadable,
help_test_reloadable_late,
help_test_setting_attribute_via_mqtt_json_message,
help_test_setting_attribute_with_template,
help_test_setting_blocked_attribute_via_mqtt_json_message,
@ -78,11 +77,6 @@ DEFAULT_CONFIG = {
}
}
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
DEFAULT_CONFIG_LEGACY = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
DEFAULT_CONFIG_LEGACY[humidifier.DOMAIN]["platform"] = mqtt.DOMAIN
@pytest.fixture(autouse=True)
def humidifer_platform_only():
@ -1313,15 +1307,6 @@ async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_pa
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup."""
domain = humidifier.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain]
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity."""
platform = humidifier.DOMAIN
@ -1347,16 +1332,3 @@ async def test_unload_config_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_p
await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_setup_with_legacy_schema(hass, mqtt_mock_entry_with_yaml_config):
"""Test a setup with deprecated yaml platform schema."""
domain = humidifier.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain])
config["name"] = "test"
assert await async_setup_component(hass, domain, {domain: config})
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
assert hass.states.get(f"{domain}.test") is not None

View File

@ -2735,7 +2735,7 @@ async def test_one_deprecation_warning_per_platform(
await mqtt_mock_entry_with_yaml_config()
count = 0
for record in caplog.records:
if record.levelname == "WARNING" and (
if record.levelname == "ERROR" and (
f"Manually configured MQTT {platform}(s) found under platform key '{platform}'"
in record.message
):
@ -2817,15 +2817,6 @@ async def test_reload_entry_with_new_config(hass, tmp_path):
"mqtt": {
"light": [{"name": "test_new_modern", "command_topic": "test-topic_new"}]
},
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
"light": [
{
"platform": "mqtt",
"name": "test_new_legacy",
"command_topic": "test-topic_new",
}
],
}
await help_test_setup_manual_entity_from_yaml(hass, config_old)
assert hass.states.get("light.test_old1") is not None
@ -2833,7 +2824,6 @@ async def test_reload_entry_with_new_config(hass, tmp_path):
await help_test_entry_reload_with_new_config(hass, tmp_path, config_yaml_new)
assert hass.states.get("light.test_old1") is None
assert hass.states.get("light.test_new_modern") is not None
assert hass.states.get("light.test_new_legacy") is not None
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.LIGHT])
@ -2846,15 +2836,6 @@ async def test_disabling_and_enabling_entry(hass, tmp_path, caplog):
"mqtt": {
"light": [{"name": "test_new_modern", "command_topic": "test-topic_new"}]
},
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
"light": [
{
"platform": "mqtt",
"name": "test_new_legacy",
"command_topic": "test-topic_new",
}
],
}
await help_test_setup_manual_entity_from_yaml(hass, config_old)
assert hass.states.get("light.test_old1") is not None
@ -2883,12 +2864,6 @@ async def test_disabling_and_enabling_entry(hass, tmp_path, caplog):
await hass.async_block_till_done()
await hass.async_block_till_done()
# Assert that the discovery was still received
# but kipped the setup
assert (
"MQTT integration is disabled, skipping setup of manually configured MQTT light"
in caplog.text
)
assert mqtt_config_entry.state is ConfigEntryState.NOT_LOADED
assert hass.states.get("light.test_old1") is None
@ -2903,7 +2878,6 @@ async def test_disabling_and_enabling_entry(hass, tmp_path, caplog):
assert hass.states.get("light.test_old1") is None
assert hass.states.get("light.test_new_modern") is not None
assert hass.states.get("light.test_new_legacy") is not None
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.LIGHT])

View File

@ -29,7 +29,7 @@ from homeassistant.components.vacuum import (
ATTR_STATUS,
VacuumEntityFeature,
)
from homeassistant.const import CONF_NAME, CONF_PLATFORM, STATE_OFF, STATE_ON, Platform
from homeassistant.const import CONF_NAME, STATE_OFF, STATE_ON, Platform
from homeassistant.setup import async_setup_component
from .test_common import (
@ -52,7 +52,6 @@ from .test_common import (
help_test_entity_id_update_subscriptions,
help_test_publishing_with_custom_encoding,
help_test_reloadable,
help_test_reloadable_late,
help_test_setting_attribute_via_mqtt_json_message,
help_test_setting_attribute_with_template,
help_test_setting_blocked_attribute_via_mqtt_json_message,
@ -91,11 +90,6 @@ DEFAULT_CONFIG = {
DEFAULT_CONFIG_2 = {mqtt.DOMAIN: {vacuum.DOMAIN: {"name": "test"}}}
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
DEFAULT_CONFIG_LEGACY = deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
DEFAULT_CONFIG_LEGACY[vacuum.DOMAIN][CONF_PLATFORM] = mqtt.DOMAIN
@pytest.fixture(autouse=True)
def vacuum_platform_only():
@ -936,15 +930,6 @@ async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_pa
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup."""
domain = vacuum.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain]
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
@pytest.mark.parametrize(
"topic,value,attribute,attribute_value",
[
@ -1011,16 +996,3 @@ async def test_setup_manual_entity_from_yaml(hass):
platform = vacuum.DOMAIN
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
assert hass.states.get(f"{platform}.mqtttest")
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_setup_with_legacy_schema(hass, mqtt_mock_entry_with_yaml_config):
"""Test a setup with deprecated yaml platform schema."""
domain = vacuum.DOMAIN
config = deepcopy(DEFAULT_CONFIG_LEGACY[domain])
config["name"] = "test"
assert await async_setup_component(hass, domain, {domain: config})
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
assert hass.states.get(f"{domain}.test") is not None

View File

@ -216,7 +216,6 @@ from .test_common import (
help_test_entity_id_update_subscriptions,
help_test_publishing_with_custom_encoding,
help_test_reloadable,
help_test_reloadable_late,
help_test_setting_attribute_via_mqtt_json_message,
help_test_setting_attribute_with_template,
help_test_setting_blocked_attribute_via_mqtt_json_message,
@ -234,11 +233,6 @@ DEFAULT_CONFIG = {
mqtt.DOMAIN: {light.DOMAIN: {"name": "test", "command_topic": "test-topic"}}
}
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
DEFAULT_CONFIG_LEGACY = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
DEFAULT_CONFIG_LEGACY[light.DOMAIN]["platform"] = mqtt.DOMAIN
@pytest.fixture(autouse=True)
def light_platform_only():
@ -2945,15 +2939,6 @@ async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_pa
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup."""
domain = light.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain]
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
@pytest.mark.parametrize(
"topic,value,attribute,attribute_value,init_payload",
[
@ -3151,16 +3136,3 @@ async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_setup_with_legacy_schema(hass, mqtt_mock_entry_with_yaml_config):
"""Test a setup with deprecated yaml platform schema."""
domain = light.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain])
config["name"] = "test"
assert await async_setup_component(hass, domain, {domain: config})
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
assert hass.states.get(f"{domain}.test") is not None

View File

@ -119,7 +119,6 @@ from .test_common import (
help_test_entity_id_update_subscriptions,
help_test_publishing_with_custom_encoding,
help_test_reloadable,
help_test_reloadable_late,
help_test_setting_attribute_via_mqtt_json_message,
help_test_setting_attribute_with_template,
help_test_setting_blocked_attribute_via_mqtt_json_message,
@ -142,11 +141,6 @@ DEFAULT_CONFIG = {
}
}
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
DEFAULT_CONFIG_LEGACY = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
DEFAULT_CONFIG_LEGACY[light.DOMAIN]["platform"] = mqtt.DOMAIN
@pytest.fixture(autouse=True)
def light_platform_only():
@ -2205,15 +2199,6 @@ async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_pa
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup."""
domain = light.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain]
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
@pytest.mark.parametrize(
"topic,value,attribute,attribute_value,init_payload",
[
@ -2267,16 +2252,3 @@ async def test_setup_manual_entity_from_yaml(hass):
platform = light.DOMAIN
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
assert hass.states.get(f"{platform}.test")
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_setup_with_legacy_schema(hass, mqtt_mock_entry_with_yaml_config):
"""Test a setup with deprecated yaml platform schema."""
domain = light.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain])
config["name"] = "test"
assert await async_setup_component(hass, domain, {domain: config})
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
assert hass.states.get(f"{domain}.test") is not None

View File

@ -64,7 +64,6 @@ from .test_common import (
help_test_entity_id_update_subscriptions,
help_test_publishing_with_custom_encoding,
help_test_reloadable,
help_test_reloadable_late,
help_test_setting_attribute_via_mqtt_json_message,
help_test_setting_attribute_with_template,
help_test_setting_blocked_attribute_via_mqtt_json_message,
@ -90,11 +89,6 @@ DEFAULT_CONFIG = {
}
}
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
DEFAULT_CONFIG_LEGACY = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
DEFAULT_CONFIG_LEGACY[light.DOMAIN]["platform"] = mqtt.DOMAIN
@pytest.fixture(autouse=True)
def light_platform_only():
@ -1201,15 +1195,6 @@ async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_pa
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup."""
domain = light.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain]
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
@pytest.mark.parametrize(
"topic,value,attribute,attribute_value,init_payload",
[
@ -1257,16 +1242,3 @@ async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_setup_with_legacy_schema(hass, mqtt_mock_entry_with_yaml_config):
"""Test a setup with deprecated yaml platform schema."""
domain = light.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain])
config["name"] = "test"
assert await async_setup_component(hass, domain, {domain: config})
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
assert hass.states.get(f"{domain}.test") is not None

View File

@ -1,5 +1,4 @@
"""The tests for the MQTT lock platform."""
import copy
from unittest.mock import patch
import pytest
@ -42,7 +41,6 @@ from .test_common import (
help_test_entity_id_update_subscriptions,
help_test_publishing_with_custom_encoding,
help_test_reloadable,
help_test_reloadable_late,
help_test_setting_attribute_via_mqtt_json_message,
help_test_setting_attribute_with_template,
help_test_setting_blocked_attribute_via_mqtt_json_message,
@ -59,11 +57,6 @@ DEFAULT_CONFIG = {
mqtt.DOMAIN: {lock.DOMAIN: {"name": "test", "command_topic": "test-topic"}}
}
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
DEFAULT_CONFIG_LEGACY = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
DEFAULT_CONFIG_LEGACY[lock.DOMAIN]["platform"] = mqtt.DOMAIN
@pytest.fixture(autouse=True)
def lock_platform_only():
@ -726,15 +719,6 @@ async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_pa
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup."""
domain = lock.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain]
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
@pytest.mark.parametrize(
"topic,value,attribute,attribute_value",
[
@ -778,16 +762,3 @@ async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_setup_with_legacy_schema(hass, mqtt_mock_entry_with_yaml_config):
"""Test a setup with deprecated yaml platform schema."""
domain = lock.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain])
config["name"] = "test"
assert await async_setup_component(hass, domain, {domain: config})
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
assert hass.states.get(f"{domain}.test") is not None

View File

@ -1,5 +1,4 @@
"""The tests for mqtt number component."""
import copy
import json
from unittest.mock import patch
@ -52,7 +51,6 @@ from .test_common import (
help_test_entity_id_update_subscriptions,
help_test_publishing_with_custom_encoding,
help_test_reloadable,
help_test_reloadable_late,
help_test_setting_attribute_via_mqtt_json_message,
help_test_setting_attribute_with_template,
help_test_setting_blocked_attribute_via_mqtt_json_message,
@ -69,11 +67,6 @@ DEFAULT_CONFIG = {
mqtt.DOMAIN: {number.DOMAIN: {"name": "test", "command_topic": "test-topic"}}
}
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
DEFAULT_CONFIG_LEGACY = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
DEFAULT_CONFIG_LEGACY[number.DOMAIN]["platform"] = mqtt.DOMAIN
@pytest.fixture(autouse=True)
def number_platform_only():
@ -907,15 +900,6 @@ async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_pa
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup."""
domain = number.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain]
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
@pytest.mark.parametrize(
"topic,value,attribute,attribute_value",
[
@ -960,16 +944,3 @@ async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_setup_with_legacy_schema(hass, mqtt_mock_entry_with_yaml_config):
"""Test a setup with deprecated yaml platform schema."""
domain = number.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain])
config["name"] = "test"
assert await async_setup_component(hass, domain, {domain: config})
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
assert hass.states.get(f"{domain}.test") is not None

View File

@ -19,7 +19,6 @@ from .test_common import (
help_test_discovery_update,
help_test_discovery_update_unchanged,
help_test_reloadable,
help_test_reloadable_late,
help_test_setup_manual_entity_from_yaml,
help_test_unique_id,
help_test_unload_config_entry_with_platform,
@ -37,11 +36,6 @@ DEFAULT_CONFIG = {
}
}
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
DEFAULT_CONFIG_LEGACY = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
DEFAULT_CONFIG_LEGACY[scene.DOMAIN]["platform"] = mqtt.DOMAIN
@pytest.fixture(autouse=True)
def scene_platform_only():
@ -231,15 +225,6 @@ async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_pa
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup."""
domain = scene.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain]
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity."""
platform = scene.DOMAIN
@ -254,16 +239,3 @@ async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_setup_with_legacy_schema(hass, mqtt_mock_entry_with_yaml_config):
"""Test a setup with deprecated yaml platform schema."""
domain = scene.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain])
config["name"] = "test"
assert await async_setup_component(hass, domain, {domain: config})
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
assert hass.states.get(f"{domain}.test") is not None

View File

@ -42,7 +42,6 @@ from .test_common import (
help_test_entity_id_update_subscriptions,
help_test_publishing_with_custom_encoding,
help_test_reloadable,
help_test_reloadable_late,
help_test_setting_attribute_via_mqtt_json_message,
help_test_setting_attribute_with_template,
help_test_setting_blocked_attribute_via_mqtt_json_message,
@ -65,11 +64,6 @@ DEFAULT_CONFIG = {
}
}
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
DEFAULT_CONFIG_LEGACY = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
DEFAULT_CONFIG_LEGACY[select.DOMAIN]["platform"] = mqtt.DOMAIN
@pytest.fixture(autouse=True)
def select_platform_only():
@ -661,15 +655,6 @@ async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_pa
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup."""
domain = select.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain]
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
@pytest.mark.parametrize(
"topic,value,attribute,attribute_value",
[
@ -716,16 +701,3 @@ async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_setup_with_legacy_schema(hass, mqtt_mock_entry_with_yaml_config):
"""Test a setup with deprecated yaml platform schema."""
domain = select.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain])
config["name"] = "test"
assert await async_setup_component(hass, domain, {domain: config})
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
assert hass.states.get(f"{domain}.test") is not None

View File

@ -52,7 +52,6 @@ from .test_common import (
help_test_entity_id_update_subscriptions,
help_test_reload_with_config,
help_test_reloadable,
help_test_reloadable_late,
help_test_setting_attribute_via_mqtt_json_message,
help_test_setting_attribute_with_template,
help_test_setting_blocked_attribute_via_mqtt_json_message,
@ -73,11 +72,6 @@ DEFAULT_CONFIG = {
mqtt.DOMAIN: {sensor.DOMAIN: {"name": "test", "state_topic": "test-topic"}}
}
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
DEFAULT_CONFIG_LEGACY = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
DEFAULT_CONFIG_LEGACY[sensor.DOMAIN]["platform"] = mqtt.DOMAIN
@pytest.fixture(autouse=True)
def sensor_platform_only():
@ -1110,15 +1104,6 @@ async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_pa
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup."""
domain = sensor.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain]
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
async def test_cleanup_triggers_and_restoring_state(
hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, freezer
):
@ -1258,16 +1243,3 @@ async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_setup_with_legacy_schema(hass, mqtt_mock_entry_with_yaml_config):
"""Test a setup with deprecated yaml platform schema."""
domain = sensor.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain])
config["name"] = "test"
assert await async_setup_component(hass, domain, {domain: config})
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
assert hass.states.get(f"{domain}.test") is not None

View File

@ -39,7 +39,6 @@ from .test_common import (
help_test_entity_id_update_subscriptions,
help_test_publishing_with_custom_encoding,
help_test_reloadable,
help_test_reloadable_late,
help_test_setting_attribute_via_mqtt_json_message,
help_test_setting_attribute_with_template,
help_test_setting_blocked_attribute_via_mqtt_json_message,
@ -56,11 +55,6 @@ DEFAULT_CONFIG = {
mqtt.DOMAIN: {siren.DOMAIN: {"name": "test", "command_topic": "test-topic"}}
}
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
DEFAULT_CONFIG_LEGACY = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
DEFAULT_CONFIG_LEGACY[siren.DOMAIN]["platform"] = mqtt.DOMAIN
@pytest.fixture(autouse=True)
def siren_platform_only():
@ -954,15 +948,6 @@ async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_pa
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup."""
domain = siren.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain]
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
@pytest.mark.parametrize(
"topic,value,attribute,attribute_value",
[
@ -1006,16 +991,3 @@ async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_setup_with_legacy_schema(hass, mqtt_mock_entry_with_yaml_config):
"""Test a setup with deprecated yaml platform schema."""
domain = siren.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain])
config["name"] = "test"
assert await async_setup_component(hass, domain, {domain: config})
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
assert hass.states.get(f"{domain}.test") is not None

View File

@ -26,13 +26,7 @@ from homeassistant.components.vacuum import (
STATE_CLEANING,
STATE_DOCKED,
)
from homeassistant.const import (
CONF_NAME,
CONF_PLATFORM,
ENTITY_MATCH_ALL,
STATE_UNKNOWN,
Platform,
)
from homeassistant.const import CONF_NAME, ENTITY_MATCH_ALL, STATE_UNKNOWN, Platform
from homeassistant.setup import async_setup_component
from .test_common import (
@ -55,7 +49,6 @@ from .test_common import (
help_test_entity_id_update_subscriptions,
help_test_publishing_with_custom_encoding,
help_test_reloadable,
help_test_reloadable_late,
help_test_setting_attribute_via_mqtt_json_message,
help_test_setting_attribute_with_template,
help_test_setting_blocked_attribute_via_mqtt_json_message,
@ -88,13 +81,6 @@ DEFAULT_CONFIG = {
DEFAULT_CONFIG_2 = {mqtt.DOMAIN: {vacuum.DOMAIN: {"schema": "state", "name": "test"}}}
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
DEFAULT_CONFIG_LEGACY = deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
DEFAULT_CONFIG_LEGACY[vacuum.DOMAIN][CONF_PLATFORM] = mqtt.DOMAIN
DEFAULT_CONFIG_2_LEGACY = deepcopy(DEFAULT_CONFIG_2[mqtt.DOMAIN])
DEFAULT_CONFIG_2_LEGACY[vacuum.DOMAIN][CONF_PLATFORM] = mqtt.DOMAIN
@pytest.fixture(autouse=True)
def vacuum_platform_only():
@ -680,15 +666,6 @@ async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_pa
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup."""
domain = vacuum.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain]
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
@pytest.mark.parametrize(
"topic,value,attribute,attribute_value",
[
@ -735,16 +712,3 @@ async def test_setup_manual_entity_from_yaml(hass):
platform = vacuum.DOMAIN
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
assert hass.states.get(f"{platform}.mqtttest")
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_setup_with_legacy_schema(hass, mqtt_mock_entry_with_yaml_config):
"""Test a setup with deprecated yaml platform schema."""
domain = vacuum.DOMAIN
config = deepcopy(DEFAULT_CONFIG_LEGACY[domain])
config["name"] = "test"
assert await async_setup_component(hass, domain, {domain: config})
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
assert hass.states.get(f"{domain}.test") is not None

View File

@ -36,7 +36,6 @@ from .test_common import (
help_test_entity_id_update_subscriptions,
help_test_publishing_with_custom_encoding,
help_test_reloadable,
help_test_reloadable_late,
help_test_setting_attribute_via_mqtt_json_message,
help_test_setting_attribute_with_template,
help_test_setting_blocked_attribute_via_mqtt_json_message,
@ -54,11 +53,6 @@ DEFAULT_CONFIG = {
mqtt.DOMAIN: {switch.DOMAIN: {"name": "test", "command_topic": "test-topic"}}
}
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
DEFAULT_CONFIG_LEGACY = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN])
DEFAULT_CONFIG_LEGACY[switch.DOMAIN]["platform"] = mqtt.DOMAIN
@pytest.fixture(autouse=True)
def switch_platform_only():
@ -642,15 +636,6 @@ async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_pa
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
"""Test reloading the MQTT platform with late entry setup."""
domain = switch.DOMAIN
config = DEFAULT_CONFIG_LEGACY[domain]
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
@pytest.mark.parametrize(
"topic,value,attribute,attribute_value",
[
@ -694,16 +679,3 @@ async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
)
# Test deprecated YAML configuration under the platform key
# Scheduled to be removed in HA core 2022.12
async def test_setup_with_legacy_schema(hass, mqtt_mock_entry_with_yaml_config):
"""Test a setup with deprecated yaml platform schema."""
domain = switch.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG_LEGACY[domain])
config["name"] = "test"
assert await async_setup_component(hass, domain, {domain: config})
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
assert hass.states.get(f"{domain}.test") is not None

View File

@ -30,6 +30,7 @@ from .test_common import (
help_test_entity_device_info_with_connection,
help_test_entity_device_info_with_identifier,
help_test_entity_id_update_discovery_update,
help_test_reloadable,
help_test_setting_attribute_via_mqtt_json_message,
help_test_setting_attribute_with_template,
help_test_setup_manual_entity_from_yaml,
@ -527,3 +528,12 @@ async def test_unload_entry(hass, mqtt_mock_entry_with_yaml_config, tmp_path):
await help_test_unload_config_entry_with_platform(
hass, mqtt_mock_entry_with_yaml_config, tmp_path, domain, config
)
async def test_reloadable(hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path):
"""Test reloading the MQTT platform."""
domain = update.DOMAIN
config = DEFAULT_CONFIG
await help_test_reloadable(
hass, mqtt_mock_entry_with_yaml_config, caplog, tmp_path, domain, config
)