Skip to content

Commit 3f4994a

Browse files
committed
[TASK] add new battery and disconnected devices info
1 parent cb73f83 commit 3f4994a

File tree

9 files changed

+414
-289
lines changed

9 files changed

+414
-289
lines changed

dist/better-thermostat-ui-card.js

Lines changed: 88 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 223 additions & 212 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "better-thermostat-ui-card",
3-
"version": "1.0.5",
3+
"version": "1.1.0",
44
"description": "Lovelace better-thermostat-ui",
55
"keywords": [
66
"home-assistant",
@@ -24,19 +24,19 @@
2424
"start:hass-cmd": "docker run --rm -p8123:8123 -v %cd%/.hass_dev:/config homeassistant/home-assistant:beta"
2525
},
2626
"dependencies": {
27-
"@babel/preset-env": "^7.22.5",
27+
"@babel/preset-env": "^7.22.7",
2828
"@mdi/js": "^7.2.96",
2929
"@svgdotjs/svg.js": "^3.2.0",
3030
"@types/gsap": "^3.0.0",
3131
"animejs": "^3.2.1",
3232
"custom-card-helpers": "^1.9.0",
3333
"gsap": "^3.12.2",
3434
"home-assistant-js-websocket": "^8.1.0",
35-
"lit": "^2.7.5",
35+
"lit": "^2.7.6",
3636
"memoize-one": "^6.0.0"
3737
},
3838
"devDependencies": {
39-
"@babel/core": "^7.22.5",
39+
"@babel/core": "^7.22.8",
4040
"@babel/preset-typescript": "^7.22.5",
4141
"@material/mwc-ripple": "^0.27.0",
4242
"@material/tab-bar": "^14.0.0",
@@ -47,10 +47,10 @@
4747
"@rollup/plugin-typescript": "^11.1.2",
4848
"@types/color": "^3.0.3",
4949
"@types/hammerjs": "^2.0.41",
50-
"@types/node": "^20.3.3",
50+
"@types/node": "^20.4.0",
5151
"eslint": "^8.44.0",
52-
"prettier": "^2.8.8",
53-
"rollup": "^3.26.0",
52+
"prettier": "^3.0.0",
53+
"rollup": "^3.26.2",
5454
"rollup-plugin-serve": "^2.0.2",
5555
"rollup-plugin-terser": "^7.0.2",
5656
"rollup-plugin-import-css": "^3.3.1",

src/better-thermostat-ui-card-editor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const loadHaComponents = (version: string) => {
3333
}
3434
};
3535

36-
const CLIMATE_LABELS = ["eco_temperature", "disable_window", "disable_summer", "disable_eco", "disable_heat", "disable_off", "set_current_as_main"] as string[];
36+
const CLIMATE_LABELS = ["eco_temperature", "disable_window", "disable_summer", "disable_eco", "disable_heat", "disable_off", "disable_menu", "set_current_as_main"] as string[];
3737

3838
const computeSchema = memoizeOne(
3939
(): any[] => [
@@ -49,6 +49,7 @@ const computeSchema = memoizeOne(
4949
{ name: "disable_eco", selector: { boolean: {} } },
5050
{ name: "disable_heat", selector: { boolean: {} } },
5151
{ name: "disable_off", selector: { boolean: {} } },
52+
{ name: "disable_menu", selector: { boolean: {} } },
5253
{ name: "set_current_as_main", selector: { boolean: {} } },
5354
],
5455
},

src/better-thermostat-ui.ts

Lines changed: 89 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
LitElement,
44
html,
55
css,
6-
CSSResult,
76
PropertyValueMap,
87
svg,
98
CSSResultGroup,
@@ -12,15 +11,12 @@ import {
1211
import {
1312
customElement,
1413
property,
15-
query,
1614
state
1715
} from "lit/decorators.js";
1816
import { classMap } from "lit/directives/class-map.js";
1917
import {
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";
4035
import {
4136
CARD_VERSION
4237
} from './const';
4338
import {
4439
localize
4540
} from './localize/localize';
4641
import {
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
};

src/climate-card-config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export type ClimateCardConfig = LovelaceCardConfig &
3333
disable_eco?: boolean;
3434
disable_heat?: boolean;
3535
disable_off?: boolean;
36+
disable_menu?: boolean;
3637
set_current_as_main?: boolean;
3738
eco_temperature?: number;
3839
};
@@ -48,5 +49,6 @@ export const climateCardConfigStruct = assign(
4849
disable_off: optional(boolean()),
4950
set_current_as_main: optional(boolean()),
5051
eco_temperature: optional(number()),
52+
disable_menu: optional(boolean()),
5153
})
5254
);

src/const.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const CARD_VERSION = '1.0.5';
1+
export const CARD_VERSION = '1.1.0';

src/localize/languages/de.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"disable_eco": "Eco-Anzeige deaktivieren",
1212
"disable_heat": "Heiz-Anzeige deaktivieren",
1313
"disable_off": "Aus-Anzeige deaktivieren",
14+
"disable_menu": "Menü deaktivieren",
1415
"eco_temperature": "Eco Temperatur",
1516
"set_current_as_main": "Zieltemperatur mit aktueller Temperatur tauschen"
1617
}

src/localize/languages/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"disable_eco": "Disable eco",
1212
"disable_heat": "Disable heat",
1313
"disable_off": "Disable off",
14+
"disable_menu": "Disable menu",
1415
"eco_temperature": "Eco temperature",
1516
"set_current_as_main": "Swap target with current temperature places"
1617
}

0 commit comments

Comments
 (0)