diff --git a/src/card.ts b/src/card.ts index 8f57cd9d..74ba6c81 100644 --- a/src/card.ts +++ b/src/card.ts @@ -63,6 +63,7 @@ import { MediaShowInfo, MEDIA_TYPE_IMAGE, MEDIA_TYPE_VIDEO, + MESSAGE_TYPE_PRIORITIES, MenuButton, Message, RawFrigateCardConfig, @@ -1115,7 +1116,7 @@ export class FrigateCard extends LitElement { { message: localize('error.reconnecting'), icon: 'mdi:lan-disconnect', - type: 'info', + type: 'connection', dotdotdot: true, }, true, @@ -1403,7 +1404,7 @@ export class FrigateCard extends LitElement { this._setMessageAndUpdate({ message: localize('error.diagnostics'), - type: 'info', + type: 'diagnostics', icon: 'mdi:information', context: { ha_version: this._hass.config.version, @@ -1562,8 +1563,12 @@ export class FrigateCard extends LitElement { * @param skipUpdate If true an update request is skipped. */ protected _setMessageAndUpdate(message: Message, skipUpdate?: boolean): void { - // Register the first message, or prioritize errors if there's pre-render competition. - if (!this._message || (message.type == 'error' && this._message.type != 'error')) { + const currentPriority = this._message + ? MESSAGE_TYPE_PRIORITIES[this._message.type] ?? 0 + : 0; + const newPriority = MESSAGE_TYPE_PRIORITIES[message.type] ?? 0; + + if (!this._message || newPriority >= currentPriority) { this._message = message; if (!skipUpdate) { this.requestUpdate(); @@ -1650,14 +1655,12 @@ export class FrigateCard extends LitElement { // - Aspect ratio enforcement is disabled. // - Aspect ratio enforcement is dynamic and it's a media view (i.e. not the // gallery) or timeline. - // - There is a message to display to the user. return !( (screenfull.isEnabled && screenfull.isFullscreen) || aspectRatioMode == 'unconstrained' || (aspectRatioMode == 'dynamic' && - (this._view?.isAnyMediaView() || this._view?.is('timeline'))) || - this._message != null + (this._view?.isAnyMediaView() || this._view?.is('timeline'))) ); } diff --git a/src/components/image.ts b/src/components/image.ts index d11f4260..ba21b97e 100644 --- a/src/components/image.ts +++ b/src/components/image.ts @@ -237,7 +237,7 @@ export class FrigateCardImage extends LitElement { dispatchErrorMessageEvent( this, localize('error.image_load_error'), - this.imageConfig, + { context: this.imageConfig }, ); } }} diff --git a/src/components/live.ts b/src/components/live.ts index 5eea9682..c017d908 100644 --- a/src/components/live.ts +++ b/src/components/live.ts @@ -15,7 +15,7 @@ import { customElement, property, state } from 'lit/decorators.js'; import { createRef, Ref, ref } from 'lit/directives/ref.js'; import { until } from 'lit/directives/until.js'; import { ConditionState, getOverriddenConfig } from '../card-condition.js'; -import { renderProgressIndicator } from '../components/message.js'; +import { dispatchFrigateCardErrorEvent, renderProgressIndicator } from '../components/message.js'; import { localize } from '../localize/localize.js'; import liveFrigateStyle from '../scss/live-frigate.scss'; import liveJSMPEGStyle from '../scss/live-jsmpeg.scss'; @@ -751,7 +751,7 @@ export class FrigateCardLiveFrigate extends LitElement { return dispatchErrorMessageEvent( this, localize('error.no_live_camera'), - this.cameraConfig, + { context: this.cameraConfig }, ); } @@ -760,7 +760,7 @@ export class FrigateCardLiveFrigate extends LitElement { return dispatchErrorMessageEvent( this, localize('error.live_camera_unavailable'), - this.cameraConfig, + { context: this.cameraConfig }, ); } @@ -906,7 +906,7 @@ export class FrigateCardLiveWebRTCCard extends LitElement { e instanceof FrigateCardError ? e.message : localize('error.webrtc_card_reported_error') + ': ' + (e as Error).message, - (e as FrigateCardError).context, + { context: (e as FrigateCardError).context }, ); } if (webrtcElement) { @@ -924,7 +924,7 @@ export class FrigateCardLiveWebRTCCard extends LitElement { return html`${this._webrtcTask.render({ initial: () => renderProgressIndicator(localize('error.webrtc_card_waiting')), pending: () => renderProgressIndicator(localize('error.webrtc_card_waiting')), - error: (e: unknown) => dispatchErrorMessageEvent(this, (e as Error).message), + error: (e: unknown) => dispatchFrigateCardErrorEvent(this, e as Error), complete: () => render(), })}`; } @@ -1147,7 +1147,7 @@ export class FrigateCardLiveJSMPEG extends LitElement { return dispatchErrorMessageEvent( this, localize('error.no_camera_name'), - this.cameraConfig, + { context: this.cameraConfig }, ); } diff --git a/src/components/message.ts b/src/components/message.ts index e4f21fa5..6130eada 100644 --- a/src/components/message.ts +++ b/src/components/message.ts @@ -1,9 +1,10 @@ import { CSSResultGroup, html, LitElement, TemplateResult, unsafeCSS } from 'lit'; import { customElement, property } from 'lit/decorators.js'; +import { classMap } from 'lit/directives/class-map.js'; import { TROUBLESHOOTING_URL } from '../const.js'; import { localize } from '../localize/localize.js'; import messageStyle from '../scss/message.scss'; -import { FrigateCardError, Message } from '../types.js'; +import { FrigateCardError, Message, MessageType } from '../types.js'; import { dispatchFrigateCardEvent } from '../utils/basic.js'; @customElement('frigate-card-message') @@ -23,14 +24,18 @@ export class FrigateCardMessage extends LitElement { // Render the menu. protected render(): TemplateResult { const icon = this.icon ? this.icon : 'mdi:information-outline'; + const classes = { + dotdotdot: !!this.dotdotdot, + }; return html`