mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 11:16:35 +00:00
Format input number (#8811)
This commit is contained in:
parent
dffe0f656d
commit
d75c6aecbe
@ -68,8 +68,12 @@ export const computeStateDisplay = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// `counter` and `number` domains do not have a unit of measurement but should still use `formatNumber`
|
// `counter` `number` and `input_number` domains do not have a unit of measurement but should still use `formatNumber`
|
||||||
if (domain === "counter" || domain === "number") {
|
if (
|
||||||
|
domain === "counter" ||
|
||||||
|
domain === "number" ||
|
||||||
|
domain === "input_number"
|
||||||
|
) {
|
||||||
return formatNumber(compareState, locale);
|
return formatNumber(compareState, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import {
|
|||||||
PropertyValues,
|
PropertyValues,
|
||||||
TemplateResult,
|
TemplateResult,
|
||||||
} from "lit-element";
|
} from "lit-element";
|
||||||
import { formatNumber } from "../../../common/string/format_number";
|
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
|
||||||
import { computeRTLDirection } from "../../../common/util/compute_rtl";
|
import { computeRTLDirection } from "../../../common/util/compute_rtl";
|
||||||
import "../../../components/ha-slider";
|
import "../../../components/ha-slider";
|
||||||
import { UNAVAILABLE_STATES } from "../../../data/entity";
|
import { UNAVAILABLE_STATES } from "../../../data/entity";
|
||||||
@ -89,8 +89,12 @@ class HuiInputNumberEntityRow extends LitElement implements LovelaceRow {
|
|||||||
id="input"
|
id="input"
|
||||||
></ha-slider>
|
></ha-slider>
|
||||||
<span class="state">
|
<span class="state">
|
||||||
${formatNumber(Number(stateObj.state), this.hass.locale)}
|
${computeStateDisplay(
|
||||||
${stateObj.attributes.unit_of_measurement}
|
this.hass.localize,
|
||||||
|
stateObj,
|
||||||
|
this.hass.locale,
|
||||||
|
stateObj.state
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
|
@ -19,6 +19,7 @@ import { hasConfigOrEntityChanged } from "../common/has-changed";
|
|||||||
import "../components/hui-generic-entity-row";
|
import "../components/hui-generic-entity-row";
|
||||||
import { EntityConfig, LovelaceRow } from "./types";
|
import { EntityConfig, LovelaceRow } from "./types";
|
||||||
import { createEntityNotFoundWarning } from "../components/hui-warning";
|
import { createEntityNotFoundWarning } from "../components/hui-warning";
|
||||||
|
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
|
||||||
|
|
||||||
@customElement("hui-number-entity-row")
|
@customElement("hui-number-entity-row")
|
||||||
class HuiNumberEntityRow extends LitElement implements LovelaceRow {
|
class HuiNumberEntityRow extends LitElement implements LovelaceRow {
|
||||||
@ -88,8 +89,12 @@ class HuiNumberEntityRow extends LitElement implements LovelaceRow {
|
|||||||
id="input"
|
id="input"
|
||||||
></ha-slider>
|
></ha-slider>
|
||||||
<span class="state">
|
<span class="state">
|
||||||
${Number(stateObj.state)}
|
${computeStateDisplay(
|
||||||
${stateObj.attributes.unit_of_measurement}
|
this.hass.localize,
|
||||||
|
stateObj,
|
||||||
|
this.hass.locale,
|
||||||
|
stateObj.state
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
|
@ -5,6 +5,7 @@ import { mixinBehaviors } from "@polymer/polymer/lib/legacy/class";
|
|||||||
import { html } from "@polymer/polymer/lib/utils/html-tag";
|
import { html } from "@polymer/polymer/lib/utils/html-tag";
|
||||||
/* eslint-plugin-disable lit */
|
/* eslint-plugin-disable lit */
|
||||||
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
||||||
|
import { computeStateDisplay } from "../common/entity/compute_state_display";
|
||||||
import "../components/entity/state-info";
|
import "../components/entity/state-info";
|
||||||
import "../components/ha-slider";
|
import "../components/ha-slider";
|
||||||
|
|
||||||
@ -75,7 +76,7 @@ class StateCardInputNumber extends mixinBehaviors(
|
|||||||
class="state sliderstate"
|
class="state sliderstate"
|
||||||
hidden="[[hiddenslider]]"
|
hidden="[[hiddenslider]]"
|
||||||
>
|
>
|
||||||
[[value]] [[stateObj.attributes.unit_of_measurement]]
|
[[formattedState]]
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
@ -138,6 +139,7 @@ class StateCardInputNumber extends mixinBehaviors(
|
|||||||
},
|
},
|
||||||
step: Number,
|
step: Number,
|
||||||
value: Number,
|
value: Number,
|
||||||
|
formattedState: String,
|
||||||
mode: String,
|
mode: String,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -159,6 +161,12 @@ class StateCardInputNumber extends mixinBehaviors(
|
|||||||
max: Number(newVal.attributes.max),
|
max: Number(newVal.attributes.max),
|
||||||
step: Number(newVal.attributes.step),
|
step: Number(newVal.attributes.step),
|
||||||
value: Number(newVal.state),
|
value: Number(newVal.state),
|
||||||
|
formattedState: computeStateDisplay(
|
||||||
|
this.hass.localize,
|
||||||
|
newVal,
|
||||||
|
this.hass.locale,
|
||||||
|
newVal.state
|
||||||
|
),
|
||||||
mode: String(newVal.attributes.mode),
|
mode: String(newVal.attributes.mode),
|
||||||
maxlength: String(newVal.attributes.max).length,
|
maxlength: String(newVal.attributes.max).length,
|
||||||
hiddenbox: newVal.attributes.mode !== "box",
|
hiddenbox: newVal.attributes.mode !== "box",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user