Skip to content

Commit

Permalink
Remove check on remove deprecated call back for mqtt subscribe (home-…
Browse files Browse the repository at this point in the history
…assistant#91464)

Remove check on deprecated callback wrapper
  • Loading branch information
jbouwh authored Apr 18, 2023
1 parent 5f7d98f commit 4132f08
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 61 deletions.
20 changes: 0 additions & 20 deletions homeassistant/components/mqtt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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
Expand Down Expand Up @@ -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(
Expand Down
41 changes: 0 additions & 41 deletions tests/components/mqtt/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 4132f08

Please sign in to comment.