1 """Config helpers for Alexa."""
3 from __future__
import annotations
5 from abc
import ABC, abstractmethod
15 from .const
import DOMAIN
16 from .entities
import TRANSLATION_TABLE
17 from .state_report
import async_enable_proactive_mode
19 STORE_AUTHORIZED =
"authorized"
21 _LOGGER = logging.getLogger(__name__)
25 """Hold the configuration for Alexa."""
27 _store: AlexaConfigStore
28 _unsub_proactive_report: CALLBACK_TYPE |
None =
None
30 def __init__(self, hass: HomeAssistant) ->
None:
31 """Initialize abstract config."""
34 self._on_deinitialize: list[CALLBACK_TYPE] = []
37 """Perform async initialization of config."""
43 """Remove listeners."""
44 _LOGGER.debug(
"async_deinitialize")
45 while self._on_deinitialize:
46 self._on_deinitialize.pop()()
50 """Return if config supports auth."""
55 """Return if states should be proactively reported."""
61 """Endpoint for report state."""
66 """Return config locale."""
70 """Return entity config."""
75 """Return if proactive mode is enabled."""
81 """Return an identifier for the user that represents this config."""
84 """Enable proactive mode."""
85 _LOGGER.debug(
"Enable proactive mode")
86 async
with self._enable_proactive_mode_lock:
87 if self._unsub_proactive_report
is not None:
94 """Disable proactive mode."""
95 _LOGGER.debug(
"Disable proactive mode")
102 """If an entity should be exposed."""
106 """Return the alexa ID for an entity ID."""
107 return entity_id.replace(
".",
"#").translate(TRANSLATION_TABLE)
111 """Invalidate access token."""
112 raise NotImplementedError
115 """Get an access token."""
116 raise NotImplementedError
119 """Accept a grant."""
120 raise NotImplementedError
124 """Return authorization status."""
125 return self.
_store_store.authorized
128 """Set authorization status.
130 - Set when an incoming message is received from Alexa.
131 - Unset if state reporting fails
147 """A configuration store for Alexa."""
150 _STORAGE_KEY = DOMAIN
153 """Initialize a configuration store."""
154 self.
_data_data: dict[str, Any] |
None =
None
160 """Return authorization status."""
161 assert self.
_data_data
is not None
162 return bool(self.
_data_data[STORE_AUTHORIZED])
166 """Set authorization status."""
167 if self.
_data_data
is not None and authorized != self.
_data_data[STORE_AUTHORIZED]:
168 self.
_data_data[STORE_AUTHORIZED] = authorized
172 """Load saved configuration from disk."""
176 self.
_data_data = {STORE_AUTHORIZED:
False}
bool should_report_state(self)
None async_enable_proactive_mode(self)
bool is_reporting_states(self)
None __init__(self, HomeAssistant hass)
str|URL|None endpoint(self)
_enable_proactive_mode_lock
None async_disable_proactive_mode(self)
bool should_expose(self, str entity_id)
str user_identifier(self)
str|None async_accept_grant(self, str code)
None async_invalidate_access_token(self)
None set_authorized(self, bool authorized)
dict[str, Any] entity_config(self)
None async_deinitialize(self)
str|None async_get_access_token(self)
None async_initialize(self)
str generate_alexa_id(self, str entity_id)
None set_authorized(self, bool authorized)
None __init__(self, HomeAssistant hass)
None async_load(HomeAssistant hass)
None async_delay_save(self, Callable[[], _T] data_func, float delay=0)