33 LitElement ,
44 html ,
55 css ,
6- CSSResult ,
76 PropertyValueMap ,
87 svg ,
98 CSSResultGroup ,
@@ -12,15 +11,12 @@ import {
1211import {
1312 customElement ,
1413 property ,
15- query ,
1614 state
1715} from "lit/decorators.js" ;
1816import { classMap } from "lit/directives/class-map.js" ;
1917import {
2018 mdiWindowOpenVariant ,
2119 mdiSunThermometer ,
22- mdiPlus ,
23- mdiMinus ,
2420 mdiDotsVertical ,
2521 mdiCalendarSync ,
2622 mdiAutorenew ,
@@ -31,32 +27,22 @@ import {
3127 mdiWaterPercent ,
3228 mdiLeaf ,
3329 mdiThermometer ,
34- mdiHeatWave
30+ mdiHeatWave ,
31+ mdiBatteryAlert ,
32+ mdiWifiStrengthOffOutline
3533} from "@mdi/js" ;
3634
37- import {
38- HassEntity
39- } from "home-assistant-js-websocket" ;
4035import {
4136 CARD_VERSION
4237} from './const' ;
4338import {
4439 localize
4540} from './localize/localize' ;
4641import {
47- actionHandler ,
48- ActionHandlerEvent ,
4942 ClimateEntity ,
50- computeRTL ,
51- computeStateDisplay ,
5243 fireEvent ,
5344 formatNumber ,
54- handleAction ,
55- hasAction ,
5645 HomeAssistant ,
57- HvacMode ,
58- isActive ,
59- isAvailable ,
6046 LovelaceCard ,
6147 LovelaceCardEditor ,
6248} from "./ha" ;
@@ -170,6 +156,8 @@ export class BetterThermostatUi extends LitElement implements LovelaceCard {
170156 private _display_bottom : number = 0 ;
171157 private _display_top : number = 0 ;
172158 private modes : any = [ ] ;
159+ private lowBattery : any = { } ;
160+ private error : any = [ ] ;
173161
174162 @state ( ) private _config ?: ClimateCardConfig ;
175163
@@ -194,8 +182,11 @@ export class BetterThermostatUi extends LitElement implements LovelaceCard {
194182 display: block;
195183 overflow: hidden;
196184 box-sizing: border-box;
185+ position: relative;
186+ }
187+ .summer {
188+ --mode-color: var(--label-badge-yellow)
197189 }
198-
199190 ha-card {
200191 height: 100%;
201192 width: 100%;
@@ -207,6 +198,36 @@ export class BetterThermostatUi extends LitElement implements LovelaceCard {
207198 box-sizing: border-box;
208199 }
209200
201+ .content.battery {
202+ opacity: 0.5;
203+ filter: blur(5px);
204+ pointer-events: none;
205+ }
206+
207+ .low_battery, .error {
208+ position: absolute;
209+ display: flex;
210+ flex-flow: column;
211+ align-items: center;
212+ place-content: center;
213+ width: -webkit-fill-available;
214+ height: -webkit-fill-available;
215+ left: 0px;
216+ top: 0px;
217+ background: rgba(200, 200, 200, 0.16);
218+ border-radius: var(--ha-card-border-radius,12px);
219+ border-width: var(--ha-card-border-width,1px);
220+ border-style: solid;
221+ border-color: var(--ha-card-border-color,var(--divider-color,#e0e0e0));
222+ pointer-events: all;
223+ font-size: 22px;
224+ text-align: center;
225+ line-height: 40px;
226+ padding: 1em;
227+ --mdc-icon-size: 40px;
228+
229+ }
230+
210231 .unavailable {
211232 opacity: 0.3;
212233 }
@@ -267,11 +288,7 @@ export class BetterThermostatUi extends LitElement implements LovelaceCard {
267288 }
268289
269290 .window_open {
270- --mode-color: var(--energy-grid-consumption-color)
271- }
272-
273- .summer {
274- --mode-color: var(--label-badge-yellow)
291+ --mode-color: #80a7c4
275292 }
276293
277294 .auto,
@@ -392,7 +409,7 @@ export class BetterThermostatUi extends LitElement implements LovelaceCard {
392409 fill: var(--label-badge-yellow);
393410 }
394411 .window.active {
395- fill: var(--energy-grid-consumption-color) ;
412+ fill: #80a7c4 ;
396413 }
397414 ` ;
398415
@@ -497,7 +514,7 @@ export class BetterThermostatUi extends LitElement implements LovelaceCard {
497514 protected firstUpdated ( _changedProperties : PropertyValueMap < any > | Map < PropertyKey , unknown > ) : void {
498515 const that = this ;
499516 const valueHandler : any = this ?. shadowRoot ?. querySelector ( ".value-handler" ) ;
500- const currentHandler : any = this ?. shadowRoot ?. querySelector ( ".current-handler" )
517+ const currentHandler : any = this ?. shadowRoot ?. querySelector ( ".current-handler" ) ;
501518 this ?. shadowRoot ?. querySelector ( "#c-minus" ) ?. addEventListener ( "click" , ( ) => {
502519 clearTimeout ( that . _timeout ) ;
503520 if ( that . _oldValueMin === 0 ) that . _oldValueMin = that . value ;
@@ -655,6 +672,12 @@ export class BetterThermostatUi extends LitElement implements LovelaceCard {
655672 } ) ;
656673 }
657674 this . _firstRender = false ;
675+
676+ this ?. shadowRoot ?. querySelector ( '.low_battery' ) ?. addEventListener ( 'click' , ( ) => {
677+ this ?. shadowRoot ?. querySelector ( '.low_battery' ) ?. remove ( ) ;
678+ this ?. shadowRoot ?. querySelector ( '.content' ) ?. classList . remove ( 'battery' ) ;
679+ this . _vibrate ( 2 ) ;
680+ } ) ;
658681 }
659682
660683 public willUpdate ( changedProps : PropertyValues ) {
@@ -709,6 +732,27 @@ export class BetterThermostatUi extends LitElement implements LovelaceCard {
709732 this . _hasSummer = true ;
710733 this . summer = ! attributes . call_for_heat
711734 }
735+ if ( attributes ?. batteries !== undefined ) {
736+ const batteries = Object . entries ( JSON . parse ( attributes . batteries ) ) ;
737+ const lowBatteries = batteries . filter ( ( entity : any ) => entity [ 1 ] . battery < 10 ) ;
738+ if ( lowBatteries . length > 0 ) {
739+ this . lowBattery = lowBatteries . map ( ( data :any ) => { return { "name" : data [ 0 ] , "battery" : data [ 1 ] . battery } } ) [ 0 ] ;
740+ } else {
741+ this . lowBattery = null ;
742+ }
743+ } else {
744+ this . lowBattery = null ;
745+ }
746+ if ( attributes ?. errors !== undefined ) {
747+ const errors = JSON . parse ( attributes . errors ) ;
748+ if ( errors . length > 0 ) {
749+ this . error = errors [ 0 ] ;
750+ } else {
751+ this . error = [ ] ;
752+ }
753+ } else {
754+ this . error = [ ] ;
755+ }
712756 this . _updateDisplay ( ) ;
713757 }
714758 }
@@ -782,6 +826,7 @@ export class BetterThermostatUi extends LitElement implements LovelaceCard {
782826 [ this . mode ] : true ,
783827 } ) }
784828 >
829+ ${ this . _config ?. disable_menu ? `` : html `
785830 < ha-icon-button
786831 class ="more-info "
787832 .label =${ this . hass ! . localize (
@@ -791,8 +836,24 @@ export class BetterThermostatUi extends LitElement implements LovelaceCard {
791836 @click=${ this . _handleMoreInfo }
792837 tabindex="0"
793838 > </ ha-icon-button >
839+ ` }
794840 < div class ="name "> ${ this . _config ?. name } </ div >
795- < div class ="content ${ this . window ? 'window_open' : '' } ${ this . summer ? 'summer' : '' } ${ ( this ?. stateObj ?. attributes ?. saved_temperature && this ?. stateObj ?. attributes ?. saved_temperature !== null ) ? 'eco' : '' } ">
841+ ${ this . lowBattery !== null ? html `
842+ < div class ="low_battery ">
843+ < ha-icon-button class ="alert " .path =${ mdiBatteryAlert } >
844+ </ ha-icon-button >
845+ < span > ${ this . lowBattery . name } </ span >
846+ < span > ${ this . lowBattery . battery } %</ span >
847+ </ div >
848+ ` : `` }
849+ ${ this . error . length > 0 ? html `
850+ < div class ="error ">
851+ < ha-icon-button class ="alert " .path =${ mdiWifiStrengthOffOutline } >
852+ </ ha-icon-button >
853+ < span > ${ this . error } </ span >
854+ </ div >
855+ ` : `` }
856+ < div class ="content ${ this . lowBattery !== null || this . error . length > 0 ? 'battery' : '' } ${ this . window ? 'window_open' : '' } ${ ( this ?. stateObj ?. attributes ?. saved_temperature && this ?. stateObj ?. attributes ?. saved_temperature !== null ) ? 'eco' : '' } ${ this . summer ? 'summer' : '' } ">
796857 < svg id ="main " viewbox ="0 0 125 100 ">
797858 < g transform ="translate(57.5,37) scale(0.35) ">
798859 ${ ( this . _hasWindow && ! this . _config ?. disable_window ) ? svg `
@@ -887,7 +948,8 @@ export class BetterThermostatUi extends LitElement implements LovelaceCard {
887948 ` }
888949
889950 </ div >
890- </ div >
951+ </ div >
952+ </ div >
891953 </ ha-card >
892954 ` ;
893955 } ;
0 commit comments