1
1
import { css , CSSResultGroup , html , nothing } from "lit" ;
2
2
import { customElement , state } from "lit/decorators.js" ;
3
3
import { classMap } from "lit/directives/class-map.js" ;
4
+ import { styleMap } from "lit/directives/style-map.js" ;
4
5
import {
5
6
actionHandler ,
6
7
ActionHandlerEvent ,
@@ -10,6 +11,7 @@ import {
10
11
HomeAssistant ,
11
12
HumidifierEntity ,
12
13
isActive ,
14
+ isAvailable ,
13
15
LovelaceCard ,
14
16
LovelaceCardEditor ,
15
17
} from "../../ha" ;
@@ -64,8 +66,6 @@ export class HumidifierCard
64
66
} ;
65
67
}
66
68
67
- @state ( ) private humidity ?: number ;
68
-
69
69
protected get hasControls ( ) : boolean {
70
70
return Boolean ( this . _config ?. show_target_humidity_control ) ;
71
71
}
@@ -86,12 +86,6 @@ export class HumidifierCard
86
86
handleAction ( this , this . hass ! , this . _config ! , ev . detail . action ! ) ;
87
87
}
88
88
89
- private onCurrentHumidityChange ( e : CustomEvent < { value ?: number } > ) : void {
90
- if ( e . detail . value != null ) {
91
- this . humidity = e . detail . value ;
92
- }
93
- }
94
-
95
89
protected render ( ) {
96
90
if ( ! this . _config || ! this . hass || ! this . _config . entity ) {
97
91
return nothing ;
@@ -109,13 +103,12 @@ export class HumidifierCard
109
103
const picture = computeEntityPicture ( stateObj , appearance . icon_type ) ;
110
104
111
105
let stateDisplay = this . hass . formatEntityState ( stateObj ) ;
112
- if ( this . humidity ) {
106
+ if ( stateObj . attributes . current_humidity !== null ) {
113
107
const humidity = this . hass . formatEntityAttributeValue (
114
108
stateObj ,
115
- "current_humidity" ,
116
- this . humidity
109
+ "current_humidity"
117
110
) ;
118
- stateDisplay = humidity ;
111
+ stateDisplay += ` ⸱ ${ humidity } ` ;
119
112
}
120
113
121
114
const rtl = computeRTL ( this . hass ) ;
@@ -150,7 +143,6 @@ export class HumidifierCard
150
143
<mushroom- humidifier- humidity- control
151
144
.hass = ${ this . hass }
152
145
.entity = ${ stateObj }
153
- @current-change = ${ this . onCurrentHumidityChange }
154
146
> </ mushroom- humidifier- humidity- control>
155
147
</ div>
156
148
`
@@ -160,6 +152,33 @@ export class HumidifierCard
160
152
` ;
161
153
}
162
154
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
+
163
182
static get styles ( ) : CSSResultGroup {
164
183
return [
165
184
super . styles ,
0 commit comments