Files
homeassistant_espscreen/tests/test_twenty_tiles.py
T
Max Gramser 1a6308aba7 Fix what a full test round of today's releases found: a ticking single clock, a switch that works in standby, no taps from a swipe (0.2.78)
A test and code-analysis round of 0.2.72 to 0.2.76 (suites at every tag, sanitizers, ESP32 and GitHub builds, host
harnesses on both boards, the editor in a browser, best practice checked against ESPHome, LVGL, Home Assistant and
Vue) found these, fixed here with Max's choices for the product questions:

- Firmware 0.2.65: the second hand of a single analog clock moves again; on a page that is one full on/off tile the
  waking push also switches it; on the Guition a flick is never a tap and a finger that slides off a tile doesn't tap
  it; Previous/Next react to a firm press; the same Go to page tile may sit on several pages; a layout the screen has
  no memory for is refused instead of crashing; 64-bit redraw mask for 48 tiles; Montserrat 14 no longer built.
- App: Save refuses a layout too long for one message or too big for eight pages; an offline screen keeps its
  firmware version from the device registry; HA refusals reach the editor; 128 KB requests; changelog out of the
  live stream; cached hashed assets; tini as init and a clean stop; changelog parsing without asterisks or crashes.
- Editor: clicking the open screen keeps unsaved edits, edits during a save stay unsaved, a Page row and phone
  dragging to other pages, repeated page tiles, limits from the server, HA's error messages, a type-checked build.
- tools/check.sh + GitHub Actions + a CYD flash budget; docs match 48 tiles and the new editor.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-18 17:25:23 +02:00

37 lines
2.0 KiB
Python

import json
import sys
import tempfile
import unittest
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
import test_portal
from core import validate_layout, validate_settings, packets
class TwentyTiles(unittest.IsolatedAsyncioTestCase):
async def test_twenty_and_old_firmware_guard(self):
with tempfile.TemporaryDirectory() as tmp:
m=test_portal.ManagerTests().setup_manager(Path(tmp)/'screens.json')
layout={'title':'Twenty','tiles':[{'entity':f'light.item{i}'} for i in range(20)],
'settings':validate_settings({'swipe_pages':True})}
for tile in layout['tiles']:m.ha.states[tile['entity']]={'state':'on','attributes':{}}
with self.assertRaises(ValueError):m.save('text.screen',layout)
m.ha.registry[0]['device_id']='screen-device'
m.ha.registry.append({'entity_id':'sensor.version','platform':'esphome','original_name':'Screen firmware','device_id':'screen-device'})
m.ha.states['sensor.version']={'state':'0.2.7'}
m.save('text.screen',layout)
await m.sync_one('text.screen',m.layouts['text.screen'])
self.assertEqual(len(m.ha.messages),21)
wire=m.ha.messages[0][1]
self.assertEqual(len(wire['entities']),20)
self.assertEqual(len(wire['settings']),11)
self.assertTrue(wire['swipe_pages'])
for _,message in m.ha.messages:self.assertTrue(packets(message))
old=dict(layout);old['settings']={k:v for k,v in layout['settings'].items() if k!='swipe_pages'}
m.save('text.screen',old)
self.assertTrue(m.layouts['text.screen']['settings']['swipe_pages'])
m.ha.states['sensor.version']['state']='0.2.6'
m.ha.messages.clear()
await m.sync_one('text.screen',m.layouts['text.screen'],True)
self.assertEqual(m.ha.messages,[])
self.assertEqual(len(json.loads(m.path.read_text())['screens']['text.screen']['tiles']),20)