diff --git a/src/editor.ts b/src/editor.ts
index 0b3fca00..6bc70ee3 100644
--- a/src/editor.ts
+++ b/src/editor.ts
@@ -17,36 +17,16 @@ import frigate_card_editor_style from './frigate-card-editor.scss'
const options = {
required: {
- icon: 'tune',
+ icon: 'cog',
name: 'Required',
secondary: 'Required options for this card to function',
show: true,
},
optional: {
- icon: 'gesture-tap-hold',
+ icon: 'tune',
name: 'Optional',
- secondary: 'Optional configuration to tune this',
+ secondary: 'Optional configuration to tweak card behavior',
show: false,
- options: {
- tap: {
- icon: 'gesture-tap',
- name: 'Tap',
- secondary: 'Set the action to perform on tap',
- show: false,
- },
- hold: {
- icon: 'gesture-tap-hold',
- name: 'Hold',
- secondary: 'Set the action to perform on hold',
- show: false,
- },
- double_tap: {
- icon: 'gesture-double-tap',
- name: 'Double Tap',
- secondary: 'Set the action to perform on double tap',
- show: false,
- },
- },
}
};
@@ -77,7 +57,11 @@ export class FrigateCardEditor extends LitElement implements LovelaceCardEditor
}
const entities = Object.keys(
this.hass.states).filter(eid => eid.substr(0, eid.indexOf('.')) === domain);
- return entities.sort();
+ entities.sort();
+
+ // Add a blank entry to unset a selection.
+ entities.unshift('');
+ return entities;
}
protected render(): TemplateResult | void {
@@ -91,8 +75,14 @@ export class FrigateCardEditor extends LitElement implements LovelaceCardEditor
// You can restrict on domain type
const camera_entities = this._getEntities('camera');
const binary_sensor_entities = this._getEntities('binary_sensor');
+
+ const webrtc_camera_entity =
+ this._config?.webrtc && (this._config?.webrtc as any).entity ?
+ (this._config?.webrtc as any).entity :
+ '';
const view_modes = {
+ "": "",
"live": "Live view",
"clips": "Clip gallery",
"snapshots": "Snapshot gallery",
@@ -100,6 +90,12 @@ export class FrigateCardEditor extends LitElement implements LovelaceCardEditor
"snapshot": "Latest snapshot",
}
+ const live_provider = {
+ "": "",
+ "frigate": "Frigate",
+ "webrtc": "WebRTC",
+ }
+
return html`
@@ -171,21 +167,49 @@ export class FrigateCardEditor extends LitElement implements LovelaceCardEditor
${Object.keys(view_modes).map(key => {
return html`
- ${view_modes[key]}
+
+ ${view_modes[key]}
`;
})}
+
+ .configValue=${'live_provider'}
+ >
+
+ ${Object.keys(live_provider).map(key => {
+ return html`
+ ${live_provider[key]}
+
+ `;
+ })}
+
+
+
+
+ ${camera_entities.map(entity => {
+ return html`
+ ${entity}
+ `;
+ })}
+
+
`
: ''
}
@@ -222,19 +246,38 @@ export class FrigateCardEditor extends LitElement implements LovelaceCardEditor
return;
}
const target = ev.target;
- if (this[`_${target.configValue}`] === target.value) {
+ let key: string = target.configValue;
+ console.log(target);
+ console.log(target.value);
+
+ if (!key) {
return;
}
- if (target.configValue) {
- if (target.value === '') {
- delete this._config[target.configValue];
- } else {
- this._config = {
- ...this._config,
- [target.configValue]: target.checked !== undefined ? target.checked : target.value,
- };
+
+ // Need to deep copy the config so cannot use Object.assign.
+ const newConfig = JSON.parse(JSON.stringify(this._config));
+ let objectTarget = newConfig;
+
+ if (key.includes('.')) {
+ const parts = key.split('.', 2);
+ const configName = parts[0];
+ if (!(configName in newConfig)) {
+ newConfig[configName] = {}
}
+ objectTarget = newConfig[configName];
+ key = parts[1];
}
+ //console.log(`Value is: ${target.value}`);
+ //return;
+
+ if (objectTarget[key] === target.value) {
+ return;
+ } else if (target.value === '') {
+ delete objectTarget[key];
+ } else {
+ objectTarget[key] = (target.checked !== undefined ? target.checked : target.value);
+ }
+ this._config = newConfig;
fireEvent(this, 'config-changed', { config: this._config });
}
diff --git a/src/types.ts b/src/types.ts
index 6cfdd311..475a1b05 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -19,7 +19,7 @@ export const frigateCardConfigSchema = z.object({
frigate_camera_name: z.string().optional(),
view_default: z.enum(["live", "clips", "clip", "snapshots", "snapshot"]).optional().default("live"),
- view_timeout: z.number().or(z.string().regex(/^\d+$/).transform(val => Number(val))),
+ view_timeout: z.number().or(z.string().regex(/^\d+$/).transform(val => Number(val))).optional(),
live_provider: z.enum(["frigate", "webrtc"]).default("frigate"),
webrtc: z.object({}).passthrough().optional(),
label: z.string().optional(),