Skip to content
Merged
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
25 changes: 23 additions & 2 deletions homeassistant/components/mqtt/discovery.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""Support for MQTT discovery."""
import asyncio
from collections import deque
from dataclasses import dataclass
import datetime as dt
import functools
import json
import logging
import re
import time
from typing import TypedDict
from typing import Any

from homeassistant.const import CONF_DEVICE, CONF_PLATFORM
from homeassistant.core import HomeAssistant
Expand All @@ -17,6 +18,7 @@
async_dispatcher_connect,
async_dispatcher_send,
)
from homeassistant.helpers.frame import report
from homeassistant.loader import async_get_mqtt

from .. import mqtt
Expand Down Expand Up @@ -89,7 +91,8 @@ class MQTTConfig(dict):
"""Dummy class to allow adding attributes."""


class MqttServiceInfo(TypedDict):
@dataclass
class MqttServiceInfo:
"""Prepared info from mqtt entries."""

topic: str
Expand All @@ -99,6 +102,24 @@ class MqttServiceInfo(TypedDict):
subscribed_topic: str
timestamp: dt.datetime

# Used to prevent log flooding. To be removed in 2022.6
_warning_logged: bool = False

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

Deprecated, and will be removed in version 2022.6.
"""
if not self._warning_logged:
report(
f"accessed discovery_info['{name}'] instead of discovery_info.{name}; this will fail in version 2022.6",
exclude_integrations={"mqtt"},
error_if_core=False,
)
Comment on lines +115 to +119
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is ok to use WARNING (not DEBUG) straight away for usb as there is only one core component and the PRs for these are ready on my machine:

  • tasmota

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's fine

self._warning_logged = True
return getattr(self, name)


async def async_start( # noqa: C901
hass: HomeAssistant, discovery_topic, config_entry=None
Expand Down