Skip to content

Commit

Permalink
Use correct number format options in hui-gauge
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkragten committed Feb 23, 2023
1 parent 19d721f commit 59f141c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/components/ha-gauge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
? ""
Expand Down
7 changes: 2 additions & 5 deletions src/data/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ export interface ThreadRouterDiscoveryEvent {
}

class DiscoveryStream {
hass: HomeAssistant;

routers: { [key: string]: ThreadRouter };

constructor(hass: HomeAssistant) {
this.hass = hass;
constructor() {
this.routers = {};
}

Expand All @@ -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<ThreadRouterDiscoveryEvent>(
(message) => callbackFunction(stream.processEvent(message)),
{
Expand Down
2 changes: 2 additions & 0 deletions src/panels/lovelace/cards/hui-gauge-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 59f141c

Please sign in to comment.