Make sure calculations are done using Decimal

This commit is contained in:
Odd Stråbø 2021-11-29 20:42:54 +01:00
parent 0cd5872fb6
commit b5740d78c8

View file

@ -405,16 +405,18 @@ if __name__ == "__main__":
data = try_read_parse(dev, 0x0100, 11, parse_battery_state) data = try_read_parse(dev, 0x0100, 11, parse_battery_state)
if data: if data:
data[DataName.CALCULATED_BATTERY_POWER] = float( data[DataName.CALCULATED_BATTERY_POWER] = float(
Decimal(data.get(DataName.BATTERY_VOLTAGE, 0)) Decimal(str(data.get(DataName.BATTERY_VOLTAGE, 0)))
* Decimal(data.get(DataName.BATTERY_CURRENT, 0)) * Decimal(
str(data.get(DataName.BATTERY_CURRENT, 0))
)
) )
data[DataName.CALCULATED_PANEL_POWER] = float( data[DataName.CALCULATED_PANEL_POWER] = float(
Decimal(data.get(DataName.PANEL_VOLTAGE, 0)) Decimal(str(data.get(DataName.PANEL_VOLTAGE, 0)))
* Decimal(data.get(DataName.PANEL_CURRENT, 0)) * Decimal(str(data.get(DataName.PANEL_CURRENT, 0)))
) )
data[DataName.CALCULATED_LOAD_POWER] = float( data[DataName.CALCULATED_LOAD_POWER] = float(
Decimal(data.get(DataName.LOAD_VOLTAGE, 0)) Decimal(str(data.get(DataName.LOAD_VOLTAGE, 0)))
* Decimal(data.get(DataName.LOAD_CURRENT, 0)) * Decimal(str(data.get(DataName.LOAD_CURRENT, 0)))
) )
log(data) log(data)
for consumer in consumers: for consumer in consumers: