From 4132f08146a8e269f6b288428920b183c1274a94 Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Tue, 18 Apr 2023 16:02:24 +0200 Subject: [PATCH] Remove check on remove deprecated call back for mqtt subscribe (#91464) Remove check on deprecated callback wrapper --- homeassistant/components/mqtt/client.py | 20 ------------ tests/components/mqtt/test_init.py | 41 ------------------------- 2 files changed, 61 deletions(-) diff --git a/homeassistant/components/mqtt/client.py b/homeassistant/components/mqtt/client.py index 2064594fbf0..55db1da6ff7 100644 --- a/homeassistant/components/mqtt/client.py +++ b/homeassistant/components/mqtt/client.py @@ -4,7 +4,6 @@ from __future__ import annotations import asyncio from collections.abc import Callable, Coroutine, Iterable from functools import lru_cache -import inspect from itertools import chain, groupby import logging from operator import attrgetter @@ -172,25 +171,6 @@ async def async_subscribe( f"Cannot subscribe to topic '{topic}', MQTT is not enabled" ) mqtt_data = get_mqtt_data(hass) - # Support for a deprecated callback type was removed with HA core 2023.3.0 - # The signature validation code can be removed from HA core 2023.5.0 - non_default = 0 - if msg_callback: - non_default = sum( - p.default == inspect.Parameter.empty - for _, p in inspect.signature(msg_callback).parameters.items() - ) - - # Check for not supported callback signatures - # Can be removed from HA core 2023.5.0 - if non_default != 1: - module = inspect.getmodule(msg_callback) - raise HomeAssistantError( - "Signature for MQTT msg_callback '{}.{}' is not supported".format( - module.__name__ if module else "", msg_callback.__name__ - ) - ) - async_remove = await mqtt_data.client.async_subscribe( topic, catch_log_exception( diff --git a/tests/components/mqtt/test_init.py b/tests/components/mqtt/test_init.py index 8583533bcf8..62ad74b6a09 100644 --- a/tests/components/mqtt/test_init.py +++ b/tests/components/mqtt/test_init.py @@ -32,7 +32,6 @@ from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import device_registry as dr, entity_registry as er, template from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity_platform import async_get_platforms -from homeassistant.helpers.service_info.mqtt import ReceivePayloadType from homeassistant.helpers.typing import ConfigType from homeassistant.setup import async_setup_component from homeassistant.util.dt import utcnow @@ -946,46 +945,6 @@ async def test_subscribe_bad_topic( await mqtt.async_subscribe(hass, 55, record_calls) # type: ignore[arg-type] -# Support for a deprecated callback type was removed with HA core 2023.3.0 -# Test can be removed from HA core 2023.5.0 -async def test_subscribe_with_deprecated_callback_fails( - hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator -) -> None: - """Test the subscription of a topic using deprecated callback signature fails.""" - await mqtt_mock_entry() - - async def record_calls(topic: str, payload: ReceivePayloadType, qos: int) -> None: - """Record calls.""" - - with pytest.raises(HomeAssistantError): - await mqtt.async_subscribe(hass, "test-topic", record_calls) - # Test with partial wrapper - with pytest.raises(HomeAssistantError): - await mqtt.async_subscribe(hass, "test-topic", RecordCallsPartial(record_calls)) - - -# Support for a deprecated callback type was removed with HA core 2023.3.0 -# Test can be removed from HA core 2023.5.0 -async def test_subscribe_deprecated_async_fails( - hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator -) -> None: - """Test the subscription of a topic using deprecated coroutine signature fails.""" - await mqtt_mock_entry() - - @callback - def async_record_calls(topic: str, payload: ReceivePayloadType, qos: int) -> None: - """Record calls.""" - - with pytest.raises(HomeAssistantError): - await mqtt.async_subscribe(hass, "test-topic", async_record_calls) - - # Test with partial wrapper - with pytest.raises(HomeAssistantError): - await mqtt.async_subscribe( - hass, "test-topic", RecordCallsPartial(async_record_calls) - ) - - async def test_subscribe_topic_not_match( hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator,