Skip to content

Commit

Permalink
Workaround upstream MQTT change. (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
dermotduffy authored Feb 7, 2022
1 parent 19a10d0 commit 1778635
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions custom_components/frigate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
from awesomeversion import AwesomeVersion

from custom_components.frigate.config_flow import get_config_entry_title
from homeassistant.components.mqtt.models import ReceiveMessage
from homeassistant.components.mqtt.subscription import (
EntitySubscription,
async_subscribe_topics,
async_unsubscribe_topics,
)
Expand All @@ -30,16 +32,36 @@
from homeassistant.loader import async_get_integration
from homeassistant.util import slugify

# TODO(@dermotduffy): To be removed some safe distance from the official release of 2021.8.
# TODO(@dermotduffy): This section can be removed some safe distance from the
# official release of 2022.3 (and the contents of the first version of
# `subscribe_topics` can be moved into async_added_to_hass below).
try:
from homeassistant.components.mqtt.models import ( # pylint: disable=no-name-in-module # pragma: no cover
ReceiveMessage,
)
except ImportError: # pragma: no cover
from homeassistant.components.mqtt.models import ( # pylint: disable=no-name-in-module # pragma: no cover
Message as ReceiveMessage,
from homeassistant.components.mqtt.subscription import (
async_prepare_subscribe_topics,
)

async def subscribe_topics(
hass: HomeAssistant,
state: dict[str, EntitySubscription] | None,
topics: dict[str, Any],
) -> Any: # pragma: no cover
"""Subscribe to MQTT topic."""
state = async_prepare_subscribe_topics(hass, state, topics)
# pylint: disable=no-value-for-parameter
return await async_subscribe_topics(hass, state)


except ImportError:

async def subscribe_topics(
hass: HomeAssistant,
state: dict[str, EntitySubscription] | None,
topics: dict[str, Any],
) -> Any: # pragma: no cover
"""Subscribe to MQTT topic."""
return await async_subscribe_topics(hass, state, topics)


from .api import FrigateApiClient, FrigateApiClientError
from .const import (
ATTR_CLIENT,
Expand Down Expand Up @@ -366,7 +388,7 @@ def __init__(

async def async_added_to_hass(self) -> None:
"""Subscribe mqtt events."""
self._sub_state = await async_subscribe_topics(
self._sub_state = await subscribe_topics(
self.hass,
self._sub_state,
{
Expand Down

0 comments on commit 1778635

Please sign in to comment.