mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 01:06:35 +00:00
Fetch weather units from core (#15212)
This commit is contained in:
parent
c747ab7605
commit
4a9ec7233d
@ -523,3 +523,18 @@ export const isForecastHourly = (
|
|||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type WeatherUnits = {
|
||||||
|
precipitation_unit: string[];
|
||||||
|
pressure_unit: string[];
|
||||||
|
temperature_unit: string[];
|
||||||
|
visibility_unit: string[];
|
||||||
|
wind_speed_unit: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getWeatherConvertibleUnits = (
|
||||||
|
hass: HomeAssistant
|
||||||
|
): Promise<{ units: WeatherUnits }> =>
|
||||||
|
hass.callWS({
|
||||||
|
type: "weather/convertible_units",
|
||||||
|
});
|
||||||
|
@ -72,6 +72,10 @@ import {
|
|||||||
import { domainToName } from "../../../data/integration";
|
import { domainToName } from "../../../data/integration";
|
||||||
import { getNumberDeviceClassConvertibleUnits } from "../../../data/number";
|
import { getNumberDeviceClassConvertibleUnits } from "../../../data/number";
|
||||||
import { getSensorDeviceClassConvertibleUnits } from "../../../data/sensor";
|
import { getSensorDeviceClassConvertibleUnits } from "../../../data/sensor";
|
||||||
|
import {
|
||||||
|
WeatherUnits,
|
||||||
|
getWeatherConvertibleUnits,
|
||||||
|
} from "../../../data/weather";
|
||||||
import { showAliasesDialog } from "../../../dialogs/aliases/show-dialog-aliases";
|
import { showAliasesDialog } from "../../../dialogs/aliases/show-dialog-aliases";
|
||||||
import { showOptionsFlowDialog } from "../../../dialogs/config-flow/show-dialog-options-flow";
|
import { showOptionsFlowDialog } from "../../../dialogs/config-flow/show-dialog-options-flow";
|
||||||
import {
|
import {
|
||||||
@ -118,14 +122,6 @@ const OVERRIDE_DEVICE_CLASSES = {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
const OVERRIDE_WEATHER_UNITS = {
|
|
||||||
precipitation: ["mm", "in"],
|
|
||||||
pressure: ["hPa", "mbar", "mmHg", "inHg"],
|
|
||||||
temperature: ["°C", "°F"],
|
|
||||||
visibility: ["km", "mi"],
|
|
||||||
wind_speed: ["ft/s", "km/h", "kn", "m/s", "mph"],
|
|
||||||
};
|
|
||||||
|
|
||||||
const SWITCH_AS_DOMAINS = ["cover", "fan", "light", "lock", "siren"];
|
const SWITCH_AS_DOMAINS = ["cover", "fan", "light", "lock", "siren"];
|
||||||
|
|
||||||
const PRECISIONS = [0, 1, 2, 3, 4, 5, 6];
|
const PRECISIONS = [0, 1, 2, 3, 4, 5, 6];
|
||||||
@ -180,6 +176,8 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
@state() private _sensorDeviceClassConvertibleUnits?: string[];
|
@state() private _sensorDeviceClassConvertibleUnits?: string[];
|
||||||
|
|
||||||
|
@state() private _weatherConvertibleUnits?: WeatherUnits;
|
||||||
|
|
||||||
private _origEntityId!: string;
|
private _origEntityId!: string;
|
||||||
|
|
||||||
private _deviceLookup?: Record<string, DeviceRegistryEntry>;
|
private _deviceLookup?: Record<string, DeviceRegistryEntry>;
|
||||||
@ -319,6 +317,16 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
|
|||||||
this._sensorDeviceClassConvertibleUnits = [];
|
this._sensorDeviceClassConvertibleUnits = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (changedProps.has("_entityId")) {
|
||||||
|
const domain = computeDomain(this.entry.entity_id);
|
||||||
|
|
||||||
|
if (domain === "weather") {
|
||||||
|
const { units } = await getWeatherConvertibleUnits(this.hass);
|
||||||
|
this._weatherConvertibleUnits = units;
|
||||||
|
} else {
|
||||||
|
this._weatherConvertibleUnits = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
@ -543,7 +551,7 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
|
|||||||
@selected=${this._precipitationUnitChanged}
|
@selected=${this._precipitationUnitChanged}
|
||||||
@closed=${stopPropagation}
|
@closed=${stopPropagation}
|
||||||
>
|
>
|
||||||
${OVERRIDE_WEATHER_UNITS.precipitation.map(
|
${this._weatherConvertibleUnits?.precipitation_unit.map(
|
||||||
(unit: string) => html`
|
(unit: string) => html`
|
||||||
<mwc-list-item .value=${unit}>${unit}</mwc-list-item>
|
<mwc-list-item .value=${unit}>${unit}</mwc-list-item>
|
||||||
`
|
`
|
||||||
@ -559,7 +567,7 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
|
|||||||
@selected=${this._pressureUnitChanged}
|
@selected=${this._pressureUnitChanged}
|
||||||
@closed=${stopPropagation}
|
@closed=${stopPropagation}
|
||||||
>
|
>
|
||||||
${OVERRIDE_WEATHER_UNITS.pressure.map(
|
${this._weatherConvertibleUnits?.pressure_unit.map(
|
||||||
(unit: string) => html`
|
(unit: string) => html`
|
||||||
<mwc-list-item .value=${unit}>${unit}</mwc-list-item>
|
<mwc-list-item .value=${unit}>${unit}</mwc-list-item>
|
||||||
`
|
`
|
||||||
@ -575,7 +583,7 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
|
|||||||
@selected=${this._temperatureUnitChanged}
|
@selected=${this._temperatureUnitChanged}
|
||||||
@closed=${stopPropagation}
|
@closed=${stopPropagation}
|
||||||
>
|
>
|
||||||
${OVERRIDE_WEATHER_UNITS.temperature.map(
|
${this._weatherConvertibleUnits?.temperature_unit.map(
|
||||||
(unit: string) => html`
|
(unit: string) => html`
|
||||||
<mwc-list-item .value=${unit}>${unit}</mwc-list-item>
|
<mwc-list-item .value=${unit}>${unit}</mwc-list-item>
|
||||||
`
|
`
|
||||||
@ -591,7 +599,7 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
|
|||||||
@selected=${this._visibilityUnitChanged}
|
@selected=${this._visibilityUnitChanged}
|
||||||
@closed=${stopPropagation}
|
@closed=${stopPropagation}
|
||||||
>
|
>
|
||||||
${OVERRIDE_WEATHER_UNITS.visibility.map(
|
${this._weatherConvertibleUnits?.visibility_unit.map(
|
||||||
(unit: string) => html`
|
(unit: string) => html`
|
||||||
<mwc-list-item .value=${unit}>${unit}</mwc-list-item>
|
<mwc-list-item .value=${unit}>${unit}</mwc-list-item>
|
||||||
`
|
`
|
||||||
@ -607,7 +615,7 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
|
|||||||
@selected=${this._windSpeedUnitChanged}
|
@selected=${this._windSpeedUnitChanged}
|
||||||
@closed=${stopPropagation}
|
@closed=${stopPropagation}
|
||||||
>
|
>
|
||||||
${OVERRIDE_WEATHER_UNITS.wind_speed.map(
|
${this._weatherConvertibleUnits?.wind_speed_unit.map(
|
||||||
(unit: string) => html`
|
(unit: string) => html`
|
||||||
<mwc-list-item .value=${unit}>${unit}</mwc-list-item>
|
<mwc-list-item .value=${unit}>${unit}</mwc-list-item>
|
||||||
`
|
`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user