Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Feature Request 1088 #1625

Merged
merged 3 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions src/cards/humidifier-card/humidifier-card.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { css, CSSResultGroup, html, nothing } from "lit";
import { customElement, state } from "lit/decorators.js";
import { classMap } from "lit/directives/class-map.js";
import { styleMap } from "lit/directives/style-map.js";
import {
actionHandler,
ActionHandlerEvent,
Expand All @@ -10,6 +11,7 @@ import {
HomeAssistant,
HumidifierEntity,
isActive,
isAvailable,
LovelaceCard,
LovelaceCardEditor,
} from "../../ha";
Expand Down Expand Up @@ -64,7 +66,6 @@ export class HumidifierCard
};
}

@state() private humidity?: number;

protected get hasControls(): boolean {
return Boolean(this._config?.show_target_humidity_control);
Expand All @@ -86,12 +87,6 @@ export class HumidifierCard
handleAction(this, this.hass!, this._config!, ev.detail.action!);
}

private onCurrentHumidityChange(e: CustomEvent<{ value?: number }>): void {
if (e.detail.value != null) {
this.humidity = e.detail.value;
}
}

protected render() {
if (!this._config || !this.hass || !this._config.entity) {
return nothing;
Expand All @@ -109,13 +104,12 @@ export class HumidifierCard
const picture = computeEntityPicture(stateObj, appearance.icon_type);

let stateDisplay = this.hass.formatEntityState(stateObj);
if (this.humidity) {
if (stateObj.attributes.current_humidity !== null) {
const humidity = this.hass.formatEntityAttributeValue(
stateObj,
"current_humidity",
this.humidity
"current_humidity"
);
stateDisplay = humidity;
stateDisplay += ` ⸱ ${humidity}`;
}

const rtl = computeRTL(this.hass);
Expand Down Expand Up @@ -150,7 +144,6 @@ export class HumidifierCard
<mushroom-humidifier-humidity-control
.hass=${this.hass}
.entity=${stateObj}
@current-change=${this.onCurrentHumidityChange}
></mushroom-humidifier-humidity-control>
</div>
`
Expand All @@ -160,6 +153,31 @@ export class HumidifierCard
`;
}

protected renderBadge(entity: HumidifierEntity) {
if (isAvailable(entity)) {
return this.renderActionBadge(entity);
} else {
return super.renderBadge(entity);
}
}

renderActionBadge(entity: HumidifierEntity) {
const action = entity.attributes.action;
if (!action || action == "off") return nothing;

const color = action == "idle" ? "var(--rgb-disabled)" : "var(--rgb-state-humidifier)";

return html`
<mushroom-badge-icon
slot="badge"
.icon=${"mdi:water-percent"}
style=${styleMap({
"--main-color": `rgb(${color})`,
})}
></mushroom-badge-icon>
`;
}

static get styles(): CSSResultGroup {
return [
super.styles,
Expand Down
4 changes: 4 additions & 0 deletions src/ha/data/humidifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import {
HassEntityBase,
} from "home-assistant-js-websocket";

export type HumidifierAction = "off" | "humidifying" | "dehumidifying" | "idle";

export type HumidifierEntity = HassEntityBase & {
attributes: HassEntityAttributeBase & {
humidity?: number;
current_humidity?: number;
min_humidity?: number;
max_humidity?: number;
action: HumidifierAction;
mode?: string;
available_modes?: string[];
};
Expand Down