Remove check on remove deprecated call back for mqtt subscribe (#91464)

Remove check on deprecated callback wrapper
pull/91612/head
Jan Bouwhuis 2023-04-18 16:02:24 +02:00 committed by GitHub
parent 5f7d98f15b
commit 4132f08146
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 0 additions and 61 deletions

View File

@ -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 "<unknown>", msg_callback.__name__
)
)
async_remove = await mqtt_data.client.async_subscribe(
topic,
catch_log_exception(

View File

@ -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,