Announce a deprecated callback for MQTT subscribe will stop working (#82610)

* Announce a deprecated callback will stop working

* Use 2 months grace period

* Use 2 months grace period

* Use 2 months grace period

* Add deprecation comment to tests
This commit is contained in:
Jan Bouwhuis 2022-11-25 10:22:12 +01:00 committed by GitHub
parent a4dbb9a24e
commit 01b0f4d565
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View file

@ -152,6 +152,7 @@ DeprecatedMessageCallbackTypes = Union[
] ]
# Support for a deprecated callback type will be removed from HA core 2023.2.0
def wrap_msg_callback( def wrap_msg_callback(
msg_callback: DeprecatedMessageCallbackTypes, msg_callback: DeprecatedMessageCallbackTypes,
) -> AsyncMessageCallbackType | MessageCallbackType: ) -> AsyncMessageCallbackType | MessageCallbackType:
@ -203,6 +204,7 @@ async def async_subscribe(
raise HomeAssistantError( raise HomeAssistantError(
f"Cannot subscribe to topic '{topic}', MQTT is not enabled" f"Cannot subscribe to topic '{topic}', MQTT is not enabled"
) )
# Support for a deprecated callback type will be removed from HA core 2023.2.0
# Count callback parameters which don't have a default value # Count callback parameters which don't have a default value
non_default = 0 non_default = 0
if msg_callback: if msg_callback:
@ -216,7 +218,8 @@ async def async_subscribe(
if non_default == 3: if non_default == 3:
module = inspect.getmodule(msg_callback) module = inspect.getmodule(msg_callback)
_LOGGER.warning( _LOGGER.warning(
"Signature of MQTT msg_callback '%s.%s' is deprecated", "Signature of MQTT msg_callback '%s.%s' is deprecated, "
"this will stop working with HA core 2023.2",
module.__name__ if module else "<unknown>", module.__name__ if module else "<unknown>",
msg_callback.__name__, msg_callback.__name__,
) )

View file

@ -882,6 +882,7 @@ async def test_subscribe_bad_topic(
await mqtt.async_subscribe(hass, 55, record_calls) await mqtt.async_subscribe(hass, 55, record_calls)
# Support for a deprecated callback type will be removed from HA core 2023.2.0
async def test_subscribe_deprecated(hass, mqtt_mock_entry_no_yaml_config): async def test_subscribe_deprecated(hass, mqtt_mock_entry_no_yaml_config):
"""Test the subscription of a topic using deprecated callback signature.""" """Test the subscription of a topic using deprecated callback signature."""
mqtt_mock = await mqtt_mock_entry_no_yaml_config() mqtt_mock = await mqtt_mock_entry_no_yaml_config()
@ -930,6 +931,7 @@ async def test_subscribe_deprecated(hass, mqtt_mock_entry_no_yaml_config):
assert len(calls) == 1 assert len(calls) == 1
# Support for a deprecated callback type will be removed from HA core 2023.2.0
async def test_subscribe_deprecated_async(hass, mqtt_mock_entry_no_yaml_config): async def test_subscribe_deprecated_async(hass, mqtt_mock_entry_no_yaml_config):
"""Test the subscription of a topic using deprecated coroutine signature.""" """Test the subscription of a topic using deprecated coroutine signature."""
mqtt_mock = await mqtt_mock_entry_no_yaml_config() mqtt_mock = await mqtt_mock_entry_no_yaml_config()