Move manual configuration of MQTT climate to the integration key (#72251)
Add climate Co-authored-by: Erik Montnemery <erik@montnemery.com>pull/72268/head^2
parent
d1afbbfb09
commit
e8664ce1ae
|
@ -194,6 +194,7 @@ PLATFORM_CONFIG_SCHEMA_BASE = vol.Schema(
|
|||
vol.Optional(Platform.BINARY_SENSOR.value): cv.ensure_list,
|
||||
vol.Optional(Platform.BUTTON.value): cv.ensure_list,
|
||||
vol.Optional(Platform.CAMERA.value): cv.ensure_list,
|
||||
vol.Optional(Platform.CLIMATE.value): cv.ensure_list,
|
||||
vol.Optional(Platform.FAN.value): cv.ensure_list,
|
||||
vol.Optional(Platform.LIGHT.value): cv.ensure_list,
|
||||
vol.Optional(Platform.LOCK.value): cv.ensure_list,
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
"""Support for MQTT climate devices."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import functools
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import climate
|
||||
from homeassistant.components.climate import (
|
||||
PLATFORM_SCHEMA as CLIMATE_PLATFORM_SCHEMA,
|
||||
ClimateEntity,
|
||||
)
|
||||
from homeassistant.components.climate import ClimateEntity
|
||||
from homeassistant.components.climate.const import (
|
||||
ATTR_HVAC_MODE,
|
||||
ATTR_TARGET_TEMP_HIGH,
|
||||
|
@ -46,20 +44,17 @@ import homeassistant.helpers.config_validation as cv
|
|||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import (
|
||||
MQTT_BASE_PLATFORM_SCHEMA,
|
||||
MqttCommandTemplate,
|
||||
MqttValueTemplate,
|
||||
subscription,
|
||||
)
|
||||
from . import MqttCommandTemplate, MqttValueTemplate, subscription
|
||||
from .. import mqtt
|
||||
from .const import CONF_ENCODING, CONF_QOS, CONF_RETAIN, PAYLOAD_NONE
|
||||
from .debug_info import log_messages
|
||||
from .mixins import (
|
||||
MQTT_ENTITY_COMMON_SCHEMA,
|
||||
MqttEntity,
|
||||
async_get_platform_config_from_yaml,
|
||||
async_setup_entry_helper,
|
||||
async_setup_platform_helper,
|
||||
warn_for_legacy_schema,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -237,8 +232,7 @@ def valid_preset_mode_configuration(config):
|
|||
return config
|
||||
|
||||
|
||||
SCHEMA_BASE = CLIMATE_PLATFORM_SCHEMA.extend(MQTT_BASE_PLATFORM_SCHEMA.schema)
|
||||
_PLATFORM_SCHEMA_BASE = SCHEMA_BASE.extend(
|
||||
_PLATFORM_SCHEMA_BASE = mqtt.MQTT_BASE_SCHEMA.extend(
|
||||
{
|
||||
vol.Optional(CONF_AUX_COMMAND_TOPIC): mqtt.valid_publish_topic,
|
||||
vol.Optional(CONF_AUX_STATE_TEMPLATE): cv.template,
|
||||
|
@ -330,8 +324,14 @@ _PLATFORM_SCHEMA_BASE = SCHEMA_BASE.extend(
|
|||
}
|
||||
).extend(MQTT_ENTITY_COMMON_SCHEMA.schema)
|
||||
|
||||
PLATFORM_SCHEMA = vol.All(
|
||||
PLATFORM_SCHEMA_MODERN = vol.All(
|
||||
_PLATFORM_SCHEMA_BASE,
|
||||
valid_preset_mode_configuration,
|
||||
)
|
||||
|
||||
# Configuring MQTT Climate under the climate platform key is deprecated in HA Core 2022.6
|
||||
PLATFORM_SCHEMA = vol.All(
|
||||
cv.PLATFORM_SCHEMA.extend(_PLATFORM_SCHEMA_BASE.schema),
|
||||
# CONF_SEND_IF_OFF is deprecated, support will be removed with release 2022.9
|
||||
cv.deprecated(CONF_SEND_IF_OFF),
|
||||
# AWAY and HOLD mode topics and templates are deprecated, support will be removed with release 2022.9
|
||||
|
@ -344,6 +344,7 @@ PLATFORM_SCHEMA = vol.All(
|
|||
cv.deprecated(CONF_HOLD_STATE_TOPIC),
|
||||
cv.deprecated(CONF_HOLD_LIST),
|
||||
valid_preset_mode_configuration,
|
||||
warn_for_legacy_schema(climate.DOMAIN),
|
||||
)
|
||||
|
||||
_DISCOVERY_SCHEMA_BASE = _PLATFORM_SCHEMA_BASE.extend({}, extra=vol.REMOVE_EXTRA)
|
||||
|
@ -371,7 +372,8 @@ async def async_setup_platform(
|
|||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up MQTT climate device through configuration.yaml."""
|
||||
"""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, config, async_add_entities, _async_setup_entity
|
||||
)
|
||||
|
@ -382,7 +384,17 @@ async def async_setup_entry(
|
|||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up MQTT climate device 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
|
||||
await asyncio.gather(
|
||||
*(
|
||||
_async_setup_entity(hass, async_add_entities, config, config_entry)
|
||||
for config in await async_get_platform_config_from_yaml(
|
||||
hass, climate.DOMAIN, PLATFORM_SCHEMA_MODERN
|
||||
)
|
||||
)
|
||||
)
|
||||
# setup for discovery
|
||||
setup = functools.partial(
|
||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||
)
|
||||
|
|
|
@ -53,6 +53,7 @@ from .test_common import (
|
|||
help_test_setting_attribute_via_mqtt_json_message,
|
||||
help_test_setting_attribute_with_template,
|
||||
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
||||
help_test_setup_manual_entity_from_yaml,
|
||||
help_test_unique_id,
|
||||
help_test_update_with_json_attrs_bad_JSON,
|
||||
help_test_update_with_json_attrs_not_dict,
|
||||
|
@ -1761,3 +1762,15 @@ async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
|
|||
domain = CLIMATE_DOMAIN
|
||||
config = DEFAULT_CONFIG[domain]
|
||||
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
|
||||
|
||||
|
||||
async def test_setup_manual_entity_from_yaml(hass, caplog, tmp_path):
|
||||
"""Test setup manual configured MQTT entity."""
|
||||
platform = CLIMATE_DOMAIN
|
||||
config = copy.deepcopy(DEFAULT_CONFIG[platform])
|
||||
config["name"] = "test"
|
||||
del config["platform"]
|
||||
await help_test_setup_manual_entity_from_yaml(
|
||||
hass, caplog, tmp_path, platform, config
|
||||
)
|
||||
assert hass.states.get(f"{platform}.test") is not None
|
||||
|
|
Loading…
Reference in New Issue