Code styling tweaks to the MQTT integration (#85463)
This commit is contained in:
parent
1b592e6885
commit
800b8abe39
26 changed files with 152 additions and 80 deletions
|
@ -486,7 +486,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
entity.async_remove()
|
||||
for mqtt_platform in mqtt_platforms
|
||||
for entity in mqtt_platform.entities.values()
|
||||
if not entity._discovery_data # type: ignore[attr-defined] # pylint: disable=protected-access
|
||||
# pylint: disable=protected-access
|
||||
if not entity._discovery_data # type: ignore[attr-defined]
|
||||
if mqtt_platform.config_entry
|
||||
and mqtt_platform.domain in RELOADABLE_PLATFORMS
|
||||
]
|
||||
|
@ -542,7 +543,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
mqtt_data.reload_entry = False
|
||||
reload_manual_setup = True
|
||||
|
||||
# When the entry was disabled before, reload manual set up items to enable MQTT again
|
||||
# When the entry was disabled before, reload manual set up items to enable
|
||||
# MQTT again
|
||||
if mqtt_data.reload_needed:
|
||||
mqtt_data.reload_needed = False
|
||||
reload_manual_setup = True
|
||||
|
@ -710,7 +712,8 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
|
||||
# Trigger reload manual MQTT items at entry setup
|
||||
if (mqtt_entry_status := mqtt_config_entry_enabled(hass)) is False:
|
||||
# The entry is disabled reload legacy manual items when the entry is enabled again
|
||||
# The entry is disabled reload legacy manual items when
|
||||
# the entry is enabled again
|
||||
mqtt_data.reload_needed = True
|
||||
elif mqtt_entry_status is True:
|
||||
# The entry is reloaded:
|
||||
|
|
|
@ -112,7 +112,8 @@ 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 was deprecated in HA Core 2022.6
|
||||
# Configuring MQTT alarm control panels under the alarm_control_panel platform key
|
||||
# was deprecated in HA Core 2022.6;
|
||||
# Setup for the legacy YAML format was removed in HA Core 2022.12
|
||||
PLATFORM_SCHEMA = vol.All(
|
||||
warn_for_legacy_schema(alarm.DOMAIN),
|
||||
|
@ -126,7 +127,7 @@ async def async_setup_entry(
|
|||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up MQTT alarm control panel through configuration.yaml and dynamically through MQTT discovery."""
|
||||
"""Set up MQTT alarm control panel through YAML and through MQTT discovery."""
|
||||
setup = functools.partial(
|
||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||
)
|
||||
|
|
|
@ -69,7 +69,8 @@ PLATFORM_SCHEMA_MODERN = MQTT_RO_SCHEMA.extend(
|
|||
}
|
||||
).extend(MQTT_ENTITY_COMMON_SCHEMA.schema)
|
||||
|
||||
# Configuring MQTT Binary sensors under the binary_sensor platform key was deprecated in HA Core 2022.6
|
||||
# Configuring MQTT Binary sensors under the binary_sensor platform key was deprecated in
|
||||
# HA Core 2022.6
|
||||
# Setup for the legacy YAML format was removed in HA Core 2022.12
|
||||
PLATFORM_SCHEMA = vol.All(
|
||||
warn_for_legacy_schema(binary_sensor.DOMAIN),
|
||||
|
@ -83,7 +84,7 @@ async def async_setup_entry(
|
|||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up MQTT binary sensor through configuration.yaml and dynamically through MQTT discovery."""
|
||||
"""Set up MQTT binary sensor through YAML and through MQTT discovery."""
|
||||
setup = functools.partial(
|
||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||
)
|
||||
|
|
|
@ -46,7 +46,8 @@ PLATFORM_SCHEMA_MODERN = MQTT_BASE_SCHEMA.extend(
|
|||
}
|
||||
).extend(MQTT_ENTITY_COMMON_SCHEMA.schema)
|
||||
|
||||
# Configuring MQTT Buttons under the button platform key was deprecated in HA Core 2022.6
|
||||
# Configuring MQTT Buttons under the button platform key was deprecated in
|
||||
# HA Core 2022.6
|
||||
# Setup for the legacy YAML format was removed in HA Core 2022.12
|
||||
PLATFORM_SCHEMA = vol.All(
|
||||
warn_for_legacy_schema(button.DOMAIN),
|
||||
|
@ -61,7 +62,7 @@ async def async_setup_entry(
|
|||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up MQTT button through configuration.yaml and dynamically through MQTT discovery."""
|
||||
"""Set up MQTT button through YAML and through MQTT discovery."""
|
||||
setup = functools.partial(
|
||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||
)
|
||||
|
|
|
@ -70,7 +70,7 @@ async def async_setup_entry(
|
|||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up MQTT camera through configuration.yaml and dynamically through MQTT discovery."""
|
||||
"""Set up MQTT camera through YAML and through MQTT discovery."""
|
||||
setup = functools.partial(
|
||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||
)
|
||||
|
|
|
@ -132,7 +132,8 @@ async def async_publish(
|
|||
return
|
||||
outgoing_payload = str(payload)
|
||||
if encoding != DEFAULT_ENCODING:
|
||||
# a string is encoded as utf-8 by default, other encoding requires bytes as payload
|
||||
# A string is encoded as utf-8 by default, other encoding
|
||||
# requires bytes as payload
|
||||
try:
|
||||
outgoing_payload = outgoing_payload.encode(encoding)
|
||||
except (AttributeError, LookupError, UnicodeEncodeError):
|
||||
|
|
|
@ -82,7 +82,8 @@ CONF_ACTION_TOPIC = "action_topic"
|
|||
CONF_AUX_COMMAND_TOPIC = "aux_command_topic"
|
||||
CONF_AUX_STATE_TEMPLATE = "aux_state_template"
|
||||
CONF_AUX_STATE_TOPIC = "aux_state_topic"
|
||||
# AWAY and HOLD mode topics and templates are no longer supported, support was removed with release 2022.9
|
||||
# AWAY and HOLD mode topics and templates are no longer supported,
|
||||
# support was removed with release 2022.9
|
||||
CONF_AWAY_MODE_COMMAND_TOPIC = "away_mode_command_topic"
|
||||
CONF_AWAY_MODE_STATE_TEMPLATE = "away_mode_state_template"
|
||||
CONF_AWAY_MODE_STATE_TOPIC = "away_mode_state_topic"
|
||||
|
@ -96,7 +97,8 @@ CONF_FAN_MODE_COMMAND_TOPIC = "fan_mode_command_topic"
|
|||
CONF_FAN_MODE_LIST = "fan_modes"
|
||||
CONF_FAN_MODE_STATE_TEMPLATE = "fan_mode_state_template"
|
||||
CONF_FAN_MODE_STATE_TOPIC = "fan_mode_state_topic"
|
||||
# AWAY and HOLD mode topics and templates are no longer supported, support was removed with release 2022.9
|
||||
# AWAY and HOLD mode topics and templates are no longer supported,
|
||||
# support was removed with release 2022.9
|
||||
CONF_HOLD_COMMAND_TEMPLATE = "hold_command_template"
|
||||
CONF_HOLD_COMMAND_TOPIC = "hold_command_topic"
|
||||
CONF_HOLD_STATE_TEMPLATE = "hold_state_template"
|
||||
|
@ -235,7 +237,7 @@ def valid_preset_mode_configuration(config: ConfigType) -> ConfigType:
|
|||
|
||||
|
||||
def valid_humidity_range_configuration(config: ConfigType) -> ConfigType:
|
||||
"""Validate that the target_humidity range configuration is valid, throws if it isn't."""
|
||||
"""Validate a target_humidity range configuration, throws otherwise."""
|
||||
if config[CONF_HUMIDITY_MIN] >= config[CONF_HUMIDITY_MAX]:
|
||||
raise ValueError("target_humidity_max must be > target_humidity_min")
|
||||
if config[CONF_HUMIDITY_MAX] > 100:
|
||||
|
@ -245,13 +247,18 @@ def valid_humidity_range_configuration(config: ConfigType) -> ConfigType:
|
|||
|
||||
|
||||
def valid_humidity_state_configuration(config: ConfigType) -> ConfigType:
|
||||
"""Validate that if CONF_HUMIDITY_STATE_TOPIC is set then CONF_HUMIDITY_COMMAND_TOPIC is also set."""
|
||||
"""Validate humidity state.
|
||||
|
||||
Ensure that if CONF_HUMIDITY_STATE_TOPIC is set then
|
||||
CONF_HUMIDITY_COMMAND_TOPIC is also set.
|
||||
"""
|
||||
if (
|
||||
CONF_HUMIDITY_STATE_TOPIC in config
|
||||
and CONF_HUMIDITY_COMMAND_TOPIC not in config
|
||||
):
|
||||
raise ValueError(
|
||||
f"{CONF_HUMIDITY_STATE_TOPIC} cannot be used without {CONF_HUMIDITY_COMMAND_TOPIC}"
|
||||
f"{CONF_HUMIDITY_STATE_TOPIC} cannot be used without"
|
||||
f" {CONF_HUMIDITY_COMMAND_TOPIC}"
|
||||
)
|
||||
|
||||
return config
|
||||
|
@ -312,7 +319,8 @@ _PLATFORM_SCHEMA_BASE = MQTT_BASE_SCHEMA.extend(
|
|||
vol.Optional(CONF_RETAIN, default=DEFAULT_RETAIN): cv.boolean,
|
||||
vol.Optional(CONF_ACTION_TEMPLATE): cv.template,
|
||||
vol.Optional(CONF_ACTION_TOPIC): valid_subscribe_topic,
|
||||
# CONF_PRESET_MODE_COMMAND_TOPIC and CONF_PRESET_MODES_LIST must be used together
|
||||
# CONF_PRESET_MODE_COMMAND_TOPIC and CONF_PRESET_MODES_LIST
|
||||
# must be used together
|
||||
vol.Inclusive(
|
||||
CONF_PRESET_MODE_COMMAND_TOPIC, "preset_modes"
|
||||
): valid_publish_topic,
|
||||
|
@ -353,7 +361,8 @@ _PLATFORM_SCHEMA_BASE = MQTT_BASE_SCHEMA.extend(
|
|||
PLATFORM_SCHEMA_MODERN = vol.All(
|
||||
# Support CONF_SEND_IF_OFF is removed with release 2022.9
|
||||
cv.removed(CONF_SEND_IF_OFF),
|
||||
# AWAY and HOLD mode topics and templates are no longer supported, support was removed with release 2022.9
|
||||
# AWAY and HOLD mode topics and templates are no longer supported,
|
||||
# support was removed with release 2022.9
|
||||
cv.removed(CONF_AWAY_MODE_COMMAND_TOPIC),
|
||||
cv.removed(CONF_AWAY_MODE_STATE_TEMPLATE),
|
||||
cv.removed(CONF_AWAY_MODE_STATE_TOPIC),
|
||||
|
@ -368,7 +377,8 @@ PLATFORM_SCHEMA_MODERN = vol.All(
|
|||
valid_humidity_state_configuration,
|
||||
)
|
||||
|
||||
# Configuring MQTT Climate under the climate platform key was deprecated in HA Core 2022.6
|
||||
# Configuring MQTT Climate under the climate platform key was deprecated in
|
||||
# HA Core 2022.6
|
||||
# Setup for the legacy YAML format was removed in HA Core 2022.12
|
||||
PLATFORM_SCHEMA = vol.All(
|
||||
warn_for_legacy_schema(climate.DOMAIN),
|
||||
|
@ -380,7 +390,8 @@ DISCOVERY_SCHEMA = vol.All(
|
|||
_DISCOVERY_SCHEMA_BASE,
|
||||
# Support CONF_SEND_IF_OFF is removed with release 2022.9
|
||||
cv.removed(CONF_SEND_IF_OFF),
|
||||
# AWAY and HOLD mode topics and templates are no longer supported, support was removed with release 2022.9
|
||||
# AWAY and HOLD mode topics and templates are no longer supported,
|
||||
# support was removed with release 2022.9
|
||||
cv.removed(CONF_AWAY_MODE_COMMAND_TOPIC),
|
||||
cv.removed(CONF_AWAY_MODE_STATE_TEMPLATE),
|
||||
cv.removed(CONF_AWAY_MODE_STATE_TOPIC),
|
||||
|
@ -400,7 +411,7 @@ async def async_setup_entry(
|
|||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up MQTT climate device through configuration.yaml and dynamically through MQTT discovery."""
|
||||
"""Set up MQTT climate device through YAML and through MQTT discovery."""
|
||||
setup = functools.partial(
|
||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||
)
|
||||
|
|
|
@ -589,7 +589,8 @@ async def async_get_broker_settings(
|
|||
current_user = current_config.get(CONF_USERNAME)
|
||||
current_pass = current_config.get(CONF_PASSWORD)
|
||||
|
||||
# Treat the previous post as an update of the current settings (if there was a basic broker setup step)
|
||||
# Treat the previous post as an update of the current settings
|
||||
# (if there was a basic broker setup step)
|
||||
current_config.update(user_input_basic)
|
||||
|
||||
# Get default settings for advanced broker options
|
||||
|
|
|
@ -81,64 +81,84 @@ DEFAULT_VALUES = {
|
|||
PLATFORM_CONFIG_SCHEMA_BASE = vol.Schema(
|
||||
{
|
||||
Platform.ALARM_CONTROL_PANEL.value: vol.All(
|
||||
cv.ensure_list, [alarm_control_panel_platform.PLATFORM_SCHEMA_MODERN] # type: ignore[has-type]
|
||||
cv.ensure_list,
|
||||
[alarm_control_panel_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type] # noqa: E501
|
||||
),
|
||||
Platform.BINARY_SENSOR.value: vol.All(
|
||||
cv.ensure_list, [binary_sensor_platform.PLATFORM_SCHEMA_MODERN] # type: ignore[has-type]
|
||||
cv.ensure_list,
|
||||
[binary_sensor_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||
),
|
||||
Platform.BUTTON.value: vol.All(
|
||||
cv.ensure_list, [button_platform.PLATFORM_SCHEMA_MODERN] # type: ignore[has-type]
|
||||
cv.ensure_list,
|
||||
[button_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||
),
|
||||
Platform.CAMERA.value: vol.All(
|
||||
cv.ensure_list, [camera_platform.PLATFORM_SCHEMA_MODERN] # type: ignore[has-type]
|
||||
cv.ensure_list,
|
||||
[camera_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||
),
|
||||
Platform.CLIMATE.value: vol.All(
|
||||
cv.ensure_list, [climate_platform.PLATFORM_SCHEMA_MODERN] # type: ignore[has-type]
|
||||
cv.ensure_list,
|
||||
[climate_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||
),
|
||||
Platform.COVER.value: vol.All(
|
||||
cv.ensure_list, [cover_platform.PLATFORM_SCHEMA_MODERN] # type: ignore[has-type]
|
||||
cv.ensure_list,
|
||||
[cover_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||
),
|
||||
Platform.DEVICE_TRACKER.value: vol.All(
|
||||
cv.ensure_list, [device_tracker_platform.PLATFORM_SCHEMA_MODERN] # type: ignore[has-type]
|
||||
cv.ensure_list,
|
||||
[device_tracker_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||
),
|
||||
Platform.FAN.value: vol.All(
|
||||
cv.ensure_list, [fan_platform.PLATFORM_SCHEMA_MODERN] # type: ignore[has-type]
|
||||
cv.ensure_list,
|
||||
[fan_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||
),
|
||||
Platform.HUMIDIFIER.value: vol.All(
|
||||
cv.ensure_list, [humidifier_platform.PLATFORM_SCHEMA_MODERN] # type: ignore[has-type]
|
||||
cv.ensure_list,
|
||||
[humidifier_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||
),
|
||||
Platform.LOCK.value: vol.All(
|
||||
cv.ensure_list, [lock_platform.PLATFORM_SCHEMA_MODERN] # type: ignore[has-type]
|
||||
cv.ensure_list,
|
||||
[lock_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||
),
|
||||
Platform.LIGHT.value: vol.All(
|
||||
cv.ensure_list, [light_platform.PLATFORM_SCHEMA_MODERN] # type: ignore[has-type]
|
||||
cv.ensure_list,
|
||||
[light_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||
),
|
||||
Platform.NUMBER.value: vol.All(
|
||||
cv.ensure_list, [number_platform.PLATFORM_SCHEMA_MODERN] # type: ignore[has-type]
|
||||
cv.ensure_list,
|
||||
[number_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||
),
|
||||
Platform.SCENE.value: vol.All(
|
||||
cv.ensure_list, [scene_platform.PLATFORM_SCHEMA_MODERN] # type: ignore[has-type]
|
||||
cv.ensure_list,
|
||||
[scene_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||
),
|
||||
Platform.SELECT.value: vol.All(
|
||||
cv.ensure_list, [select_platform.PLATFORM_SCHEMA_MODERN] # type: ignore[has-type]
|
||||
cv.ensure_list,
|
||||
[select_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||
),
|
||||
Platform.SENSOR.value: vol.All(
|
||||
cv.ensure_list, [sensor_platform.PLATFORM_SCHEMA_MODERN] # type: ignore[has-type]
|
||||
cv.ensure_list,
|
||||
[sensor_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||
),
|
||||
Platform.SIREN.value: vol.All(
|
||||
cv.ensure_list, [siren_platform.PLATFORM_SCHEMA_MODERN] # type: ignore[has-type]
|
||||
cv.ensure_list,
|
||||
[siren_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||
),
|
||||
Platform.SWITCH.value: vol.All(
|
||||
cv.ensure_list, [switch_platform.PLATFORM_SCHEMA_MODERN] # type: ignore[has-type]
|
||||
cv.ensure_list,
|
||||
[switch_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||
),
|
||||
Platform.TEXT.value: vol.All(
|
||||
cv.ensure_list, [text_platform.PLATFORM_SCHEMA_MODERN] # type: ignore[has-type]
|
||||
cv.ensure_list,
|
||||
[text_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||
),
|
||||
Platform.UPDATE.value: vol.All(
|
||||
cv.ensure_list, [update_platform.PLATFORM_SCHEMA_MODERN] # type: ignore[has-type]
|
||||
cv.ensure_list,
|
||||
[update_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||
),
|
||||
Platform.VACUUM.value: vol.All(
|
||||
cv.ensure_list, [vacuum_platform.PLATFORM_SCHEMA_MODERN] # type: ignore[has-type]
|
||||
cv.ensure_list,
|
||||
[vacuum_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||
),
|
||||
}
|
||||
)
|
||||
|
|
|
@ -227,7 +227,7 @@ async def async_setup_entry(
|
|||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up MQTT cover through configuration.yaml and dynamically through MQTT discovery."""
|
||||
"""Set up MQTT cover through YAML and through MQTT discovery."""
|
||||
setup = functools.partial(
|
||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||
)
|
||||
|
@ -656,7 +656,8 @@ class MqttCover(MqttEntity, CoverEntity):
|
|||
tilt = kwargs[ATTR_TILT_POSITION]
|
||||
percentage_tilt = tilt
|
||||
tilt = self.find_in_range_from_percent(tilt)
|
||||
# Handover the tilt after calculated from percent would make it more consistent with receiving templates
|
||||
# Handover the tilt after calculated from percent would make it more
|
||||
# consistent with receiving templates
|
||||
variables = {
|
||||
"tilt_position": percentage_tilt,
|
||||
"entity_id": self.entity_id,
|
||||
|
|
|
@ -61,7 +61,8 @@ PLATFORM_SCHEMA_MODERN = MQTT_RO_SCHEMA.extend(
|
|||
|
||||
DISCOVERY_SCHEMA = PLATFORM_SCHEMA_MODERN.extend({}, extra=vol.REMOVE_EXTRA)
|
||||
|
||||
# Configuring MQTT Device Trackers under the device_tracker platform key was deprecated in HA Core 2022.6
|
||||
# Configuring MQTT Device Trackers under the device_tracker platform key was deprecated
|
||||
# in HA Core 2022.6
|
||||
# Setup for the legacy YAML format was removed in HA Core 2022.12
|
||||
PLATFORM_SCHEMA = vol.All(warn_for_legacy_schema(device_tracker.DOMAIN))
|
||||
|
||||
|
@ -71,7 +72,7 @@ async def async_setup_entry(
|
|||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up MQTT device_tracker through configuration.yaml and dynamically through MQTT discovery."""
|
||||
"""Set up MQTT device_tracker through YAML and through MQTT discovery."""
|
||||
setup = functools.partial(
|
||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||
)
|
||||
|
|
|
@ -136,7 +136,8 @@ _PLATFORM_SCHEMA_BASE = MQTT_RW_SCHEMA.extend(
|
|||
vol.Optional(CONF_PERCENTAGE_COMMAND_TEMPLATE): cv.template,
|
||||
vol.Optional(CONF_PERCENTAGE_STATE_TOPIC): valid_subscribe_topic,
|
||||
vol.Optional(CONF_PERCENTAGE_VALUE_TEMPLATE): cv.template,
|
||||
# CONF_PRESET_MODE_COMMAND_TOPIC and CONF_PRESET_MODES_LIST must be used together
|
||||
# CONF_PRESET_MODE_COMMAND_TOPIC and CONF_PRESET_MODES_LIST
|
||||
# must be used together
|
||||
vol.Inclusive(
|
||||
CONF_PRESET_MODE_COMMAND_TOPIC, "preset_modes"
|
||||
): valid_publish_topic,
|
||||
|
@ -194,7 +195,7 @@ async def async_setup_entry(
|
|||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up MQTT fan through configuration.yaml and dynamically through MQTT discovery."""
|
||||
"""Set up MQTT fan through YAML and through MQTT discovery."""
|
||||
setup = functools.partial(
|
||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||
)
|
||||
|
|
|
@ -101,7 +101,11 @@ def valid_mode_configuration(config: ConfigType) -> ConfigType:
|
|||
|
||||
|
||||
def valid_humidity_range_configuration(config: ConfigType) -> ConfigType:
|
||||
"""Validate that the target_humidity range configuration is valid, throws if it isn't."""
|
||||
"""Validate humidity range.
|
||||
|
||||
Ensures that the target_humidity range configuration is valid,
|
||||
throws if it isn't.
|
||||
"""
|
||||
if config[CONF_TARGET_HUMIDITY_MIN] >= config[CONF_TARGET_HUMIDITY_MAX]:
|
||||
raise ValueError("target_humidity_max must be > target_humidity_min")
|
||||
if config[CONF_TARGET_HUMIDITY_MAX] > 100:
|
||||
|
@ -147,7 +151,8 @@ _PLATFORM_SCHEMA_BASE = MQTT_RW_SCHEMA.extend(
|
|||
}
|
||||
).extend(MQTT_ENTITY_COMMON_SCHEMA.schema)
|
||||
|
||||
# Configuring MQTT Humidifiers under the humidifier platform key was deprecated in HA Core 2022.6
|
||||
# Configuring MQTT Humidifiers under the humidifier platform key was deprecated in
|
||||
# HA Core 2022.6
|
||||
# Setup for the legacy YAML format was removed in HA Core 2022.12
|
||||
PLATFORM_SCHEMA = vol.All(
|
||||
warn_for_legacy_schema(humidifier.DOMAIN),
|
||||
|
@ -171,7 +176,7 @@ async def async_setup_entry(
|
|||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up MQTT humidifier through configuration.yaml and dynamically through MQTT discovery."""
|
||||
"""Set up MQTT humidifier through YAML and through MQTT discovery."""
|
||||
setup = functools.partial(
|
||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||
)
|
||||
|
|
|
@ -82,7 +82,7 @@ async def async_setup_entry(
|
|||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up MQTT lock through configuration.yaml and dynamically through MQTT discovery."""
|
||||
"""Set up MQTT lock through YAML and through MQTT discovery."""
|
||||
setup = functools.partial(
|
||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||
)
|
||||
|
|
|
@ -264,7 +264,10 @@ def warn_for_legacy_schema(domain: str) -> Callable[[ConfigType], ConfigType]:
|
|||
severity=IssueSeverity.ERROR,
|
||||
translation_key="deprecated_yaml",
|
||||
translation_placeholders={
|
||||
"more_info_url": f"https://www.home-assistant.io/integrations/{domain}.mqtt/#new_format",
|
||||
"more_info_url": (
|
||||
"https://www.home-assistant.io"
|
||||
f"/integrations/{domain}.mqtt/#new_format"
|
||||
),
|
||||
"platform": domain,
|
||||
},
|
||||
)
|
||||
|
@ -600,7 +603,11 @@ class MqttAvailability(Entity):
|
|||
async def cleanup_device_registry(
|
||||
hass: HomeAssistant, device_id: str | None, config_entry_id: str | None
|
||||
) -> None:
|
||||
"""Remove MQTT from the device registry entry if there are no remaining entities, triggers or tags."""
|
||||
"""Clean up the device registry after MQTT removal.
|
||||
|
||||
Remove MQTT from the device registry entry if there are no remaining
|
||||
entities, triggers or tags.
|
||||
"""
|
||||
# Local import to avoid circular dependencies
|
||||
# pylint: disable-next=import-outside-toplevel
|
||||
from . import device_trigger, tag
|
||||
|
@ -649,7 +656,11 @@ def stop_discovery_updates(
|
|||
async def async_remove_discovery_payload(
|
||||
hass: HomeAssistant, discovery_data: DiscoveryInfoType
|
||||
) -> None:
|
||||
"""Clear retained discovery topic in broker to avoid rediscovery after a restart of HA."""
|
||||
"""Clear retained discovery payload.
|
||||
|
||||
Remove discovery topic in broker to avoid rediscovery
|
||||
after a restart of Home Assistant.
|
||||
"""
|
||||
discovery_topic = discovery_data[ATTR_DISCOVERY_TOPIC]
|
||||
await async_publish(hass, discovery_topic, "", retain=True)
|
||||
|
||||
|
@ -829,8 +840,9 @@ class MqttDiscoveryUpdate(Entity):
|
|||
) -> None:
|
||||
"""Remove entity's state and entity registry entry.
|
||||
|
||||
Remove entity from entity registry if it is registered, this also removes the state.
|
||||
If the entity is not in the entity registry, just remove the state.
|
||||
Remove entity from entity registry if it is registered,
|
||||
this also removes the state. If the entity is not in the entity
|
||||
registry, just remove the state.
|
||||
"""
|
||||
entity_registry = er.async_get(self.hass)
|
||||
if entity_entry := entity_registry.async_get(self.entity_id):
|
||||
|
@ -872,7 +884,8 @@ class MqttDiscoveryUpdate(Entity):
|
|||
debug_info.add_entity_discovery_data(
|
||||
self.hass, self._discovery_data, self.entity_id
|
||||
)
|
||||
# Set in case the entity has been removed and is re-added, for example when changing entity_id
|
||||
# Set in case the entity has been removed and is re-added,
|
||||
# for example when changing entity_id
|
||||
set_discovery_hash(self.hass, discovery_hash)
|
||||
self._remove_discovery_updated = async_dispatcher_connect(
|
||||
self.hass,
|
||||
|
@ -883,11 +896,12 @@ class MqttDiscoveryUpdate(Entity):
|
|||
async def async_removed_from_registry(self) -> None:
|
||||
"""Clear retained discovery topic in broker."""
|
||||
if not self._removed_from_hass and self._discovery_data is not None:
|
||||
# Stop subscribing to discovery updates to not trigger when we clear the
|
||||
# discovery topic
|
||||
# Stop subscribing to discovery updates to not trigger when we
|
||||
# clear the discovery topic
|
||||
self._cleanup_discovery_on_remove()
|
||||
|
||||
# Clear the discovery topic so the entity is not rediscovered after a restart
|
||||
# Clear the discovery topic so the entity is not
|
||||
# rediscovered after a restart
|
||||
await async_remove_discovery_payload(self.hass, self._discovery_data)
|
||||
|
||||
@callback
|
||||
|
|
|
@ -122,7 +122,7 @@ async def async_setup_entry(
|
|||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up MQTT number through configuration.yaml and dynamically through MQTT discovery."""
|
||||
"""Set up MQTT number through YAML and through MQTT discovery."""
|
||||
setup = functools.partial(
|
||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||
)
|
||||
|
|
|
@ -40,7 +40,8 @@ PLATFORM_SCHEMA_MODERN = MQTT_BASE_SCHEMA.extend(
|
|||
vol.Optional(CONF_UNIQUE_ID): cv.string,
|
||||
vol.Optional(CONF_RETAIN, default=DEFAULT_RETAIN): cv.boolean,
|
||||
vol.Optional(CONF_OBJECT_ID): cv.string,
|
||||
# CONF_ENABLED_BY_DEFAULT is not added by default because we are not using the common schema here
|
||||
# CONF_ENABLED_BY_DEFAULT is not added by default because
|
||||
# we are not using the common schema here
|
||||
vol.Optional(CONF_ENABLED_BY_DEFAULT, default=True): cv.boolean,
|
||||
}
|
||||
).extend(MQTT_AVAILABILITY_SCHEMA.schema)
|
||||
|
@ -59,7 +60,7 @@ async def async_setup_entry(
|
|||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up MQTT scene through configuration.yaml and dynamically through MQTT discovery."""
|
||||
"""Set up MQTT scene through YAML and through MQTT discovery."""
|
||||
setup = functools.partial(
|
||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||
)
|
||||
|
|
|
@ -78,7 +78,7 @@ async def async_setup_entry(
|
|||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up MQTT select through configuration.yaml and dynamically through MQTT discovery."""
|
||||
"""Set up MQTT select through YAML and through MQTT discovery."""
|
||||
setup = functools.partial(
|
||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||
)
|
||||
|
|
|
@ -114,7 +114,8 @@ PLATFORM_SCHEMA_MODERN = vol.All(
|
|||
validate_options,
|
||||
)
|
||||
|
||||
# Configuring MQTT Sensors under the sensor platform key was deprecated in HA Core 2022.6
|
||||
# Configuring MQTT Sensors under the sensor platform key was deprecated in
|
||||
# HA Core 2022.6
|
||||
PLATFORM_SCHEMA = vol.All(
|
||||
warn_for_legacy_schema(sensor.DOMAIN),
|
||||
)
|
||||
|
@ -131,7 +132,7 @@ async def async_setup_entry(
|
|||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up MQTT sensor through configuration.yaml and dynamically through MQTT discovery."""
|
||||
"""Set up MQTT sensor through YAML and through MQTT discovery."""
|
||||
setup = functools.partial(
|
||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||
)
|
||||
|
@ -248,7 +249,8 @@ class MqttSensor(MqttEntity, RestoreSensor):
|
|||
def _update_state(msg: ReceiveMessage) -> None:
|
||||
# auto-expire enabled?
|
||||
if self._expire_after is not None and self._expire_after > 0:
|
||||
# When self._expire_after is set, and we receive a message, assume device is not expired since it has to be to receive the message
|
||||
# When self._expire_after is set, and we receive a message, assume
|
||||
# device is not expired since it has to be to receive the message
|
||||
self._expired = False
|
||||
|
||||
# Reset old trigger
|
||||
|
|
|
@ -128,7 +128,7 @@ async def async_setup_entry(
|
|||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up MQTT siren through configuration.yaml and dynamically through MQTT discovery."""
|
||||
"""Set up MQTT siren through YAML and through MQTT discovery."""
|
||||
setup = functools.partial(
|
||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||
)
|
||||
|
@ -386,4 +386,6 @@ class MqttSiren(MqttEntity, SirenEntity):
|
|||
"""Update the extra siren state attributes."""
|
||||
for attribute, support in SUPPORTED_ATTRIBUTES.items():
|
||||
if self._attr_supported_features & support and attribute in data:
|
||||
self._attr_extra_state_attributes[attribute] = data[attribute] # type: ignore[literal-required]
|
||||
self._attr_extra_state_attributes[attribute] = data[
|
||||
attribute # type: ignore[literal-required]
|
||||
]
|
||||
|
|
|
@ -64,7 +64,8 @@ PLATFORM_SCHEMA_MODERN = MQTT_RW_SCHEMA.extend(
|
|||
}
|
||||
).extend(MQTT_ENTITY_COMMON_SCHEMA.schema)
|
||||
|
||||
# Configuring MQTT Switches under the switch platform key was deprecated in HA Core 2022.6
|
||||
# Configuring MQTT Switches under the switch platform key was deprecated in
|
||||
# HA Core 2022.6
|
||||
# Setup for the legacy YAML format was removed in HA Core 2022.12
|
||||
PLATFORM_SCHEMA = vol.All(
|
||||
warn_for_legacy_schema(switch.DOMAIN),
|
||||
|
@ -78,7 +79,7 @@ async def async_setup_entry(
|
|||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up MQTT switch through configuration.yaml and dynamically through MQTT discovery."""
|
||||
"""Set up MQTT switch through YAML and through MQTT discovery."""
|
||||
setup = functools.partial(
|
||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||
)
|
||||
|
|
|
@ -102,7 +102,7 @@ async def async_setup_entry(
|
|||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up MQTT text through configuration.yaml and dynamically through MQTT discovery."""
|
||||
"""Set up MQTT text through YAML and through MQTT discovery."""
|
||||
setup = functools.partial(
|
||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||
)
|
||||
|
|
|
@ -76,7 +76,7 @@ async def async_setup_entry(
|
|||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up MQTT update through configuration.yaml and dynamically through MQTT discovery."""
|
||||
"""Set up MQTT update through YAML and through MQTT discovery."""
|
||||
setup = functools.partial(
|
||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||
)
|
||||
|
|
|
@ -34,7 +34,8 @@ def validate_mqtt_vacuum_discovery(config_value: ConfigType) -> ConfigType:
|
|||
return config
|
||||
|
||||
|
||||
# Configuring MQTT Vacuums under the vacuum platform key was deprecated in HA Core 2022.6
|
||||
# Configuring MQTT Vacuums under the vacuum platform key was deprecated in
|
||||
# HA Core 2022.6
|
||||
def validate_mqtt_vacuum(config_value: ConfigType) -> ConfigType:
|
||||
"""Validate MQTT vacuum schema (deprecated)."""
|
||||
schemas = {LEGACY: PLATFORM_SCHEMA_LEGACY, STATE: PLATFORM_SCHEMA_STATE}
|
||||
|
@ -56,7 +57,8 @@ DISCOVERY_SCHEMA = vol.All(
|
|||
MQTT_VACUUM_SCHEMA.extend({}, extra=vol.ALLOW_EXTRA), validate_mqtt_vacuum_discovery
|
||||
)
|
||||
|
||||
# Configuring MQTT Vacuums under the vacuum platform key was deprecated in HA Core 2022.6
|
||||
# Configuring MQTT Vacuums under the vacuum platform key was deprecated in
|
||||
# HA Core 2022.6
|
||||
# Setup for the legacy YAML format was removed in HA Core 2022.12
|
||||
PLATFORM_SCHEMA = vol.All(
|
||||
warn_for_legacy_schema(vacuum.DOMAIN),
|
||||
|
@ -72,7 +74,7 @@ async def async_setup_entry(
|
|||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up MQTT vacuum through configuration.yaml and dynamically through MQTT discovery."""
|
||||
"""Set up MQTT vacuum through YAML and through MQTT discovery."""
|
||||
setup = functools.partial(
|
||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||
)
|
||||
|
|
|
@ -160,7 +160,8 @@ PLATFORM_SCHEMA_LEGACY_MODERN = (
|
|||
.extend(MQTT_VACUUM_SCHEMA.schema)
|
||||
)
|
||||
|
||||
# Configuring MQTT Vacuums under the vacuum platform key was deprecated in HA Core 2022.6
|
||||
# Configuring MQTT Vacuums under the vacuum platform key was deprecated in
|
||||
# HA Core 2022.6
|
||||
PLATFORM_SCHEMA_LEGACY = vol.All(
|
||||
cv.PLATFORM_SCHEMA.extend(PLATFORM_SCHEMA_LEGACY_MODERN.schema),
|
||||
warn_for_legacy_schema(VACUUM_DOMAIN),
|
||||
|
@ -413,7 +414,8 @@ class MqttVacuum(MqttEntity, VacuumEntity):
|
|||
def battery_icon(self) -> str:
|
||||
"""Return the battery icon for the vacuum cleaner.
|
||||
|
||||
No need to check VacuumEntityFeature.BATTERY, this won't be called if battery_level is None.
|
||||
No need to check VacuumEntityFeature.BATTERY, this won't be called if
|
||||
battery_level is None.
|
||||
"""
|
||||
return icon_for_battery_level(
|
||||
battery_level=self.battery_level, charging=self._charging
|
||||
|
|
|
@ -154,7 +154,8 @@ PLATFORM_SCHEMA_STATE_MODERN = (
|
|||
.extend(MQTT_VACUUM_SCHEMA.schema)
|
||||
)
|
||||
|
||||
# Configuring MQTT Vacuums under the vacuum platform key was deprecated in HA Core 2022.6
|
||||
# Configuring MQTT Vacuums under the vacuum platform key was deprecated in
|
||||
# HA Core 2022.6
|
||||
PLATFORM_SCHEMA_STATE = vol.All(
|
||||
cv.PLATFORM_SCHEMA.extend(PLATFORM_SCHEMA_STATE_MODERN.schema),
|
||||
warn_for_legacy_schema(VACUUM_DOMAIN),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue