Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions homeassistant/components/dhcp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,11 @@
async_track_state_added_domain,
async_track_time_interval,
)
from homeassistant.helpers.frame import report
from homeassistant.helpers.typing import ConfigType
from homeassistant.loader import DHCPMatcher, async_get_dhcp
from homeassistant.util.async_ import run_callback_threadsafe
from homeassistant.util.network import is_invalid, is_link_local, is_loopback

from .const import DOMAIN

if TYPE_CHECKING:
from scapy.packet import Packet
from scapy.sendrecv import AsyncSniffer
Expand All @@ -86,36 +83,6 @@ class DhcpServiceInfo(BaseServiceInfo):
hostname: str
macaddress: str

def __getitem__(self, name: str) -> Any:
"""
Enable method for compatibility reason.

Deprecated, and will be removed in version 2022.6.
"""
report(
f"accessed discovery_info['{name}'] instead of discovery_info.{name}; "
"this will fail in version 2022.6",
exclude_integrations={DOMAIN},
error_if_core=False,
)
return getattr(self, name)

def get(self, name: str, default: Any = None) -> Any:
"""
Enable method for compatibility reason.

Deprecated, and will be removed in version 2022.6.
"""
report(
f"accessed discovery_info.get('{name}') instead of discovery_info.{name}; "
"this will fail in version 2022.6",
exclude_integrations={DOMAIN},
error_if_core=False,
)
if hasattr(self, name):
return getattr(self, name)
return default


async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the dhcp component."""
Expand Down
15 changes: 0 additions & 15 deletions homeassistant/components/mqtt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
from homeassistant.helpers.device_registry import DeviceEntry
from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.frame import report
from homeassistant.helpers.typing import ConfigType, TemplateVarsType
from homeassistant.loader import bind_hass
from homeassistant.util import dt as dt_util
Expand Down Expand Up @@ -419,20 +418,6 @@ class MqttServiceInfo(BaseServiceInfo):
subscribed_topic: str
timestamp: dt.datetime

def __getitem__(self, name: str) -> Any:
"""
Allow property access by name for compatibility reason.

Deprecated, and will be removed in version 2022.6.
"""
report(
f"accessed discovery_info['{name}'] instead of discovery_info.{name}; "
"this will fail in version 2022.6",
exclude_integrations={DOMAIN},
error_if_core=False,
)
return getattr(self, name)


def publish(
hass: HomeAssistant,
Expand Down
58 changes: 0 additions & 58 deletions homeassistant/components/ssdp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from homeassistant.helpers import discovery_flow
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.event import async_track_time_interval
from homeassistant.helpers.frame import report
from homeassistant.helpers.typing import ConfigType
from homeassistant.loader import async_get_ssdp, bind_hass

Expand Down Expand Up @@ -111,63 +110,6 @@ class SsdpServiceInfo(
):
"""Prepared info from ssdp/upnp entries."""

def __getitem__(self, name: str) -> Any:
"""
Allow property access by name for compatibility reason.

Deprecated, and will be removed in version 2022.6.
"""
report(
f"accessed discovery_info['{name}'] instead of discovery_info.{name}, "
f"discovery_info.upnp['{name}'] "
f"or discovery_info.ssdp_headers['{name}']; "
"this will fail in version 2022.6",
exclude_integrations={DOMAIN},
error_if_core=False,
)
# Use a property if it is available, fallback to upnp data
if hasattr(self, name):
return getattr(self, name)
if name in self.ssdp_headers and name not in self.upnp:
return self.ssdp_headers.get(name)
return self.upnp[name]

def get(self, name: str, default: Any = None) -> Any:
"""
Enable method for compatibility reason.

Deprecated, and will be removed in version 2022.6.
"""
report(
f"accessed discovery_info.get('{name}') instead of discovery_info.{name}, "
f"discovery_info.upnp.get('{name}') "
f"or discovery_info.ssdp_headers.get('{name}'); "
"this will fail in version 2022.6",
exclude_integrations={DOMAIN},
error_if_core=False,
)
if hasattr(self, name):
return getattr(self, name)
return self.upnp.get(name, self.ssdp_headers.get(name, default))

def __contains__(self, name: str) -> bool:
"""
Enable method for compatibility reason.

Deprecated, and will be removed in version 2022.6.
"""
report(
f"accessed discovery_info.__contains__('{name}') "
f"instead of discovery_info.upnp.__contains__('{name}') "
f"or discovery_info.ssdp_headers.__contains__('{name}'); "
"this will fail in version 2022.6",
exclude_integrations={DOMAIN},
error_if_core=False,
)
if hasattr(self, name):
return getattr(self, name) is not None
return name in self.upnp or name in self.ssdp_headers


SsdpChange = Enum("SsdpChange", "ALIVE BYEBYE UPDATE")
SsdpCallback = Callable[[SsdpServiceInfo, SsdpChange], Awaitable]
Expand Down
17 changes: 1 addition & 16 deletions homeassistant/components/usb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import logging
import os
import sys
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

from serial.tools.list_ports import comports
from serial.tools.list_ports_common import ListPortInfo
Expand All @@ -20,7 +20,6 @@
from homeassistant.data_entry_flow import BaseServiceInfo
from homeassistant.helpers import discovery_flow, system_info
from homeassistant.helpers.debounce import Debouncer
from homeassistant.helpers.frame import report
from homeassistant.helpers.typing import ConfigType
from homeassistant.loader import async_get_usb

Expand All @@ -47,20 +46,6 @@ class UsbServiceInfo(BaseServiceInfo):
manufacturer: str | None
description: str | None

def __getitem__(self, name: str) -> Any:
"""
Allow property access by name for compatibility reason.

Deprecated, and will be removed in version 2022.6.
"""
report(
f"accessed discovery_info['{name}'] instead of discovery_info.{name}; "
"this will fail in version 2022.6",
exclude_integrations={DOMAIN},
error_if_core=False,
)
return getattr(self, name)


def human_readable_device_name(
device: str,
Expand Down
31 changes: 0 additions & 31 deletions homeassistant/components/zeroconf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from homeassistant.data_entry_flow import BaseServiceInfo
from homeassistant.helpers import discovery_flow
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.frame import report
from homeassistant.helpers.network import NoURLAvailableError, get_url
from homeassistant.helpers.typing import ConfigType
from homeassistant.loader import (
Expand Down Expand Up @@ -108,36 +107,6 @@ class ZeroconfServiceInfo(BaseServiceInfo):
name: str
properties: dict[str, Any]

def __getitem__(self, name: str) -> Any:
"""
Enable method for compatibility reason.

Deprecated, and will be removed in version 2022.6.
"""
report(
f"accessed discovery_info['{name}'] instead of discovery_info.{name}; "
"this will fail in version 2022.6",
exclude_integrations={DOMAIN},
error_if_core=False,
)
return getattr(self, name)

def get(self, name: str, default: Any = None) -> Any:
"""
Enable method for compatibility reason.

Deprecated, and will be removed in version 2022.6.
"""
report(
f"accessed discovery_info.get('{name}') instead of discovery_info.{name}; "
"this will fail in version 2022.6",
exclude_integrations={DOMAIN},
error_if_core=False,
)
if hasattr(self, name):
return getattr(self, name)
return default


@bind_hass
async def async_get_instance(hass: HomeAssistant) -> HaZeroconf:
Expand Down
25 changes: 0 additions & 25 deletions tests/components/dhcp/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import threading
from unittest.mock import MagicMock, patch

import pytest
from scapy import arch # pylint: disable=unused-import # noqa: F401
from scapy.error import Scapy_Exception
from scapy.layers.dhcp import DHCP
Expand Down Expand Up @@ -973,27 +972,3 @@ async def test_aiodiscover_finds_new_hosts_after_interval(hass):
hostname="connect",
macaddress="b8b7f16db533",
)


@pytest.mark.usefixtures("mock_integration_frame")
async def test_service_info_compatibility(hass, caplog):
"""Test compatibility with old-style dict.

To be removed in 2022.6
"""
discovery_info = dhcp.DhcpServiceInfo(
ip="192.168.210.56",
hostname="connect",
macaddress="b8b7f16db533",
)

with patch("homeassistant.helpers.frame._REPORTED_INTEGRATIONS", set()):
assert discovery_info["ip"] == "192.168.210.56"
assert "Detected integration that accessed discovery_info['ip']" in caplog.text

with patch("homeassistant.helpers.frame._REPORTED_INTEGRATIONS", set()):
assert discovery_info.get("ip") == "192.168.210.56"
assert "Detected integration that accessed discovery_info.get('ip')" in caplog.text

assert discovery_info.get("ip", "fallback_host") == "192.168.210.56"
assert discovery_info.get("invalid_key", "fallback_host") == "fallback_host"
20 changes: 0 additions & 20 deletions tests/components/mqtt/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -2380,26 +2380,6 @@ async def test_publish_json_from_template(hass, mqtt_mock):
assert mqtt_mock.async_publish.call_args[0][1] == test_str


@pytest.mark.usefixtures("mock_integration_frame")
async def test_service_info_compatibility(hass, caplog):
"""Test compatibility with old-style dict.

To be removed in 2022.6
"""
discovery_info = mqtt.MqttServiceInfo(
topic="tasmota/discovery/DC4F220848A2/config",
payload="",
qos=0,
retain=False,
subscribed_topic="tasmota/discovery/#",
timestamp=None,
)

with patch("homeassistant.helpers.frame._REPORTED_INTEGRATIONS", set()):
assert discovery_info["topic"] == "tasmota/discovery/DC4F220848A2/config"
assert "Detected integration that accessed discovery_info['topic']" in caplog.text


async def test_subscribe_connection_status(hass, mqtt_mock, mqtt_client_mock):
"""Test connextion status subscription."""
mqtt_connected_calls = []
Expand Down
Loading