Add current humidity to humidifier history chart (#17288)

* Add current humidity to humidifier history chart

* state-humidifier-on-color
This commit is contained in:
Denis Shulyaka 2023-07-13 18:04:04 +03:00 committed by GitHub
parent 8bb2cbe767
commit 1fe02e8d6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 84 additions and 8 deletions

View File

@ -328,23 +328,94 @@ class StateHistoryChartLine extends LitElement {
} }
}); });
} else if (domain === "humidifier") { } else if (domain === "humidifier") {
const hasAction = states.states.some(
(entityState) => entityState.attributes?.action
);
const hasCurrent = states.states.some(
(entityState) => entityState.attributes?.current_humidity
);
const hasHumidifying =
hasAction &&
states.states.some(
(entityState: LineChartState) =>
entityState.attributes?.action === "humidifying"
);
const hasDrying =
hasAction &&
states.states.some(
(entityState: LineChartState) =>
entityState.attributes?.action === "drying"
);
addDataSet( addDataSet(
`${this.hass.localize("ui.card.humidifier.target_humidity_entity", { `${this.hass.localize("ui.card.humidifier.target_humidity_entity", {
name: name, name: name,
})}` })}`
); );
addDataSet(
`${this.hass.localize("ui.card.humidifier.on_entity", { if (hasCurrent) {
name: name, addDataSet(
})}`, `${this.hass.localize(
true "ui.card.humidifier.current_humidity_entity",
); {
name: name,
}
)}`
);
}
// If action attribute is available, we used it to shade the area below the humidity.
// If action attribute is not available, we shade the area when the device is on
if (hasHumidifying) {
addDataSet(
`${this.hass.localize("ui.card.humidifier.humidifying", {
name: name,
})}`,
true,
computedStyles.getPropertyValue("--state-humidifier-on-color")
);
} else if (hasDrying) {
addDataSet(
`${this.hass.localize("ui.card.humidifier.drying", {
name: name,
})}`,
true,
computedStyles.getPropertyValue("--state-humidifier-on-color")
);
} else {
addDataSet(
`${this.hass.localize("ui.card.humidifier.on_entity", {
name: name,
})}`,
true
);
}
states.states.forEach((entityState) => { states.states.forEach((entityState) => {
if (!entityState.attributes) return; if (!entityState.attributes) return;
const target = safeParseFloat(entityState.attributes.humidity); const target = safeParseFloat(entityState.attributes.humidity);
// If the current humidity is not available, then we fill up to the target humidity
const current = hasCurrent
? safeParseFloat(entityState.attributes?.current_humidity)
: target;
const series = [target]; const series = [target];
series.push(entityState.state === "on" ? target : null);
if (hasCurrent) {
series.push(current);
}
if (hasHumidifying) {
series.push(
entityState.attributes?.action === "humidifying" ? current : null
);
} else if (hasDrying) {
series.push(
entityState.attributes?.action === "drying" ? current : null
);
} else {
series.push(entityState.state === "on" ? current : null);
}
pushData(new Date(entityState.last_changed), series); pushData(new Date(entityState.last_changed), series);
}); });
} else { } else {

View File

@ -29,6 +29,8 @@ const LINE_ATTRIBUTES_TO_KEEP = [
"hvac_action", "hvac_action",
"humidity", "humidity",
"mode", "mode",
"action",
"current_humidity",
]; ];
export interface LineChartState { export interface LineChartState {

View File

@ -156,7 +156,7 @@ documentContainer.innerHTML = `<custom-style>
--state-device_tracker-active-color: var(--blue-color); --state-device_tracker-active-color: var(--blue-color);
--state-device_tracker-home-color: var(--green-color); --state-device_tracker-home-color: var(--green-color);
--state-fan-active-color: var(--cyan-color); --state-fan-active-color: var(--cyan-color);
--state-humidifier-active-color: var(--blue-color); --state-humidifier-on-color: var(--blue-color);
--state-light-active-color: var(--amber-color); --state-light-active-color: var(--amber-color);
--state-lock-jammed-color: var(--red-color); --state-lock-jammed-color: var(--red-color);
--state-lock-locked-color: var(--green-color); --state-lock-locked-color: var(--green-color);

View File

@ -134,6 +134,9 @@
"state": "State", "state": "State",
"mode": "Mode", "mode": "Mode",
"target_humidity_entity": "{name} target humidity", "target_humidity_entity": "{name} target humidity",
"current_humidity_entity": "{name} current humidity",
"humidifying": "{name} humidifying",
"drying": "{name} drying",
"on_entity": "{name} on" "on_entity": "{name} on"
}, },
"light": { "light": {