Skip to content

Commit 077a435

Browse files
authored
Merge pull request #209 from plugwise/production
Update code for production-power levels
2 parents 91c9d1b + 427d625 commit 077a435

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

plugwise_usb/nodes/circle.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,11 @@ def _calc_watts(self, pulses: int, seconds: int, nano_offset: int) -> float | No
10241024
return None
10251025

10261026
pulses_per_s = self._correct_power_pulses(pulses, nano_offset) / float(seconds)
1027+
negative = False
1028+
if pulses_per_s < 0:
1029+
negative = True
1030+
pulses_per_s = abs(pulses_per_s)
1031+
10271032
corrected_pulses = seconds * (
10281033
(
10291034
(
@@ -1037,18 +1042,10 @@ def _calc_watts(self, pulses: int, seconds: int, nano_offset: int) -> float | No
10371042
)
10381043
+ self._calibration.off_tot
10391044
)
1045+
if negative:
1046+
corrected_pulses = -corrected_pulses
10401047

1041-
# Fix minor miscalculations
1042-
if (
1043-
calc_value := corrected_pulses / PULSES_PER_KW_SECOND / seconds * (1000)
1044-
) >= 0.0:
1045-
return calc_value
1046-
_LOGGER.debug(
1047-
"Correct negative power %s to 0.0 for %s",
1048-
str(corrected_pulses / PULSES_PER_KW_SECOND / seconds * 1000),
1049-
self._mac_in_str,
1050-
)
1051-
return 0.0
1048+
return corrected_pulses / PULSES_PER_KW_SECOND / seconds * (1000)
10521049

10531050
def _correct_power_pulses(self, pulses: int, offset: int) -> float:
10541051
"""Correct pulses based on given measurement time offset (ns)."""

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "plugwise_usb"
7-
version = "v0.40.0a31"
7+
version = "v0.40.0a33"
88
license = {file = "LICENSE"}
99
description = "Plugwise USB (Stick) module for Python 3."
1010
readme = "README.md"

tests/stick_test_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@
690690
b"0013" # msg_id
691691
+ b"0098765432101234" # mac
692692
+ b"000A" # pulses 1s
693-
+ b"0066" # pulses 8s
693+
+ b"FF9A" # pulses 8s
694694
+ b"00001234"
695695
+ b"00000000"
696696
+ b"0004",

tests/test_usb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ async def fake_get_missing_energy_logs(address: int) -> None:
905905
)
906906
pu = await stick.nodes["0098765432101234"].power_update()
907907
assert pu.last_second == 21.2780505980402
908-
assert pu.last_8_seconds == 27.150578775440106
908+
assert pu.last_8_seconds == -27.150578775440106
909909

910910
# Test energy state without request
911911
assert stick.nodes["0098765432101234"].energy == pw_api.EnergyStatistics(

0 commit comments

Comments
 (0)