Allow customizing number unit of measurement
This commit is contained in:
parent
414db83359
commit
4881d699e3
|
@ -37,6 +37,10 @@ export interface SensorEntityOptions {
|
|||
unit_of_measurement?: string | null;
|
||||
}
|
||||
|
||||
export interface NumberEntityOptions {
|
||||
unit_of_measurement?: string | null;
|
||||
}
|
||||
|
||||
export interface WeatherEntityOptions {
|
||||
precipitation_unit?: string | null;
|
||||
pressure_unit?: string | null;
|
||||
|
|
|
@ -105,6 +105,10 @@ const OVERRIDE_DEVICE_CLASSES = {
|
|||
],
|
||||
};
|
||||
|
||||
const OVERRIDE_NUMBER_UNITS = {
|
||||
temperature: ["°C", "°F", "K"],
|
||||
};
|
||||
|
||||
const OVERRIDE_SENSOR_UNITS = {
|
||||
temperature: ["°C", "°F", "K"],
|
||||
pressure: ["hPa", "Pa", "kPa", "bar", "cbar", "mbar", "mmHg", "inHg", "psi"],
|
||||
|
@ -235,7 +239,7 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
|
|||
}
|
||||
}
|
||||
|
||||
if (domain === "sensor") {
|
||||
if (domain === "number" || domain === "sensor") {
|
||||
const stateObj: HassEntity | undefined =
|
||||
this.hass.states[this.entry.entity_id];
|
||||
this._unit_of_measurement = stateObj?.attributes?.unit_of_measurement;
|
||||
|
@ -361,6 +365,31 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
|
|||
</ha-select>
|
||||
`
|
||||
: ""}
|
||||
${domain === "number" &&
|
||||
this._deviceClass &&
|
||||
stateObj?.attributes.unit_of_measurement &&
|
||||
OVERRIDE_NUMBER_UNITS[this._deviceClass]?.includes(
|
||||
stateObj?.attributes.unit_of_measurement
|
||||
)
|
||||
? html`
|
||||
<ha-select
|
||||
.label=${this.hass.localize(
|
||||
"ui.dialogs.entity_registry.editor.unit_of_measurement"
|
||||
)}
|
||||
.value=${stateObj.attributes.unit_of_measurement}
|
||||
naturalMenuWidth
|
||||
fixedMenuPosition
|
||||
@selected=${this._unitChanged}
|
||||
@closed=${stopPropagation}
|
||||
>
|
||||
${OVERRIDE_NUMBER_UNITS[this._deviceClass].map(
|
||||
(unit: string) => html`
|
||||
<mwc-list-item .value=${unit}>${unit}</mwc-list-item>
|
||||
`
|
||||
)}
|
||||
</ha-select>
|
||||
`
|
||||
: ""}
|
||||
${domain === "sensor" &&
|
||||
this._deviceClass &&
|
||||
stateObj?.attributes.unit_of_measurement &&
|
||||
|
@ -861,10 +890,10 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
|
|||
params.hidden_by = this._hiddenBy;
|
||||
}
|
||||
if (
|
||||
domain === "sensor" &&
|
||||
(domain === "number" || domain === "number") &&
|
||||
stateObj?.attributes?.unit_of_measurement !== this._unit_of_measurement
|
||||
) {
|
||||
params.options_domain = "sensor";
|
||||
params.options_domain = domain;
|
||||
params.options = { unit_of_measurement: this._unit_of_measurement };
|
||||
}
|
||||
if (
|
||||
|
|
Loading…
Reference in New Issue