Expose mediaLoaded as a conditionState.
This commit is contained in:
@@ -709,6 +709,7 @@ All variables listed are under a `conditions:` section.
|
|||||||
| `camera` | A list of camera ids in which this condition is satisfied. See [camera IDs](#camera-ids).|
|
| `camera` | A list of camera ids in which this condition is satisfied. See [camera IDs](#camera-ids).|
|
||||||
| `fullscreen` | If `true` the condition is satisfied if the card is in fullscreen mode. If `false` the condition is satisfied if the card is **NOT** in fullscreen mode.|
|
| `fullscreen` | If `true` the condition is satisfied if the card is in fullscreen mode. If `false` the condition is satisfied if the card is **NOT** in fullscreen mode.|
|
||||||
| `state` | A list of state conditions to compare with Home Assistant state. See below. |
|
| `state` | A list of state conditions to compare with Home Assistant state. See below. |
|
||||||
|
| `mediaLoaded` | If `true` the condition is satisfied if there is media load**ED** (not load**ING**) in the card (e.g. a clip, snapshot or live view). This may be used to hide controls during media loading or when a message (not media) is being displayed. Note that if `true` this condition will never be satisfied for views that do not themselves load media directly (e.g. gallery).|
|
||||||
|
|
||||||
See the [PTZ example below](#frigate-card-conditional-example) for a real-world example of how these conditions can be used.
|
See the [PTZ example below](#frigate-card-conditional-example) for a real-world example of how these conditions can be used.
|
||||||
|
|
||||||
@@ -1592,7 +1593,7 @@ elements:
|
|||||||
scene.kitchen_tv_scene:
|
scene.kitchen_tv_scene:
|
||||||
icon: mdi:television
|
icon: mdi:television
|
||||||
title: TV!
|
title: TV!
|
||||||
# Show a pig icon if the card is in the live view, in fullscreen mode and light.office_main_lights is on.
|
# Show a pig icon if the card is in the live view, in fullscreen mode, light.office_main_lights is on and the media has been loaded.
|
||||||
- type: custom:frigate-card-conditional
|
- type: custom:frigate-card-conditional
|
||||||
elements:
|
elements:
|
||||||
- type: icon
|
- type: icon
|
||||||
@@ -1611,6 +1612,7 @@ elements:
|
|||||||
- entity: light.office_main_lights
|
- entity: light.office_main_lights
|
||||||
state: on
|
state: on
|
||||||
state_not: off
|
state_not: off
|
||||||
|
mediaLoaded: true
|
||||||
```
|
```
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ export interface ConditionState {
|
|||||||
fullscreen?: boolean;
|
fullscreen?: boolean;
|
||||||
camera?: string;
|
camera?: string;
|
||||||
state?: HassEntities;
|
state?: HassEntities;
|
||||||
|
mediaLoaded?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConditionStateRequestEvent extends Event {
|
class ConditionStateRequestEvent extends Event {
|
||||||
@@ -48,6 +49,10 @@ export function evaluateCondition(
|
|||||||
state.state[stateTest.entity].state !== stateTest.state_not)));
|
state.state[stateTest.entity].state !== stateTest.state_not)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (condition?.mediaLoaded !== undefined) {
|
||||||
|
result &&=
|
||||||
|
state.mediaLoaded !== undefined && condition.mediaLoaded == state.mediaLoaded;
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-5
@@ -279,6 +279,7 @@ export class FrigateCard extends LitElement {
|
|||||||
fullscreen: screenfull.isEnabled && screenfull.isFullscreen,
|
fullscreen: screenfull.isEnabled && screenfull.isFullscreen,
|
||||||
camera: this._view?.camera,
|
camera: this._view?.camera,
|
||||||
state: this._hass?.states,
|
state: this._hass?.states,
|
||||||
|
mediaLoaded: !!this._currentMediaShowInfo,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Update the components that need the new condition state. Passed directly
|
// Update the components that need the new condition state. Passed directly
|
||||||
@@ -1640,6 +1641,7 @@ export class FrigateCard extends LitElement {
|
|||||||
this._lastValidMediaShowInfo = this._currentMediaShowInfo = mediaShowInfo;
|
this._lastValidMediaShowInfo = this._currentMediaShowInfo = mediaShowInfo;
|
||||||
|
|
||||||
// An update may be required to draw elements.
|
// An update may be required to draw elements.
|
||||||
|
this._generateConditionState();
|
||||||
this.requestUpdate();
|
this.requestUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1819,12 +1821,9 @@ export class FrigateCard extends LitElement {
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
${!renderMenuAbove ? this._renderMenu() : ''}
|
${!renderMenuAbove ? this._renderMenu() : ''}
|
||||||
${!this._message &&
|
${this._getConfig().elements
|
||||||
(!this._view?.isAnyMediaView() || this._currentMediaShowInfo) &&
|
|
||||||
this._getConfig().elements
|
|
||||||
? // Elements need to render after the main views so it can render 'on
|
? // Elements need to render after the main views so it can render 'on
|
||||||
// top', but only if the view is a non-media view or the media is
|
// top'.
|
||||||
// already loaded.
|
|
||||||
html` <frigate-card-elements
|
html` <frigate-card-elements
|
||||||
${ref(this._refElements)}
|
${ref(this._refElements)}
|
||||||
.hass=${this._hass}
|
.hass=${this._hass}
|
||||||
|
|||||||
@@ -485,6 +485,7 @@ const frigateCardConditionSchema = z.object({
|
|||||||
view: z.string().array().optional(),
|
view: z.string().array().optional(),
|
||||||
fullscreen: z.boolean().optional(),
|
fullscreen: z.boolean().optional(),
|
||||||
camera: z.string().array().optional(),
|
camera: z.string().array().optional(),
|
||||||
|
mediaLoaded: z.boolean().optional(),
|
||||||
state: stateConditions.optional(),
|
state: stateConditions.optional(),
|
||||||
});
|
});
|
||||||
export type FrigateCardCondition = z.infer<typeof frigateCardConditionSchema>;
|
export type FrigateCardCondition = z.infer<typeof frigateCardConditionSchema>;
|
||||||
|
|||||||
Reference in New Issue
Block a user