Skip to content

Commit f6ac761

Browse files
improve power meter (#1196)
1 parent 261e6be commit f6ac761

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) {
@@ -750,12 +746,7 @@ function updateComponent(cd) {
750746
updateInnerText(el(c, "head"), headText);
751747
setValueIfNotModified(el(c, "name"), cd.name);
752748
el(c, "state").checked = cd.state;
753-
if (cd.apower !== undefined) {
754-
updateInnerText(
755-
el(c, "power_stats"),
756-
`${Math.round(cd.apower)}W, ${cd.aenergy}Wh`);
757-
el(c, "power_stats_container").style.display = "block";
758-
}
749+
updatePowerStats(c, cd);
759750
slideIfNotModified(el(c, "color_temperature"), cd.color_temperature);
760751
slideIfNotModified(el(c, "hue"), cd.hue);
761752
slideIfNotModified(el(c, "saturation"), cd.saturation);
@@ -1080,6 +1071,15 @@ function updateElement(key, value, info) {
10801071
}
10811072
}
10821073

1074+
function updatePowerStats(c, cd) {
1075+
if (cd.apower === undefined) return;
1076+
1077+
apower = Math.round(cd.apower * 10) / 10;
1078+
console.log(apower)
1079+
updateInnerText(el(c, "power_stats"), `${apower}W, ${cd.aenergy}Wh`);
1080+
el(c, "power_stats_container").style.display = "block";
1081+
}
1082+
10831083
function getInfo() {
10841084
return new Promise(function(resolve, reject) {
10851085
if (pendingGetInfo) {

0 commit comments

Comments
 (0)