Skip to content

Commit

Permalink
debug: RuntimeWarning: overflow encountered in scalar ...
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrapan committed Jan 27, 2025
1 parent 7f1904d commit a97ca49
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions custom_components/solarman/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging

from datetime import datetime
from warnings import catch_warnings

from .const import *
from .common import *
Expand Down Expand Up @@ -198,31 +199,40 @@ def _read_registers_signed(self, data, definition):
magnitude = definition.get("magnitude", False)
maxint = 0
value = 0
value2 = 0
shift = 0

for r in definition["registers"]:
if (temp := get_addr_value(data, code, r)) is None:
return None
with catch_warnings(record=True) as w:
for r in definition["registers"]:
if (temp := get_addr_value(data, code, r)) is None:
return None

maxint <<= 16
maxint |= 0xFFFF
value += (temp & 0xFFFF) << shift
shift += 16
maxint <<= 16
maxint |= 0xFFFF
value2 += (temp & 0xFFFF) << shift
shift += 16

if not self.in_range(value, definition):
return None
value = value2

if not self.in_range(value, definition):
return None

if (offset := definition.get("offset")) is not None:
value -= offset

if (offset := definition.get("offset")) is not None:
value -= offset
if value > (maxint >> 1):
value = (value - maxint) if not magnitude else -(value & (maxint >> 1))

if value > (maxint >> 1):
value = (value - maxint) if not magnitude else -(value & (maxint >> 1))
if (scale := definition.get("scale")) is not None:
value *= scale

if (scale := definition.get("scale")) is not None:
value *= scale
if (divide := definition.get("divide")) is not None:
value //= divide

if (divide := definition.get("divide")) is not None:
value //= divide
if w:
_LOGGER.warning(f"Warning spawn w/ value2: {type(value2)} ({value2}), value: {type(value)} ({value}), maxint: {type(maxint)} ({maxint}), scale: {type(scale)} ({scale})")
for wm in w:
_LOGGER.warning(f"{wm.category} <{wm.filename}> [{wm.lineno}]: {wm.message}")

return value

Expand Down

0 comments on commit a97ca49

Please sign in to comment.