Add card-mod support.
This commit is contained in:
@@ -1202,6 +1202,37 @@ elements:
|
|||||||
|
|
||||||
<a name="card-updates"></a>
|
<a name="card-updates"></a>
|
||||||
|
|
||||||
|
### Using `card-mod` to style the card
|
||||||
|
|
||||||
|
Frigate card allows the use of
|
||||||
|
[card-mod](https://github.com/thomasloven/lovelace-card-mod) to style arbitrary
|
||||||
|
card contents. `card-mod` can be complex to use and relies on the underlying
|
||||||
|
"internal" DOM structure to style elements -- as such, while its use is possible
|
||||||
|
it's not officially supported and no attempt is made to preserve backwards
|
||||||
|
compatability of the internal DOM between any versions. It'll look good, but you're on your own!
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Expand: Use card-mod to style a Picture elements label</summary>
|
||||||
|
|
||||||
|
This example changes the color and removes the padding around a [Picture
|
||||||
|
Elements state
|
||||||
|
label](https://www.home-assistant.io/lovelace/picture-elements/#state-label).
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
[...]
|
||||||
|
card_mod:
|
||||||
|
style:
|
||||||
|
frigate-card-elements $:
|
||||||
|
hui-state-label-element $: |
|
||||||
|
div {
|
||||||
|
padding: 0px !important;
|
||||||
|
color: blue;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<a name="card-updates"></a>
|
||||||
|
|
||||||
## Card Refreshes
|
## Card Refreshes
|
||||||
|
|
||||||
Four sets of flags govern when the card will automatically refresh in the
|
Four sets of flags govern when the card will automatically refresh in the
|
||||||
|
|||||||
+14
-10
@@ -130,11 +130,15 @@ export class FrigateCard extends LitElement {
|
|||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
protected _hass?: HomeAssistant & ExtendedHomeAssistant;
|
protected _hass?: HomeAssistant & ExtendedHomeAssistant;
|
||||||
|
|
||||||
|
// The main base configuration object. For most usecases use getConfig() to
|
||||||
|
// get the correct configuration (which will return overrides as appropriate).
|
||||||
|
// This variable must be called `_config` or `config` to be compatible with
|
||||||
|
// card-mod.
|
||||||
@state()
|
@state()
|
||||||
public _baseConfig!: FrigateCardConfig;
|
protected _config!: FrigateCardConfig;
|
||||||
|
|
||||||
@state()
|
@state()
|
||||||
public _overriddenConfig?: FrigateCardConfig;
|
protected _overriddenConfig?: FrigateCardConfig;
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
protected _view?: View;
|
protected _view?: View;
|
||||||
@@ -231,8 +235,8 @@ export class FrigateCard extends LitElement {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const overriddenConfig = getOverriddenConfig(
|
const overriddenConfig = getOverriddenConfig(
|
||||||
this._baseConfig,
|
this._config,
|
||||||
this._baseConfig.overrides,
|
this._config.overrides,
|
||||||
this._conditionState,
|
this._conditionState,
|
||||||
) as FrigateCardConfig;
|
) as FrigateCardConfig;
|
||||||
|
|
||||||
@@ -598,7 +602,7 @@ export class FrigateCard extends LitElement {
|
|||||||
getLovelace().setEditMode(true);
|
getLovelace().setEditMode(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._baseConfig = config;
|
this._config = config;
|
||||||
this._cameras = undefined;
|
this._cameras = undefined;
|
||||||
this._view = undefined;
|
this._view = undefined;
|
||||||
|
|
||||||
@@ -610,7 +614,7 @@ export class FrigateCard extends LitElement {
|
|||||||
* @returns A FrigateCardConfig.
|
* @returns A FrigateCardConfig.
|
||||||
*/
|
*/
|
||||||
protected _getConfig(): FrigateCardConfig {
|
protected _getConfig(): FrigateCardConfig {
|
||||||
return this._overriddenConfig || this._baseConfig;
|
return this._overriddenConfig || this._config;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _changeView(args?: { view?: View; resetMessage?: boolean }): void {
|
protected _changeView(args?: { view?: View; resetMessage?: boolean }): void {
|
||||||
@@ -1229,15 +1233,15 @@ export class FrigateCard extends LitElement {
|
|||||||
// Note: Subtle difference in condition below vs the other views in order
|
// Note: Subtle difference in condition below vs the other views in order
|
||||||
// to always render the live view for live.preload mode.
|
// to always render the live view for live.preload mode.
|
||||||
|
|
||||||
// Note: <frigate-card-live> uses the baseConfig rather than the
|
// Note: <frigate-card-live> uses the underlying _config rather than the
|
||||||
// overriden config, as it does it's own overriding as part of the
|
// overriden config (via getConfig), as it does it's own overriding as
|
||||||
// camera carousel.
|
// part of the camera carousel.
|
||||||
this._getConfig().live.preload || (!this._message && this._view.is('live'))
|
this._getConfig().live.preload || (!this._message && this._view.is('live'))
|
||||||
? html`
|
? html`
|
||||||
<frigate-card-live
|
<frigate-card-live
|
||||||
.hass=${this._hass}
|
.hass=${this._hass}
|
||||||
.view=${this._view}
|
.view=${this._view}
|
||||||
.liveConfig=${this._baseConfig.live}
|
.liveConfig=${this._config.live}
|
||||||
.conditionState=${this._conditionState}
|
.conditionState=${this._conditionState}
|
||||||
.liveOverrides=${getOverridesByKey(this._getConfig().overrides, 'live')}
|
.liveOverrides=${getOverridesByKey(this._getConfig().overrides, 'live')}
|
||||||
.cameras=${this._cameras}
|
.cameras=${this._cameras}
|
||||||
|
|||||||
@@ -759,6 +759,9 @@ export const frigateCardConfigSchema = z.object({
|
|||||||
// Configuration overrides.
|
// Configuration overrides.
|
||||||
overrides: overridesSchema,
|
overrides: overridesSchema,
|
||||||
|
|
||||||
|
// Support for card_mod (https://github.com/thomasloven/lovelace-card-mod).
|
||||||
|
card_mod: z.unknown(),
|
||||||
|
|
||||||
// Stock lovelace card config.
|
// Stock lovelace card config.
|
||||||
type: z.string(),
|
type: z.string(),
|
||||||
test_gui: z.boolean().optional(),
|
test_gui: z.boolean().optional(),
|
||||||
|
|||||||
Reference in New Issue
Block a user