2019-06-13 15:43:57 +00:00
|
|
|
"""Config helpers for Alexa."""
|
2020-01-14 07:33:45 +00:00
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
|
2019-08-31 01:34:40 +00:00
|
|
|
from homeassistant.core import callback
|
|
|
|
|
2019-06-17 20:50:01 +00:00
|
|
|
from .state_report import async_enable_proactive_mode
|
2019-06-13 15:43:57 +00:00
|
|
|
|
|
|
|
|
2020-01-14 07:33:45 +00:00
|
|
|
class AbstractConfig(ABC):
|
2019-06-13 15:43:57 +00:00
|
|
|
"""Hold the configuration for Alexa."""
|
|
|
|
|
2019-06-17 20:50:01 +00:00
|
|
|
_unsub_proactive_report = None
|
|
|
|
|
|
|
|
def __init__(self, hass):
|
|
|
|
"""Initialize abstract config."""
|
|
|
|
self.hass = hass
|
|
|
|
|
2019-06-13 18:58:08 +00:00
|
|
|
@property
|
|
|
|
def supports_auth(self):
|
|
|
|
"""Return if config supports auth."""
|
|
|
|
return False
|
|
|
|
|
2019-06-17 20:50:01 +00:00
|
|
|
@property
|
|
|
|
def should_report_state(self):
|
|
|
|
"""Return if states should be proactively reported."""
|
|
|
|
return False
|
|
|
|
|
2019-06-13 18:58:08 +00:00
|
|
|
@property
|
|
|
|
def endpoint(self):
|
|
|
|
"""Endpoint for report state."""
|
|
|
|
return None
|
|
|
|
|
2020-01-03 20:23:22 +00:00
|
|
|
@property
|
2020-01-14 07:33:45 +00:00
|
|
|
@abstractmethod
|
2020-01-03 20:23:22 +00:00
|
|
|
def locale(self):
|
|
|
|
"""Return config locale."""
|
|
|
|
|
2019-06-13 18:58:08 +00:00
|
|
|
@property
|
|
|
|
def entity_config(self):
|
|
|
|
"""Return entity config."""
|
|
|
|
return {}
|
|
|
|
|
2019-06-17 20:50:01 +00:00
|
|
|
@property
|
|
|
|
def is_reporting_states(self):
|
|
|
|
"""Return if proactive mode is enabled."""
|
|
|
|
return self._unsub_proactive_report is not None
|
|
|
|
|
2021-01-05 16:35:28 +00:00
|
|
|
@callback
|
|
|
|
@abstractmethod
|
|
|
|
def user_identifier(self):
|
|
|
|
"""Return an identifier for the user that represents this config."""
|
|
|
|
|
2019-06-17 20:50:01 +00:00
|
|
|
async def async_enable_proactive_mode(self):
|
|
|
|
"""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)
|
|
|
|
)
|
2019-06-25 05:04:31 +00:00
|
|
|
try:
|
|
|
|
await self._unsub_proactive_report
|
2020-02-25 00:47:15 +00:00
|
|
|
except Exception:
|
2019-06-17 20:50:01 +00:00
|
|
|
self._unsub_proactive_report = None
|
2019-06-25 05:04:31 +00:00
|
|
|
raise
|
2019-06-17 20:50:01 +00:00
|
|
|
|
|
|
|
async def async_disable_proactive_mode(self):
|
|
|
|
"""Disable proactive mode."""
|
|
|
|
unsub_func = await self._unsub_proactive_report
|
|
|
|
if unsub_func:
|
|
|
|
unsub_func()
|
|
|
|
self._unsub_proactive_report = None
|
|
|
|
|
2019-08-31 01:34:40 +00:00
|
|
|
@callback
|
2019-06-13 18:58:08 +00:00
|
|
|
def should_expose(self, entity_id):
|
|
|
|
"""If an entity should be exposed."""
|
|
|
|
# pylint: disable=no-self-use
|
|
|
|
return False
|
|
|
|
|
2019-08-31 01:34:40 +00:00
|
|
|
@callback
|
|
|
|
def async_invalidate_access_token(self):
|
|
|
|
"""Invalidate access token."""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2019-06-13 18:58:08 +00:00
|
|
|
async def async_get_access_token(self):
|
|
|
|
"""Get an access token."""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
async def async_accept_grant(self, code):
|
|
|
|
"""Accept a grant."""
|
|
|
|
raise NotImplementedError
|