Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions homeassistant/components/mqtt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ async def _reload_config(call: ServiceCall) -> None:
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
]
Expand Down Expand Up @@ -542,7 +543,8 @@ async def async_forward_entry_setup_and_setup_discovery(
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
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/mqtt/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@
}
).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),
Expand All @@ -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
)
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/mqtt/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
}
).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),
Expand All @@ -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
)
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/mqtt/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
}
).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),
Expand All @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/mqtt/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/mqtt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
31 changes: 21 additions & 10 deletions homeassistant/components/mqtt/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
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"
Expand All @@ -96,7 +97,8 @@
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"
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -312,7 +319,8 @@ def valid_humidity_state_configuration(config: ConfigType) -> ConfigType:
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,
Expand Down Expand Up @@ -353,7 +361,8 @@ def valid_humidity_state_configuration(config: ConfigType) -> ConfigType:
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),
Expand All @@ -368,7 +377,8 @@ def valid_humidity_state_configuration(config: ConfigType) -> ConfigType:
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),
Expand All @@ -380,7 +390,8 @@ def valid_humidity_state_configuration(config: ConfigType) -> ConfigType:
_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),
Expand All @@ -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
)
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/mqtt/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,8 @@ async def _async_validate_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
Expand Down
60 changes: 40 additions & 20 deletions homeassistant/components/mqtt/config_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,64 +81,84 @@
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]
),
}
)
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/mqtt/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -656,7 +656,8 @@ async def async_set_cover_tilt_position(self, **kwargs: Any) -> None:
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,
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/mqtt/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@

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))

Expand All @@ -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
)
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/mqtt/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ def valid_preset_mode_configuration(config: ConfigType) -> ConfigType:
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,
Expand Down Expand Up @@ -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
)
Expand Down
Loading