Cloud: Add Alexa report state (#24536)
* Cloud: Add Alexa report state * Lint * Lint * Only track state changes when we are logged in
This commit is contained in:
1 parent
5ab1996d3f
commit
a02b69db38
17 files changed
+207
-33
No files matched your search
@@ -1,11 +1,15 @@
|
||||
"""Preference management for cloud."""
|
||||
from ipaddress import ip_address
|
||||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.util.logging import async_create_catching_coro
|
||||
|
||||
from .const import (
|
||||
DOMAIN, PREF_ENABLE_ALEXA, PREF_ENABLE_GOOGLE, PREF_ENABLE_REMOTE,
|
||||
PREF_GOOGLE_SECURE_DEVICES_PIN, PREF_CLOUDHOOKS, PREF_CLOUD_USER,
|
||||
PREF_GOOGLE_ENTITY_CONFIGS, PREF_OVERRIDE_NAME, PREF_DISABLE_2FA,
|
||||
PREF_ALIASES, PREF_SHOULD_EXPOSE, PREF_ALEXA_ENTITY_CONFIGS,
|
||||
PREF_ALEXA_REPORT_STATE, DEFAULT_ALEXA_REPORT_STATE,
|
||||
InvalidTrustedNetworks, InvalidTrustedProxies)
|
||||
|
||||
STORAGE_KEY = DOMAIN
|
||||
@@ -21,6 +25,7 @@ class CloudPreferences:
|
||||
self._hass = hass
|
||||
self._store = hass.helpers.storage.Store(STORAGE_VERSION, STORAGE_KEY)
|
||||
self._prefs = None
|
||||
self._listeners = []
|
||||
|
||||
async def async_initialize(self):
|
||||
"""Finish initializing the preferences."""
|
||||
@@ -40,11 +45,17 @@ class CloudPreferences:
|
||||
|
||||
self._prefs = prefs
|
||||
|
||||
@callback
|
||||
def async_listen_updates(self, listener):
|
||||
"""Listen for updates to the preferences."""
|
||||
self._listeners.append(listener)
|
||||
|
||||
async def async_update(self, *, google_enabled=_UNDEF,
|
||||
alexa_enabled=_UNDEF, remote_enabled=_UNDEF,
|
||||
google_secure_devices_pin=_UNDEF, cloudhooks=_UNDEF,
|
||||
cloud_user=_UNDEF, google_entity_configs=_UNDEF,
|
||||
alexa_entity_configs=_UNDEF):
|
||||
alexa_entity_configs=_UNDEF,
|
||||
alexa_report_state=_UNDEF):
|
||||
"""Update user preferences."""
|
||||
for key, value in (
|
||||
(PREF_ENABLE_GOOGLE, google_enabled),
|
||||
@@ -55,18 +66,26 @@ class CloudPreferences:
|
||||
(PREF_CLOUD_USER, cloud_user),
|
||||
(PREF_GOOGLE_ENTITY_CONFIGS, google_entity_configs),
|
||||
(PREF_ALEXA_ENTITY_CONFIGS, alexa_entity_configs),
|
||||
(PREF_ALEXA_REPORT_STATE, alexa_report_state),
|
||||
):
|
||||
if value is not _UNDEF:
|
||||
self._prefs[key] = value
|
||||
|
||||
if remote_enabled is True and self._has_local_trusted_network:
|
||||
self._prefs[PREF_ENABLE_REMOTE] = False
|
||||
raise InvalidTrustedNetworks
|
||||
|
||||
if remote_enabled is True and self._has_local_trusted_proxies:
|
||||
self._prefs[PREF_ENABLE_REMOTE] = False
|
||||
raise InvalidTrustedProxies
|
||||
|
||||
await self._store.async_save(self._prefs)
|
||||
|
||||
for listener in self._listeners:
|
||||
self._hass.async_create_task(
|
||||
async_create_catching_coro(listener(self))
|
||||
)
|
||||
|
||||
async def async_update_google_entity_config(
|
||||
self, *, entity_id, override_name=_UNDEF, disable_2fa=_UNDEF,
|
||||
aliases=_UNDEF, should_expose=_UNDEF):
|
||||
@@ -134,6 +153,7 @@ class CloudPreferences:
|
||||
PREF_GOOGLE_SECURE_DEVICES_PIN: self.google_secure_devices_pin,
|
||||
PREF_GOOGLE_ENTITY_CONFIGS: self.google_entity_configs,
|
||||
PREF_ALEXA_ENTITY_CONFIGS: self.alexa_entity_configs,
|
||||
PREF_ALEXA_REPORT_STATE: self.alexa_report_state,
|
||||
PREF_CLOUDHOOKS: self.cloudhooks,
|
||||
PREF_CLOUD_USER: self.cloud_user,
|
||||
}
|
||||
@@ -156,6 +176,12 @@ class CloudPreferences:
|
||||
"""Return if Alexa is enabled."""
|
||||
return self._prefs[PREF_ENABLE_ALEXA]
|
||||
|
||||
@property
|
||||
def alexa_report_state(self):
|
||||
"""Return if Alexa report state is enabled."""
|
||||
return self._prefs.get(PREF_ALEXA_REPORT_STATE,
|
||||
DEFAULT_ALEXA_REPORT_STATE)
|
||||
|
||||
@property
|
||||
def google_enabled(self):
|
||||
"""Return if Google is enabled."""
|
||||
|
||||
Reference in new issue
Block a user