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;
|
||||
private _config?: Config;
|
||||
private _updated?: boolean;
|
||||
|
||||
static get properties(): PropertyDeclarations {
|
||||
return {
|
||||
@ -78,6 +79,11 @@ class HuiGaugeCard extends LitElement implements LovelaceCard {
|
||||
this._config = { min: 0, max: 100, theme: "default", ...config };
|
||||
}
|
||||
|
||||
public connectedCallback(): void {
|
||||
super.connectedCallback();
|
||||
this._setBaseUnit();
|
||||
}
|
||||
|
||||
protected render(): TemplateResult {
|
||||
if (!this._config || !this.hass) {
|
||||
return html``;
|
||||
@ -148,12 +154,8 @@ class HuiGaugeCard extends LitElement implements LovelaceCard {
|
||||
}
|
||||
|
||||
protected firstUpdated(): void {
|
||||
(this.shadowRoot!.querySelector(
|
||||
"ha-card"
|
||||
)! as HTMLElement).style.setProperty(
|
||||
"--base-unit",
|
||||
this._computeBaseUnit()
|
||||
);
|
||||
this._updated = true;
|
||||
this._setBaseUnit();
|
||||
}
|
||||
|
||||
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 {
|
||||
const sections = this._config!.severity;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user