From 05bd547645386fa3cc75f6b9b86b9b4912979533 Mon Sep 17 00:00:00 2001 From: Dermot Duffy Date: Sat, 8 Jan 2022 19:49:23 -0800 Subject: [PATCH] Add automatic migration from menu condition to menu override. --- src/config-mgmt.ts | 35 +++++++++++++++++++++++++++++++++++ src/const.ts | 2 ++ 2 files changed, 37 insertions(+) diff --git a/src/config-mgmt.ts b/src/config-mgmt.ts index 0dc2562d..672498e7 100644 --- a/src/config-mgmt.ts +++ b/src/config-mgmt.ts @@ -15,8 +15,10 @@ import { CONF_IMAGE_SRC, CONF_LIVE_PRELOAD, CONF_LIVE_PROVIDER, + CONF_MENU, CONF_MENU_BUTTON_SIZE, CONF_MENU_MODE, + CONF_OVERRIDES, CONF_VIEW_DEFAULT, CONF_VIEW_TIMEOUT, CONF_VIEW_UPDATE_ENTITIES, @@ -223,6 +225,38 @@ const upgradeToMultipleCameras = (): ((obj: RawFrigateCardConfig) => boolean) => }; }; +/** + * Upgrade from a condition on the menu (to allow rendering) to a menu mode + * override instead. + * @param key A string key. + * @returns A safe key. + */ + const updateMenuConditionToMenuOverride = (): ((obj: RawFrigateCardConfig) => boolean) => { + return function (obj: RawFrigateCardConfig): boolean { + const menuConditions = getConfigValue(obj, `${CONF_MENU}.conditions`) as RawFrigateCardConfig; + + if (menuConditions === undefined) { + return false; + } + + const overrides = getConfigValue(obj, `${CONF_OVERRIDES}`) as RawFrigateCardConfigArray || []; + setConfigValue( + obj, + `${CONF_OVERRIDES}.[${overrides.length}]`, + { + conditions: menuConditions, + overrides: { + menu: { + mode: 'none' + } + } + } + ); + deleteConfigValue(obj, `${CONF_MENU}.conditions`); + return true; + }; +}; + const UPGRADES = [ // v1.2.1 -> v2.0.0 upgradeMoveTo('frigate_url', 'frigate.url'), @@ -248,4 +282,5 @@ const UPGRADES = [ // v2.1.0 -> v3.0.0 upgradeToMultipleCameras(), + updateMenuConditionToMenuOverride(), ]; diff --git a/src/const.ts b/src/const.ts index 93e42ad9..1c53b912 100644 --- a/src/const.ts +++ b/src/const.ts @@ -78,3 +78,5 @@ export const CONF_DIMENSIONS = 'dimensions' as const; export const CONF_DIMENSIONS_ASPECT_RATIO = `${CONF_DIMENSIONS}.aspect_ratio` as const; export const CONF_DIMENSIONS_ASPECT_RATIO_MODE = `${CONF_DIMENSIONS}.aspect_ratio_mode` as const; + +export const CONF_OVERRIDES = 'overrides' as const; \ No newline at end of file