Keep a screen's updates going when a sensor value has too many digits to round (0.2.69)
rounded_state raised decimal.InvalidOperation for a value beyond Decimal's 28-digit context, such as 1e30; the exception escaped state_message and the whole screen's sync stalled. Such a value now passes through unrounded. App only, firmware stays 0.2.58. Found in a review of 0.2.67. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@@ -1001,8 +1001,11 @@ def rounded_state(value, precision):
|
||||
return value
|
||||
if not math.isfinite(number):
|
||||
return value
|
||||
from decimal import ROUND_HALF_UP, Decimal
|
||||
text = format(Decimal(str(value)).quantize(Decimal(1).scaleb(-precision), rounding=ROUND_HALF_UP), 'f')
|
||||
from decimal import ROUND_HALF_UP, Decimal, InvalidOperation
|
||||
try:
|
||||
text = format(Decimal(str(value)).quantize(Decimal(1).scaleb(-precision), rounding=ROUND_HALF_UP), 'f')
|
||||
except InvalidOperation: # more digits than Decimal's context holds, such as 1e30: the value is fine as it is
|
||||
return value
|
||||
return text[1:] if text.startswith('-') and not text.strip('-0.') else text
|
||||
|
||||
def ha_word(entity_id, suffix, attributes, entry, words):
|
||||
|
||||
Reference in New Issue
Block a user