Use correct number format options in hui-gauge (#15565)

This commit is contained in:
Bram Kragten 2023-02-23 15:41:27 +01:00 committed by GitHub
parent 3b5fe7fd9f
commit 7e0c80ae24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 6 deletions

View File

@ -26,6 +26,9 @@ export class Gauge extends LitElement {
@property({ type: Number }) public value = 0; @property({ type: Number }) public value = 0;
@property({ attribute: false })
public formatOptions?: Intl.NumberFormatOptions;
@property({ type: String }) public valueText?: string; @property({ type: String }) public valueText?: string;
@property() public locale!: FrontendLocaleData; @property() public locale!: FrontendLocaleData;
@ -132,7 +135,8 @@ export class Gauge extends LitElement {
${ ${
this._segment_label this._segment_label
? 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 this._segment_label
? "" ? ""

View File

@ -26,12 +26,9 @@ export interface ThreadRouterDiscoveryEvent {
} }
class DiscoveryStream { class DiscoveryStream {
hass: HomeAssistant;
routers: { [key: string]: ThreadRouter }; routers: { [key: string]: ThreadRouter };
constructor(hass: HomeAssistant) { constructor() {
this.hass = hass;
this.routers = {}; this.routers = {};
} }
@ -49,7 +46,7 @@ export const subscribeDiscoverThreadRouters = (
hass: HomeAssistant, hass: HomeAssistant,
callbackFunction: (routers: ThreadRouter[]) => void callbackFunction: (routers: ThreadRouter[]) => void
) => { ) => {
const stream = new DiscoveryStream(hass); const stream = new DiscoveryStream();
return hass.connection.subscribeMessage<ThreadRouterDiscoveryEvent>( return hass.connection.subscribeMessage<ThreadRouterDiscoveryEvent>(
(message) => callbackFunction(stream.processEvent(message)), (message) => callbackFunction(stream.processEvent(message)),
{ {

View File

@ -13,6 +13,7 @@ import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_elemen
import { fireEvent } from "../../../common/dom/fire_event"; import { fireEvent } from "../../../common/dom/fire_event";
import { computeStateName } from "../../../common/entity/compute_state_name"; import { computeStateName } from "../../../common/entity/compute_state_name";
import { isValidEntityId } from "../../../common/entity/valid_entity_id"; import { isValidEntityId } from "../../../common/entity/valid_entity_id";
import { getNumberFormatOptions } from "../../../common/number/format_number";
import "../../../components/ha-card"; import "../../../components/ha-card";
import "../../../components/ha-gauge"; import "../../../components/ha-gauge";
import { UNAVAILABLE } from "../../../data/entity"; import { UNAVAILABLE } from "../../../data/entity";
@ -129,6 +130,7 @@ class HuiGaugeCard extends LitElement implements LovelaceCard {
.min=${this._config.min!} .min=${this._config.min!}
.max=${this._config.max!} .max=${this._config.max!}
.value=${stateObj.state} .value=${stateObj.state}
.formatOptions=${getNumberFormatOptions(stateObj)}
.locale=${this.hass!.locale} .locale=${this.hass!.locale}
.label=${this._config!.unit || .label=${this._config!.unit ||
this.hass?.states[this._config!.entity].attributes this.hass?.states[this._config!.entity].attributes