Skip to content

Commit 3872aa4

Browse files
vinnyfuriaVinny Furiapiitaya
authored
Implement Feature Request 1088 (#1625)
* Implement Feature Request 1088 1. Added current humidity to state info 2. Added status badge to indicate if humidifier is idle or not * Updated per PR comments Mostly removing unneeded code and improving readability. * Use clock icon if outline --------- Co-authored-by: Vinny Furia <[email protected]> Co-authored-by: Paul Bottein <[email protected]>
1 parent 3d82e7b commit 3872aa4

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

src/cards/humidifier-card/humidifier-card.ts

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { css, CSSResultGroup, html, nothing } from "lit";
22
import { customElement, state } from "lit/decorators.js";
33
import { classMap } from "lit/directives/class-map.js";
4+
import { styleMap } from "lit/directives/style-map.js";
45
import {
56
actionHandler,
67
ActionHandlerEvent,
@@ -10,6 +11,7 @@ import {
1011
HomeAssistant,
1112
HumidifierEntity,
1213
isActive,
14+
isAvailable,
1315
LovelaceCard,
1416
LovelaceCardEditor,
1517
} from "../../ha";
@@ -64,8 +66,6 @@ export class HumidifierCard
6466
};
6567
}
6668

67-
@state() private humidity?: number;
68-
6969
protected get hasControls(): boolean {
7070
return Boolean(this._config?.show_target_humidity_control);
7171
}
@@ -86,12 +86,6 @@ export class HumidifierCard
8686
handleAction(this, this.hass!, this._config!, ev.detail.action!);
8787
}
8888

89-
private onCurrentHumidityChange(e: CustomEvent<{ value?: number }>): void {
90-
if (e.detail.value != null) {
91-
this.humidity = e.detail.value;
92-
}
93-
}
94-
9589
protected render() {
9690
if (!this._config || !this.hass || !this._config.entity) {
9791
return nothing;
@@ -109,13 +103,12 @@ export class HumidifierCard
109103
const picture = computeEntityPicture(stateObj, appearance.icon_type);
110104

111105
let stateDisplay = this.hass.formatEntityState(stateObj);
112-
if (this.humidity) {
106+
if (stateObj.attributes.current_humidity !== null) {
113107
const humidity = this.hass.formatEntityAttributeValue(
114108
stateObj,
115-
"current_humidity",
116-
this.humidity
109+
"current_humidity"
117110
);
118-
stateDisplay = humidity;
111+
stateDisplay += ` ⸱ ${humidity}`;
119112
}
120113

121114
const rtl = computeRTL(this.hass);
@@ -150,7 +143,6 @@ export class HumidifierCard
150143
<mushroom-humidifier-humidity-control
151144
.hass=${this.hass}
152145
.entity=${stateObj}
153-
@current-change=${this.onCurrentHumidityChange}
154146
></mushroom-humidifier-humidity-control>
155147
</div>
156148
`
@@ -160,6 +152,33 @@ export class HumidifierCard
160152
`;
161153
}
162154

155+
protected renderBadge(entity: HumidifierEntity) {
156+
if (isAvailable(entity)) {
157+
return this.renderActionBadge(entity);
158+
} else {
159+
return super.renderBadge(entity);
160+
}
161+
}
162+
163+
renderActionBadge(entity: HumidifierEntity) {
164+
const action = entity.attributes.action;
165+
if (!action || action == "off") return nothing;
166+
167+
const color =
168+
action === "idle" ? "var(--rgb-disabled)" : "var(--rgb-state-humidifier)";
169+
const icon = action === "idle" ? "mdi:clock-outline" : "mdi:water-percent";
170+
171+
return html`
172+
<mushroom-badge-icon
173+
slot="badge"
174+
.icon=${icon}
175+
style=${styleMap({
176+
"--main-color": `rgb(${color})`,
177+
})}
178+
></mushroom-badge-icon>
179+
`;
180+
}
181+
163182
static get styles(): CSSResultGroup {
164183
return [
165184
super.styles,

src/ha/data/humidifier.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ import {
33
HassEntityBase,
44
} from "home-assistant-js-websocket";
55

6+
export type HumidifierAction = "off" | "humidifying" | "dehumidifying" | "idle";
7+
68
export type HumidifierEntity = HassEntityBase & {
79
attributes: HassEntityAttributeBase & {
810
humidity?: number;
11+
current_humidity?: number;
912
min_humidity?: number;
1013
max_humidity?: number;
14+
action: HumidifierAction;
1115
mode?: string;
1216
available_modes?: string[];
1317
};

0 commit comments

Comments
 (0)