From 7e0c80ae24fa966690a0fa179fba914d267d2f98 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Thu, 23 Feb 2023 15:41:27 +0100 Subject: [PATCH] Use correct number format options in hui-gauge (#15565) --- src/components/ha-gauge.ts | 6 +++++- src/data/thread.ts | 7 ++----- src/panels/lovelace/cards/hui-gauge-card.ts | 2 ++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/ha-gauge.ts b/src/components/ha-gauge.ts index 6aaf31e3d5..9519ec85df 100644 --- a/src/components/ha-gauge.ts +++ b/src/components/ha-gauge.ts @@ -26,6 +26,9 @@ export class Gauge extends LitElement { @property({ type: Number }) public value = 0; + @property({ attribute: false }) + public formatOptions?: Intl.NumberFormatOptions; + @property({ type: String }) public valueText?: string; @property() public locale!: FrontendLocaleData; @@ -132,7 +135,8 @@ export class Gauge extends LitElement { ${ this._segment_label ? this._segment_label - : this.valueText || formatNumber(this.value, this.locale) + : this.valueText || + formatNumber(this.value, this.locale, this.formatOptions) }${ this._segment_label ? "" diff --git a/src/data/thread.ts b/src/data/thread.ts index b760495654..e3016b9416 100644 --- a/src/data/thread.ts +++ b/src/data/thread.ts @@ -26,12 +26,9 @@ export interface ThreadRouterDiscoveryEvent { } class DiscoveryStream { - hass: HomeAssistant; - routers: { [key: string]: ThreadRouter }; - constructor(hass: HomeAssistant) { - this.hass = hass; + constructor() { this.routers = {}; } @@ -49,7 +46,7 @@ export const subscribeDiscoverThreadRouters = ( hass: HomeAssistant, callbackFunction: (routers: ThreadRouter[]) => void ) => { - const stream = new DiscoveryStream(hass); + const stream = new DiscoveryStream(); return hass.connection.subscribeMessage( (message) => callbackFunction(stream.processEvent(message)), { diff --git a/src/panels/lovelace/cards/hui-gauge-card.ts b/src/panels/lovelace/cards/hui-gauge-card.ts index 801b70f09d..ec243f8846 100644 --- a/src/panels/lovelace/cards/hui-gauge-card.ts +++ b/src/panels/lovelace/cards/hui-gauge-card.ts @@ -13,6 +13,7 @@ import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_elemen import { fireEvent } from "../../../common/dom/fire_event"; import { computeStateName } from "../../../common/entity/compute_state_name"; import { isValidEntityId } from "../../../common/entity/valid_entity_id"; +import { getNumberFormatOptions } from "../../../common/number/format_number"; import "../../../components/ha-card"; import "../../../components/ha-gauge"; import { UNAVAILABLE } from "../../../data/entity"; @@ -129,6 +130,7 @@ class HuiGaugeCard extends LitElement implements LovelaceCard { .min=${this._config.min!} .max=${this._config.max!} .value=${stateObj.state} + .formatOptions=${getNumberFormatOptions(stateObj)} .locale=${this.hass!.locale} .label=${this._config!.unit || this.hass?.states[this._config!.entity].attributes