From 261c52e26087189e45ff1eac2a70da8919b6eaef Mon Sep 17 00:00:00 2001 From: Thomas Hollstegge Date: Mon, 11 Jul 2022 00:10:55 +0200 Subject: [PATCH] Alexa: Fix duplicate proactive reports (#74930) --- homeassistant/components/alexa/config.py | 4 ++-- homeassistant/components/alexa/smart_home_http.py | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/alexa/config.py b/homeassistant/components/alexa/config.py index b6cbe6ba74b..9f51d92a229 100644 --- a/homeassistant/components/alexa/config.py +++ b/homeassistant/components/alexa/config.py @@ -65,6 +65,7 @@ class AbstractConfig(ABC): async def async_enable_proactive_mode(self): """Enable proactive mode.""" + _LOGGER.debug("Enable proactive mode") if self._unsub_proactive_report is None: self._unsub_proactive_report = self.hass.async_create_task( async_enable_proactive_mode(self.hass, self) @@ -77,6 +78,7 @@ class AbstractConfig(ABC): async def async_disable_proactive_mode(self): """Disable proactive mode.""" + _LOGGER.debug("Disable proactive mode") if unsub_func := await self._unsub_proactive_report: unsub_func() self._unsub_proactive_report = None @@ -113,7 +115,6 @@ class AbstractConfig(ABC): self._store.set_authorized(authorized) if self.should_report_state != self.is_reporting_states: if self.should_report_state: - _LOGGER.debug("Enable proactive mode") try: await self.async_enable_proactive_mode() except Exception: @@ -121,7 +122,6 @@ class AbstractConfig(ABC): self._store.set_authorized(False) raise else: - _LOGGER.debug("Disable proactive mode") await self.async_disable_proactive_mode() diff --git a/homeassistant/components/alexa/smart_home_http.py b/homeassistant/components/alexa/smart_home_http.py index 6a953a9f9d4..9be7381adb6 100644 --- a/homeassistant/components/alexa/smart_home_http.py +++ b/homeassistant/components/alexa/smart_home_http.py @@ -12,7 +12,6 @@ from .auth import Auth from .config import AbstractConfig from .const import CONF_ENDPOINT, CONF_ENTITY_CONFIG, CONF_FILTER, CONF_LOCALE from .smart_home import async_handle_message -from .state_report import async_enable_proactive_mode _LOGGER = logging.getLogger(__name__) SMART_HOME_HTTP_ENDPOINT = "/api/alexa/smart_home" @@ -104,7 +103,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> None: hass.http.register_view(SmartHomeView(smart_home_config)) if smart_home_config.should_report_state: - await async_enable_proactive_mode(hass, smart_home_config) + await smart_home_config.async_enable_proactive_mode() class SmartHomeView(HomeAssistantView):