Cleanups.

This commit is contained in:
Dermot Duffy
2021-11-06 14:58:53 -07:00
parent be76d5bb24
commit ac0ae9f3cb
3 changed files with 13 additions and 44 deletions
+9 -36
View File
@@ -20,7 +20,12 @@ import {
import screenfull from 'screenfull'; import screenfull from 'screenfull';
import { z } from 'zod'; import { z } from 'zod';
import { entitySchema, frigateCardConfigSchema, MenuInteraction, RawFrigateCardConfig } from './types.js'; import {
entitySchema,
frigateCardConfigSchema,
MenuInteraction,
RawFrigateCardConfig,
} from './types.js';
import type { import type {
BrowseMediaQueryParameters, BrowseMediaQueryParameters,
Entity, Entity,
@@ -58,7 +63,7 @@ import './patches/ha-hls-player.js';
import cardStyle from './scss/card.scss'; import cardStyle from './scss/card.scss';
import { ResolvedMediaCache } from './resolved-media.js'; import { ResolvedMediaCache } from './resolved-media.js';
import { BrowseMediaUtil } from './browse-media-util.js'; import { BrowseMediaUtil } from './browse-media-util.js';
import { isConfigUpgradeable } from './config-mgmt.js'; import { copyConfig, isConfigUpgradeable, upgradeConfig } from './config-mgmt.js';
/** A note on media callbacks: /** A note on media callbacks:
* *
@@ -413,14 +418,14 @@ export class FrigateCard extends LitElement {
const hint = this._getParseErrorPaths(parseResult.error); const hint = this._getParseErrorPaths(parseResult.error);
let upgradeMessage = ''; let upgradeMessage = '';
if (configUpgradeable && getLovelace().mode !== 'yaml') { if (configUpgradeable && getLovelace().mode !== 'yaml') {
upgradeMessage = `${localize('editor.upgrade_available_in_editor')}. `; upgradeMessage = `${localize('error.upgrade_available')}. `;
} }
throw new Error( throw new Error(
upgradeMessage + upgradeMessage +
`${localize('error.invalid_configuration')}: ` + `${localize('error.invalid_configuration')}: ` +
(hint.length (hint.length
? JSON.stringify(hint, null, ' ') ? JSON.stringify(hint, null, ' ')
: localize('error.invalid_configuration_no_hint')) : localize('error.invalid_configuration_no_hint')),
); );
} }
const config = parseResult.data; const config = parseResult.data;
@@ -807,13 +812,6 @@ export class FrigateCard extends LitElement {
* Master render method for the card. * Master render method for the card.
*/ */
protected render(): TemplateResult | void { protected render(): TemplateResult | void {
if (this.config.show_warning) {
return this._showWarning(localize('common.show_warning'));
}
if (this.config.show_error) {
return this._showError(localize('common.show_error'));
}
const padding = this._getAspectRatioPadding(); const padding = this._getAspectRatioPadding();
const outerStyle = {}, const outerStyle = {},
innerStyle = {}; innerStyle = {};
@@ -994,31 +992,6 @@ export class FrigateCard extends LitElement {
`; `;
} }
/**
* Show a warning card.
* @param warning The warning message.
* @returns A rendered template.
*/
private _showWarning(warning: string): TemplateResult {
return html` <hui-warning> ${warning} </hui-warning> `;
}
/**
* Show an error card.
* @param error The error message.
* @returns A rendered template.
*/
private _showError(error: string): TemplateResult {
const errorCard = document.createElement('hui-error-card');
errorCard.setConfig({
type: 'error',
error,
origConfig: this.config,
});
return html` ${errorCard} `;
}
/** /**
* Return compiled CSS styles (thus safe to use with unsafeCSS). * Return compiled CSS styles (thus safe to use with unsafeCSS).
*/ */
+2 -4
View File
@@ -1,8 +1,6 @@
{ {
"common": { "common": {
"version": "Version", "version": "Version",
"show_warning": "Show warning",
"show_error": "Show error",
"frigate_card": "Frigate card", "frigate_card": "Frigate card",
"frigate_card_description": "A Lovelace card for use with Frigate", "frigate_card_description": "A Lovelace card for use with Frigate",
"no_snapshots": "No snapshots", "no_snapshots": "No snapshots",
@@ -118,8 +116,7 @@
"dimensions_secondary": "Dimensions & shape options", "dimensions_secondary": "Dimensions & shape options",
"show_button": "Show button", "show_button": "Show button",
"upgrade": "Upgrade", "upgrade": "Upgrade",
"upgrade_available": "An automatic card configuration upgrade is available", "upgrade_available": "An automatic card configuration upgrade is available"
"upgrade_available_in_editor": "An automatic card configuration upgrade is available in the editor"
}, },
"error": { "error": {
"empty_response": "Received empty response from Home Assistant for request", "empty_response": "Received empty response from Home Assistant for request",
@@ -131,6 +128,7 @@
"no_live_camera": "The camera_entity parameter must be set and valid for this live provider", "no_live_camera": "The camera_entity parameter must be set and valid for this live provider",
"invalid_configuration": "Invalid configuration", "invalid_configuration": "Invalid configuration",
"invalid_configuration_no_hint": "No location hint available (bad or missing type?)", "invalid_configuration_no_hint": "No location hint available (bad or missing type?)",
"upgrade_available": "An automated card configuration upgrade is available, please visit the visual card editor",
"missing_webrtc": "WebRTC component not found", "missing_webrtc": "WebRTC component not found",
"no_frigate_camera_name": "Cannot autodetect Frigate camera name, you need to either set camera_entity and / or frigate.camera_name", "no_frigate_camera_name": "Cannot autodetect Frigate camera name, you need to either set camera_entity and / or frigate.camera_name",
"could_not_render_elements": "Could not render picture elements", "could_not_render_elements": "Could not render picture elements",
-2
View File
@@ -461,8 +461,6 @@ export const frigateCardConfigSchema = z.object({
// Stock lovelace card config. // Stock lovelace card config.
type: z.string(), type: z.string(),
show_warning: z.boolean().optional(),
show_error: z.boolean().optional(),
test_gui: z.boolean().optional(), test_gui: z.boolean().optional(),
}); });
export type FrigateCardConfig = z.infer<typeof frigateCardConfigSchema>; export type FrigateCardConfig = z.infer<typeof frigateCardConfigSchema>;