Skip to content

Commit 610741f

Browse files
committed
improve power meter
1 parent 4eb34e2 commit 610741f

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

fs_src/script.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -673,11 +673,7 @@ function updateComponent(cd) {
673673
updateInnerText(el(c, "head"), headText);
674674
setValueIfNotModified(el(c, "name"), cd.name);
675675
el(c, "state").checked = cd.state;
676-
if (cd.apower !== undefined) {
677-
updateInnerText(
678-
el(c, "power_stats"), `${Math.round(cd.apower)}W, ${cd.aenergy}Wh`);
679-
el(c, "power_stats_container").style.display = "block";
680-
}
676+
updatePowerStats(c, cd);
681677
if (cd.type == Component_Type.kLightBulb) {
682678
checkIfNotModified(el(c, "svc_hidden"), cd.svc_hidden);
683679
if (cd.hap_optional !== undefined && cd.hap_optional == 0) {
@@ -739,12 +735,7 @@ function updateComponent(cd) {
739735
updateInnerText(el(c, "head"), headText);
740736
setValueIfNotModified(el(c, "name"), cd.name);
741737
el(c, "state").checked = cd.state;
742-
if (cd.apower !== undefined) {
743-
updateInnerText(
744-
el(c, "power_stats"),
745-
`${Math.round(cd.apower)}W, ${cd.aenergy}Wh`);
746-
el(c, "power_stats_container").style.display = "block";
747-
}
738+
updatePowerStats(c, cd);
748739
slideIfNotModified(el(c, "color_temperature"), cd.color_temperature);
749740
slideIfNotModified(el(c, "hue"), cd.hue);
750741
slideIfNotModified(el(c, "saturation"), cd.saturation);
@@ -1069,6 +1060,15 @@ function updateElement(key, value, info) {
10691060
}
10701061
}
10711062

1063+
function updatePowerStats(c, cd) {
1064+
if (cd.apower === undefined) return;
1065+
1066+
apower = Math.round(cd.apower * 10) / 10;
1067+
console.log(apower)
1068+
updateInnerText(el(c, "power_stats"), `${apower}W, ${cd.aenergy}Wh`);
1069+
el(c, "power_stats_container").style.display = "block";
1070+
}
1071+
10721072
function getInfo() {
10731073
return new Promise(function(resolve, reject) {
10741074
if (pendingGetInfo) {

0 commit comments

Comments
 (0)