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:
Max Gramser
2026-09-17 16:12:45 +02:00
parent 10540cf356
commit 45fcbdd807
4 changed files with 15 additions and 3 deletions
+7
View File
@@ -1,3 +1,10 @@
## 0.2.69 (firmware 0.2.58)
A very large sensor value no longer stops a screen's updates.
- **A screen kept getting updates.** Since 0.2.67 a sensor tile with a display precision rounds its value as Home Assistant shows it. A value with more than 28 digits, such as `1e30` from a template or counter, made that rounding fail, and the screen with that tile then got no layout or state updates at all until the value changed. Such a value now shows as it is, and the rest of the screen goes on.
- No firmware change: firmware stays 0.2.58. Includes everything from 0.2.68.
## 0.2.68 (firmware 0.2.58)
Put a new screen on from your own computer.
+5 -2
View File
@@ -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):
+1 -1
View File
@@ -1,5 +1,5 @@
name: ESP Screen Manager
version: "0.2.68"
version: "0.2.69"
slug: esp_screen_manager
description: Choose tiles for your CYD and Guition touchscreen, without reflashing.
url: https://github.com/MaxGramser/homeassistant_espscreen
+2
View File
@@ -48,6 +48,8 @@ class Rounding(unittest.TestCase):
self.assertEqual(rounded_state('21.45', 1), '21.5', 'half up, as the frontend rounds')
self.assertEqual(rounded_state('1249.6', 0), '1250', 'no thousands separator: the screen reads the number')
self.assertEqual(rounded_state('-0.04', 1), '0.0')
self.assertEqual(rounded_state('1e30', 1), '1e30', 'too many digits to round: the value stays and the sync goes on')
self.assertEqual(rounded_state('123456789012345678901234567890.5', 1), '123456789012345678901234567890.5')
self.assertEqual(rounded_state('3', 2), '3.00')
for value in ('unavailable', 'on', '', 'nan', 'inf'):
self.assertEqual(rounded_state(value, 1), value)