Add editor and migration support.

This commit is contained in:
Dermot Duffy
2024-01-21 11:30:23 -08:00
parent 278f4f372d
commit 64a909ead0
16 changed files with 385 additions and 230 deletions
+109 -39
View File
@@ -181,8 +181,13 @@ import {
CONF_VIEW_DARK_MODE,
CONF_VIEW_DEFAULT,
CONF_VIEW_SCAN,
CONF_VIEW_SCAN_ACTIONS,
CONF_VIEW_SCAN_ACTIONS_INTERACTION_MODE,
CONF_VIEW_SCAN_ACTIONS_TRIGGER,
CONF_VIEW_SCAN_ACTIONS_UNTRIGGER,
CONF_VIEW_SCAN_ENABLED,
CONF_VIEW_SCAN_TRIGGER_SHOW_STATUS,
CONF_VIEW_SCAN_FILTER_SELECTED_CAMERA,
CONF_VIEW_SCAN_SHOW_TRIGGER_STATUS,
CONF_VIEW_SCAN_UNTRIGGER_SECONDS,
CONF_VIEW_TIMEOUT_SECONDS,
CONF_VIEW_UPDATE_CYCLE_CAMERA,
@@ -237,6 +242,7 @@ const MENU_PERFORMANCE_FEATURES = 'performance.features';
const MENU_PERFORMANCE_STYLE = 'performance.style';
const MENU_TIMELINE_CONTROLS_THUMBNAILS = 'timeline.controls.thumbnails';
const MENU_VIEW_SCAN = 'scan';
const MENU_VIEW_SCAN_ACTIONS = 'scan.actions';
interface EditorOptionsSet {
icon: string;
@@ -620,6 +626,46 @@ export class FrigateCardEditor extends LitElement implements LovelaceCardEditor
},
];
protected _scanActionsInteractionModes: EditorSelectOption[] = [
{ value: '', label: '' },
{
value: 'all',
label: localize('config.view.scan.actions.interaction_modes.all'),
},
{
value: 'inactive',
label: localize('config.view.scan.actions.interaction_modes.inactive'),
},
{
value: 'active',
label: localize('config.view.scan.actions.interaction_modes.active'),
},
];
protected _scanActionsTrigger: EditorSelectOption[] = [
{ value: '', label: '' },
{
value: 'live',
label: localize('config.view.scan.actions.triggers.live'),
},
{
value: 'none',
label: localize('config.view.scan.actions.triggers.none'),
},
];
protected _scanActionsUntrigger: EditorSelectOption[] = [
{ value: '', label: '' },
{
value: 'default',
label: localize('config.view.scan.actions.untriggers.default'),
},
{
value: 'none',
label: localize('config.view.scan.actions.untriggers.none'),
},
];
public setConfig(config: RawFrigateCardConfig): void {
// Note: This does not use Zod to parse the configuration, so it may be
// partially or completely invalid. It's more useful to have a partially
@@ -876,44 +922,68 @@ export class FrigateCardEditor extends LitElement implements LovelaceCardEditor
}
protected _renderViewScanMenu(): TemplateResult {
const submenuClasses = {
submenu: true,
selected: !!this._expandedMenus[MENU_VIEW_SCAN],
};
return html`
<div class="${classMap(submenuClasses)}">
<div
class="submenu-header"
@click=${this._toggleMenu}
.domain=${MENU_VIEW_SCAN}
.key=${true}
>
<ha-icon .icon=${'mdi:target-account'}></ha-icon>
<span>${localize(`config.${CONF_VIEW_SCAN}.scan_mode`)}</span>
</div>
${this._expandedMenus[MENU_VIEW_SCAN]
? html` <div class="values">
${this._renderSwitch(
CONF_VIEW_SCAN_ENABLED,
this._defaults.view.scan.enabled,
{
label: localize(`config.${CONF_VIEW_SCAN_ENABLED}`),
},
)}
${this._renderSwitch(
CONF_VIEW_SCAN_TRIGGER_SHOW_STATUS,
this._defaults.view.scan.trigger_show_status,
{
label: localize(`config.${CONF_VIEW_SCAN_TRIGGER_SHOW_STATUS}`),
},
)}
${this._renderNumberInput(CONF_VIEW_SCAN_UNTRIGGER_SECONDS, {
default: this._defaults.view.scan.untrigger_seconds,
})}
</div>`
: ''}
</div>
`;
return this._putInSubmenu(
MENU_VIEW_SCAN,
true,
`config.${CONF_VIEW_SCAN}.editor_label`,
{ name: 'mdi:target-account' },
html`
${this._renderSwitch(CONF_VIEW_SCAN_ENABLED, this._defaults.view.scan.enabled, {
label: localize(`config.${CONF_VIEW_SCAN_ENABLED}`),
})}
${this._renderSwitch(
CONF_VIEW_SCAN_FILTER_SELECTED_CAMERA,
this._defaults.view.scan.filter_selected_camera,
{
label: localize(`config.${CONF_VIEW_SCAN_FILTER_SELECTED_CAMERA}`),
},
)}
${this._renderSwitch(
CONF_VIEW_SCAN_SHOW_TRIGGER_STATUS,
this._defaults.view.scan.show_trigger_status,
{
label: localize(`config.${CONF_VIEW_SCAN_SHOW_TRIGGER_STATUS}`),
},
)}
${this._renderNumberInput(CONF_VIEW_SCAN_UNTRIGGER_SECONDS, {
default: this._defaults.view.scan.untrigger_seconds,
})}
${this._renderOptionSelector(
CONF_VIEW_SCAN_ACTIONS_TRIGGER,
this._scanActionsTrigger,
{
label: localize('config.view.scan.actions.trigger'),
},
)}
${this._putInSubmenu(
MENU_VIEW_SCAN_ACTIONS,
true,
`config.${CONF_VIEW_SCAN_ACTIONS}.editor_label`,
{ name: 'mdi:cogs' },
html` ${this._renderOptionSelector(
CONF_VIEW_SCAN_ACTIONS_TRIGGER,
this._scanActionsTrigger,
{
label: localize('config.view.scan.actions.trigger'),
},
)}
${this._renderOptionSelector(
CONF_VIEW_SCAN_ACTIONS_UNTRIGGER,
this._scanActionsUntrigger,
{
label: localize('config.view.scan.actions.untrigger'),
},
)}
${this._renderOptionSelector(
CONF_VIEW_SCAN_ACTIONS_INTERACTION_MODE,
this._scanActionsInteractionModes,
{
label: localize('config.view.scan.actions.interaction_mode'),
},
)}`,
)}
`,
);
}
/**