Skip to content

Commit 65bc8ab

Browse files
committed
Move formatting into backend
1 parent f3e15d3 commit 65bc8ab

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

plugwise/util.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010

1111
import crcmod
1212

13-
from .constants import LOGADDR_OFFSET, PLUGWISE_EPOCH, UTF8_DECODE
13+
from .constants import (
14+
ENERGY_KILO_WATT_HOUR,
15+
LOGADDR_OFFSET,
16+
PERCENTAGE,
17+
PLUGWISE_EPOCH,
18+
UTF8_DECODE,
19+
)
1420

1521
crc_fun = crcmod.mkCrcFun(0x11021, rev=False, initCrc=0x0000, xorOut=0x0000)
1622

@@ -67,6 +73,10 @@ def escape_illegal_xml_characters(xmldata):
6773

6874
def format_measure(measure, unit):
6975
"""Format measure to correct type."""
76+
if unit == PERCENTAGE:
77+
measure = int(measure * 100)
78+
if unit == ENERGY_KILO_WATT_HOUR:
79+
measure = measure / 1000
7080
try:
7181
measure = int(measure)
7282
except ValueError:

0 commit comments

Comments
 (0)