Alexa: Fix duplicate proactive reports (#74930)

This commit is contained in:
Thomas Hollstegge 2022-07-11 00:10:55 +02:00 committed by GitHub
parent 9ff77e0fa1
commit 261c52e260
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 4 deletions

View file

@ -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()

View file

@ -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):