diff --git a/screen_manager/CHANGELOG.md b/screen_manager/CHANGELOG.md index a6b51f1..4092080 100644 --- a/screen_manager/CHANGELOG.md +++ b/screen_manager/CHANGELOG.md @@ -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. diff --git a/screen_manager/app/core.py b/screen_manager/app/core.py index 40f4485..8ab5883 100644 --- a/screen_manager/app/core.py +++ b/screen_manager/app/core.py @@ -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): diff --git a/screen_manager/config.yaml b/screen_manager/config.yaml index 1cac37a..2e22fe2 100644 --- a/screen_manager/config.yaml +++ b/screen_manager/config.yaml @@ -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 diff --git a/tests/test_state_words.py b/tests/test_state_words.py index 82139a2..d758191 100644 --- a/tests/test_state_words.py +++ b/tests/test_state_words.py @@ -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)