diff --git a/homeassistant/components/mqtt/__init__.py b/homeassistant/components/mqtt/__init__.py index 3f6f2122757..066f3be3736 100644 --- a/homeassistant/components/mqtt/__init__.py +++ b/homeassistant/components/mqtt/__init__.py @@ -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: diff --git a/homeassistant/components/mqtt/alarm_control_panel.py b/homeassistant/components/mqtt/alarm_control_panel.py index aa796d9ea8f..86513113281 100644 --- a/homeassistant/components/mqtt/alarm_control_panel.py +++ b/homeassistant/components/mqtt/alarm_control_panel.py @@ -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 ) diff --git a/homeassistant/components/mqtt/binary_sensor.py b/homeassistant/components/mqtt/binary_sensor.py index 5ed9fdfb76f..135151f179c 100644 --- a/homeassistant/components/mqtt/binary_sensor.py +++ b/homeassistant/components/mqtt/binary_sensor.py @@ -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 ) diff --git a/homeassistant/components/mqtt/button.py b/homeassistant/components/mqtt/button.py index d50a06a46d8..f81f78a487a 100644 --- a/homeassistant/components/mqtt/button.py +++ b/homeassistant/components/mqtt/button.py @@ -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 ) diff --git a/homeassistant/components/mqtt/camera.py b/homeassistant/components/mqtt/camera.py index 6ece232775a..b3a78f4d2ff 100644 --- a/homeassistant/components/mqtt/camera.py +++ b/homeassistant/components/mqtt/camera.py @@ -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 ) diff --git a/homeassistant/components/mqtt/client.py b/homeassistant/components/mqtt/client.py index 7dc6048f2f7..aa30c6c18af 100644 --- a/homeassistant/components/mqtt/client.py +++ b/homeassistant/components/mqtt/client.py @@ -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): diff --git a/homeassistant/components/mqtt/climate.py b/homeassistant/components/mqtt/climate.py index 99b51d2ab3e..b64e5ed08c3 100644 --- a/homeassistant/components/mqtt/climate.py +++ b/homeassistant/components/mqtt/climate.py @@ -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 ) diff --git a/homeassistant/components/mqtt/config_flow.py b/homeassistant/components/mqtt/config_flow.py index b79ff30f111..168f8b71cde 100644 --- a/homeassistant/components/mqtt/config_flow.py +++ b/homeassistant/components/mqtt/config_flow.py @@ -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 diff --git a/homeassistant/components/mqtt/config_integration.py b/homeassistant/components/mqtt/config_integration.py index 4140c5963ca..bbd6861435b 100644 --- a/homeassistant/components/mqtt/config_integration.py +++ b/homeassistant/components/mqtt/config_integration.py @@ -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] ), } ) diff --git a/homeassistant/components/mqtt/cover.py b/homeassistant/components/mqtt/cover.py index f0733af8bc3..66b8e60b561 100644 --- a/homeassistant/components/mqtt/cover.py +++ b/homeassistant/components/mqtt/cover.py @@ -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, diff --git a/homeassistant/components/mqtt/device_tracker.py b/homeassistant/components/mqtt/device_tracker.py index 92f213f4bdf..b55c3754696 100644 --- a/homeassistant/components/mqtt/device_tracker.py +++ b/homeassistant/components/mqtt/device_tracker.py @@ -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 ) diff --git a/homeassistant/components/mqtt/fan.py b/homeassistant/components/mqtt/fan.py index 61fbc4fd387..74290abb757 100644 --- a/homeassistant/components/mqtt/fan.py +++ b/homeassistant/components/mqtt/fan.py @@ -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 ) diff --git a/homeassistant/components/mqtt/humidifier.py b/homeassistant/components/mqtt/humidifier.py index ab51b0b9b45..93069791a79 100644 --- a/homeassistant/components/mqtt/humidifier.py +++ b/homeassistant/components/mqtt/humidifier.py @@ -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 ) diff --git a/homeassistant/components/mqtt/lock.py b/homeassistant/components/mqtt/lock.py index a518300b7f0..f56dba6766a 100644 --- a/homeassistant/components/mqtt/lock.py +++ b/homeassistant/components/mqtt/lock.py @@ -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 ) diff --git a/homeassistant/components/mqtt/mixins.py b/homeassistant/components/mqtt/mixins.py index 1e6e9989577..1487053bbda 100644 --- a/homeassistant/components/mqtt/mixins.py +++ b/homeassistant/components/mqtt/mixins.py @@ -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 diff --git a/homeassistant/components/mqtt/number.py b/homeassistant/components/mqtt/number.py index cef9f47f0d9..3682b19cf4e 100644 --- a/homeassistant/components/mqtt/number.py +++ b/homeassistant/components/mqtt/number.py @@ -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 ) diff --git a/homeassistant/components/mqtt/scene.py b/homeassistant/components/mqtt/scene.py index 3454102e5e0..dd7f3347845 100644 --- a/homeassistant/components/mqtt/scene.py +++ b/homeassistant/components/mqtt/scene.py @@ -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 ) diff --git a/homeassistant/components/mqtt/select.py b/homeassistant/components/mqtt/select.py index 6d07a1a5fff..b783a001f15 100644 --- a/homeassistant/components/mqtt/select.py +++ b/homeassistant/components/mqtt/select.py @@ -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 ) diff --git a/homeassistant/components/mqtt/sensor.py b/homeassistant/components/mqtt/sensor.py index dbb414921b5..656de35232b 100644 --- a/homeassistant/components/mqtt/sensor.py +++ b/homeassistant/components/mqtt/sensor.py @@ -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 diff --git a/homeassistant/components/mqtt/siren.py b/homeassistant/components/mqtt/siren.py index 13ccfdc9cb2..b1ec05aefa3 100644 --- a/homeassistant/components/mqtt/siren.py +++ b/homeassistant/components/mqtt/siren.py @@ -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] + ] diff --git a/homeassistant/components/mqtt/switch.py b/homeassistant/components/mqtt/switch.py index f3fcf30c7ea..521b08d2748 100644 --- a/homeassistant/components/mqtt/switch.py +++ b/homeassistant/components/mqtt/switch.py @@ -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 ) diff --git a/homeassistant/components/mqtt/text.py b/homeassistant/components/mqtt/text.py index 824aeb2f4c5..cc05a2d8db1 100644 --- a/homeassistant/components/mqtt/text.py +++ b/homeassistant/components/mqtt/text.py @@ -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 ) diff --git a/homeassistant/components/mqtt/update.py b/homeassistant/components/mqtt/update.py index 9ee0690b120..f0158be11d7 100644 --- a/homeassistant/components/mqtt/update.py +++ b/homeassistant/components/mqtt/update.py @@ -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 ) diff --git a/homeassistant/components/mqtt/vacuum/__init__.py b/homeassistant/components/mqtt/vacuum/__init__.py index 60f8d7a7d45..366a7dca159 100644 --- a/homeassistant/components/mqtt/vacuum/__init__.py +++ b/homeassistant/components/mqtt/vacuum/__init__.py @@ -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 ) diff --git a/homeassistant/components/mqtt/vacuum/schema_legacy.py b/homeassistant/components/mqtt/vacuum/schema_legacy.py index 94053e4fb72..39b734235a0 100644 --- a/homeassistant/components/mqtt/vacuum/schema_legacy.py +++ b/homeassistant/components/mqtt/vacuum/schema_legacy.py @@ -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 diff --git a/homeassistant/components/mqtt/vacuum/schema_state.py b/homeassistant/components/mqtt/vacuum/schema_state.py index 210e189c2fc..3a5d267a5d4 100644 --- a/homeassistant/components/mqtt/vacuum/schema_state.py +++ b/homeassistant/components/mqtt/vacuum/schema_state.py @@ -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),