Add cloud preference for backup sync

This commit is contained in:
Erik 2024-11-11 13:23:52 +01:00
parent 5293fc73d8
commit b23eacc7ad
4 changed files with 18 additions and 0 deletions

View file

@ -31,6 +31,7 @@ PREF_GOOGLE_REPORT_STATE = "google_report_state"
PREF_ALEXA_ENTITY_CONFIGS = "alexa_entity_configs"
PREF_ALEXA_REPORT_STATE = "alexa_report_state"
PREF_DISABLE_2FA = "disable_2fa"
PREF_ENABLE_BACKUP_SYNC = "backup_sync_enabled"
PREF_INSTANCE_ID = "instance_id"
PREF_SHOULD_EXPOSE = "should_expose"
PREF_GOOGLE_LOCAL_WEBHOOK_ID = "google_local_webhook_id"

View file

@ -42,6 +42,7 @@ from .const import (
PREF_ALEXA_REPORT_STATE,
PREF_DISABLE_2FA,
PREF_ENABLE_ALEXA,
PREF_ENABLE_BACKUP_SYNC,
PREF_ENABLE_CLOUD_ICE_SERVERS,
PREF_ENABLE_GOOGLE,
PREF_GOOGLE_REPORT_STATE,
@ -442,6 +443,7 @@ def validate_language_voice(value: tuple[str, str]) -> tuple[str, str]:
vol.Required("type"): "cloud/update_prefs",
vol.Optional(PREF_ALEXA_REPORT_STATE): bool,
vol.Optional(PREF_ENABLE_ALEXA): bool,
vol.Optional(PREF_ENABLE_BACKUP_SYNC): bool,
vol.Optional(PREF_ENABLE_CLOUD_ICE_SERVERS): bool,
vol.Optional(PREF_ENABLE_GOOGLE): bool,
vol.Optional(PREF_GOOGLE_REPORT_STATE): bool,

View file

@ -32,6 +32,7 @@ from .const import (
PREF_CLOUD_USER,
PREF_CLOUDHOOKS,
PREF_ENABLE_ALEXA,
PREF_ENABLE_BACKUP_SYNC,
PREF_ENABLE_CLOUD_ICE_SERVERS,
PREF_ENABLE_GOOGLE,
PREF_ENABLE_REMOTE,
@ -166,6 +167,7 @@ class CloudPreferences:
alexa_enabled: bool | UndefinedType = UNDEFINED,
alexa_report_state: bool | UndefinedType = UNDEFINED,
alexa_settings_version: int | UndefinedType = UNDEFINED,
backup_sync_enabled: bool | UndefinedType = UNDEFINED,
cloud_ice_servers_enabled: bool | UndefinedType = UNDEFINED,
cloud_user: str | UndefinedType = UNDEFINED,
cloudhooks: dict[str, dict[str, str | bool]] | UndefinedType = UNDEFINED,
@ -191,6 +193,7 @@ class CloudPreferences:
(PREF_CLOUD_USER, cloud_user),
(PREF_CLOUDHOOKS, cloudhooks),
(PREF_ENABLE_ALEXA, alexa_enabled),
(PREF_ENABLE_BACKUP_SYNC, backup_sync_enabled),
(PREF_ENABLE_CLOUD_ICE_SERVERS, cloud_ice_servers_enabled),
(PREF_ENABLE_GOOGLE, google_enabled),
(PREF_ENABLE_REMOTE, remote_enabled),
@ -242,6 +245,7 @@ class CloudPreferences:
PREF_ALEXA_REPORT_STATE: self.alexa_report_state,
PREF_CLOUDHOOKS: self.cloudhooks,
PREF_ENABLE_ALEXA: self.alexa_enabled,
PREF_ENABLE_BACKUP_SYNC: self.backup_sync_enabled,
PREF_ENABLE_CLOUD_ICE_SERVERS: self.cloud_ice_servers_enabled,
PREF_ENABLE_GOOGLE: self.google_enabled,
PREF_ENABLE_REMOTE: self.remote_enabled,
@ -374,6 +378,12 @@ class CloudPreferences:
)
return cloud_ice_servers_enabled
@property
def backup_sync_enabled(self) -> bool:
"""Return if backup sync is enabled."""
backup_sync_enabled: bool = self._prefs.get(PREF_ENABLE_BACKUP_SYNC, False)
return backup_sync_enabled
async def get_cloud_user(self) -> str:
"""Return ID of Home Assistant Cloud system user."""
user = await self._load_cloud_user()
@ -419,6 +429,7 @@ class CloudPreferences:
PREF_CLOUD_USER: None,
PREF_CLOUDHOOKS: {},
PREF_ENABLE_ALEXA: True,
PREF_ENABLE_BACKUP_SYNC: True,
PREF_ENABLE_GOOGLE: True,
PREF_ENABLE_REMOTE: False,
PREF_ENABLE_CLOUD_ICE_SERVERS: True,

View file

@ -786,6 +786,7 @@ async def test_websocket_status(
"remote_enabled": False,
"cloud_ice_servers_enabled": True,
"tts_default_voice": ["en-US", "JennyNeural"],
"backup_sync_enabled": True,
},
"alexa_entities": {
"include_domains": [],
@ -905,6 +906,7 @@ async def test_websocket_update_preferences(
assert cloud.client.prefs.google_secure_devices_pin is None
assert cloud.client.prefs.remote_allow_remote_enable is True
assert cloud.client.prefs.cloud_ice_servers_enabled is True
assert cloud.client.prefs.backup_sync_enabled is True
client = await hass_ws_client(hass)
@ -917,6 +919,7 @@ async def test_websocket_update_preferences(
"tts_default_voice": ["en-GB", "RyanNeural"],
"remote_allow_remote_enable": False,
"cloud_ice_servers_enabled": False,
"backup_sync_enabled": False,
}
)
response = await client.receive_json()
@ -927,6 +930,7 @@ async def test_websocket_update_preferences(
assert cloud.client.prefs.google_secure_devices_pin == "1234"
assert cloud.client.prefs.remote_allow_remote_enable is False
assert cloud.client.prefs.cloud_ice_servers_enabled is False
assert cloud.client.prefs.backup_sync_enabled is False
assert cloud.client.prefs.tts_default_voice == ("en-GB", "RyanNeural")