mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-25 05:47:20 +00:00
Improve UX for counter and input_number helpers (#9061)
This commit is contained in:
parent
3575d94ca1
commit
4e1d10cc08
@ -224,12 +224,15 @@ export const computeHistory = (
|
||||
|
||||
if (stateWithUnit) {
|
||||
unit = stateWithUnit.attributes.unit_of_measurement;
|
||||
} else if (computeStateDomain(stateInfo[0]) === "climate") {
|
||||
unit = hass.config.unit_system.temperature;
|
||||
} else if (computeStateDomain(stateInfo[0]) === "water_heater") {
|
||||
unit = hass.config.unit_system.temperature;
|
||||
} else if (computeStateDomain(stateInfo[0]) === "humidifier") {
|
||||
unit = "%";
|
||||
} else {
|
||||
unit = {
|
||||
climate: hass.config.unit_system.temperature,
|
||||
counter: "#",
|
||||
humidifier: "%",
|
||||
input_number: "#",
|
||||
number: "#",
|
||||
water_heater: hass.config.unit_system.temperature,
|
||||
}[computeStateDomain(stateInfo[0])];
|
||||
}
|
||||
|
||||
if (!unit) {
|
||||
|
@ -44,7 +44,7 @@ class HuiGaugeCard extends LitElement implements LovelaceCard {
|
||||
entities: string[],
|
||||
entitiesFallback: string[]
|
||||
): GaugeCardConfig {
|
||||
const includeDomains = ["sensor"];
|
||||
const includeDomains = ["counter", "input_number", "number", "sensor"];
|
||||
const maxEntities = 1;
|
||||
const entityFilter = (stateObj: HassEntity): boolean =>
|
||||
!isNaN(Number(stateObj.state));
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { HassEntity } from "home-assistant-js-websocket/dist/types";
|
||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||
import { customElement } from "lit-element";
|
||||
import { HomeAssistant } from "../../../types";
|
||||
import { findEntities } from "../common/find-entities";
|
||||
@ -7,6 +8,8 @@ import { LovelaceCardEditor } from "../types";
|
||||
import { HuiEntityCard } from "./hui-entity-card";
|
||||
import { EntityCardConfig, SensorCardConfig } from "./types";
|
||||
|
||||
const includeDomains = ["counter", "input_number", "number", "sensor"];
|
||||
|
||||
@customElement("hui-sensor-card")
|
||||
class HuiSensorCard extends HuiEntityCard {
|
||||
public static async getConfigElement(): Promise<LovelaceCardEditor> {
|
||||
@ -19,7 +22,6 @@ class HuiSensorCard extends HuiEntityCard {
|
||||
entities: string[],
|
||||
entitiesFallback: string[]
|
||||
): SensorCardConfig {
|
||||
const includeDomains = ["sensor"];
|
||||
const maxEntities = 1;
|
||||
const entityFilter = (stateObj: HassEntity): boolean =>
|
||||
!isNaN(Number(stateObj.state)) &&
|
||||
@ -38,7 +40,10 @@ class HuiSensorCard extends HuiEntityCard {
|
||||
}
|
||||
|
||||
public setConfig(config: SensorCardConfig): void {
|
||||
if (!config.entity || config.entity.split(".")[0] !== "sensor") {
|
||||
if (
|
||||
!config.entity ||
|
||||
!includeDomains.includes(computeDomain(config.entity))
|
||||
) {
|
||||
throw new Error("Specify an entity from within the sensor domain");
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ const cardConfigStruct = object({
|
||||
theme: optional(string()),
|
||||
});
|
||||
|
||||
const includeDomains = ["sensor"];
|
||||
const includeDomains = ["counter", "input_number", "number", "sensor"];
|
||||
|
||||
@customElement("hui-gauge-card-editor")
|
||||
export class HuiGaugeCardEditor
|
||||
|
@ -37,7 +37,7 @@ const cardConfigStruct = object({
|
||||
hours_to_show: optional(number()),
|
||||
});
|
||||
|
||||
const includeDomains = ["sensor"];
|
||||
const includeDomains = ["counter", "input_number", "number", "sensor"];
|
||||
|
||||
@customElement("hui-sensor-card-editor")
|
||||
export class HuiSensorCardEditor
|
||||
|
@ -12,6 +12,7 @@ import {
|
||||
} from "lit-element";
|
||||
import "../../../components/ha-circular-progress";
|
||||
import { fetchRecent } from "../../../data/history";
|
||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||
import { HomeAssistant } from "../../../types";
|
||||
import { findEntities } from "../common/find-entities";
|
||||
import { coordinates } from "../common/graph/coordinates";
|
||||
@ -22,6 +23,7 @@ import { GraphHeaderFooterConfig } from "./types";
|
||||
|
||||
const MINUTE = 60000;
|
||||
const HOUR = MINUTE * 60;
|
||||
const includeDomains = ["counter", "input_number", "number", "sensor"];
|
||||
|
||||
@customElement("hui-graph-header-footer")
|
||||
export class HuiGraphHeaderFooter
|
||||
@ -37,7 +39,6 @@ export class HuiGraphHeaderFooter
|
||||
entities: string[],
|
||||
entitiesFallback: string[]
|
||||
): GraphHeaderFooterConfig {
|
||||
const includeDomains = ["sensor"];
|
||||
const maxEntities = 1;
|
||||
const entityFilter = (stateObj: HassEntity): boolean =>
|
||||
!isNaN(Number(stateObj.state)) &&
|
||||
@ -75,7 +76,10 @@ export class HuiGraphHeaderFooter
|
||||
}
|
||||
|
||||
public setConfig(config: GraphHeaderFooterConfig): void {
|
||||
if (!config?.entity || config.entity.split(".")[0] !== "sensor") {
|
||||
if (
|
||||
!config?.entity ||
|
||||
!includeDomains.includes(computeDomain(config.entity))
|
||||
) {
|
||||
throw new Error("Specify an entity from within the sensor domain");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user