mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 11:46:42 +00:00
Fix gauge (#2456)
This commit is contained in:
parent
963bdcc53c
commit
668d4e82ba
@ -56,6 +56,7 @@ class HuiGaugeCard extends LitElement implements LovelaceCard {
|
|||||||
|
|
||||||
public hass?: HomeAssistant;
|
public hass?: HomeAssistant;
|
||||||
private _config?: Config;
|
private _config?: Config;
|
||||||
|
private _updated?: boolean;
|
||||||
|
|
||||||
static get properties(): PropertyDeclarations {
|
static get properties(): PropertyDeclarations {
|
||||||
return {
|
return {
|
||||||
@ -78,6 +79,11 @@ class HuiGaugeCard extends LitElement implements LovelaceCard {
|
|||||||
this._config = { min: 0, max: 100, theme: "default", ...config };
|
this._config = { min: 0, max: 100, theme: "default", ...config };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public connectedCallback(): void {
|
||||||
|
super.connectedCallback();
|
||||||
|
this._setBaseUnit();
|
||||||
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
if (!this._config || !this.hass) {
|
if (!this._config || !this.hass) {
|
||||||
return html``;
|
return html``;
|
||||||
@ -148,12 +154,8 @@ class HuiGaugeCard extends LitElement implements LovelaceCard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected firstUpdated(): void {
|
protected firstUpdated(): void {
|
||||||
(this.shadowRoot!.querySelector(
|
this._updated = true;
|
||||||
"ha-card"
|
this._setBaseUnit();
|
||||||
)! as HTMLElement).style.setProperty(
|
|
||||||
"--base-unit",
|
|
||||||
this._computeBaseUnit()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected updated(changedProps: PropertyValues): void {
|
protected updated(changedProps: PropertyValues): void {
|
||||||
@ -169,6 +171,19 @@ class HuiGaugeCard extends LitElement implements LovelaceCard {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _setBaseUnit(): void {
|
||||||
|
if (!this.isConnected || !this._updated) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const baseUnit = this._computeBaseUnit();
|
||||||
|
if (baseUnit === "0px") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
(this.shadowRoot!.querySelector(
|
||||||
|
"ha-card"
|
||||||
|
)! as HTMLElement).style.setProperty("--base-unit", baseUnit);
|
||||||
|
}
|
||||||
|
|
||||||
private _computeSeverity(numberValue: number): string {
|
private _computeSeverity(numberValue: number): string {
|
||||||
const sections = this._config!.severity;
|
const sections = this._config!.severity;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user