Add automatic migration from menu condition to menu override.
This commit is contained in:
@@ -15,8 +15,10 @@ import {
|
|||||||
CONF_IMAGE_SRC,
|
CONF_IMAGE_SRC,
|
||||||
CONF_LIVE_PRELOAD,
|
CONF_LIVE_PRELOAD,
|
||||||
CONF_LIVE_PROVIDER,
|
CONF_LIVE_PROVIDER,
|
||||||
|
CONF_MENU,
|
||||||
CONF_MENU_BUTTON_SIZE,
|
CONF_MENU_BUTTON_SIZE,
|
||||||
CONF_MENU_MODE,
|
CONF_MENU_MODE,
|
||||||
|
CONF_OVERRIDES,
|
||||||
CONF_VIEW_DEFAULT,
|
CONF_VIEW_DEFAULT,
|
||||||
CONF_VIEW_TIMEOUT,
|
CONF_VIEW_TIMEOUT,
|
||||||
CONF_VIEW_UPDATE_ENTITIES,
|
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 = [
|
const UPGRADES = [
|
||||||
// v1.2.1 -> v2.0.0
|
// v1.2.1 -> v2.0.0
|
||||||
upgradeMoveTo('frigate_url', 'frigate.url'),
|
upgradeMoveTo('frigate_url', 'frigate.url'),
|
||||||
@@ -248,4 +282,5 @@ const UPGRADES = [
|
|||||||
|
|
||||||
// v2.1.0 -> v3.0.0
|
// v2.1.0 -> v3.0.0
|
||||||
upgradeToMultipleCameras(),
|
upgradeToMultipleCameras(),
|
||||||
|
updateMenuConditionToMenuOverride(),
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -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 = `${CONF_DIMENSIONS}.aspect_ratio` as const;
|
||||||
export const CONF_DIMENSIONS_ASPECT_RATIO_MODE =
|
export const CONF_DIMENSIONS_ASPECT_RATIO_MODE =
|
||||||
`${CONF_DIMENSIONS}.aspect_ratio_mode` as const;
|
`${CONF_DIMENSIONS}.aspect_ratio_mode` as const;
|
||||||
|
|
||||||
|
export const CONF_OVERRIDES = 'overrides' as const;
|
||||||
Reference in New Issue
Block a user