1a6308aba7
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>
54 lines
3.2 KiB
Python
54 lines
3.2 KiB
Python
import re
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
import sys
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
import test_portal
|
|
from core import TILE_BACKGROUNDS, validate_layout
|
|
|
|
def luminance(color):
|
|
rgb=[int(color[i:i+2],16)/255 for i in (1,3,5)]
|
|
linear=[v/12.92 if v<=0.04045 else ((v+0.055)/1.055)**2.4 for v in rgb]
|
|
return sum(v*w for v,w in zip(linear,(.2126,.7152,.0722)))
|
|
|
|
class PaletteTests(unittest.IsolatedAsyncioTestCase):
|
|
def test_palette_matches_firmware_and_has_readable_text(self):
|
|
# The named card colours live in theme.h (firmware 0.2.54+): name, light value, dark value.
|
|
header=(Path(__file__).resolve().parents[1]/'components/smart_display/theme.h').read_text()
|
|
native={name:light for name,light,_ in re.findall(r'\{"(\w+)", 0x([A-F0-9]{6}), 0x([A-F0-9]{6})\}',header)}
|
|
expected={k:v['color'][1:] for k,v in TILE_BACKGROUNDS.items() if v['color']}
|
|
self.assertEqual(native,expected)
|
|
for color in expected.values():
|
|
for foreground,minimum in (('#1B1B1B',7),('#46525E',4.5)):
|
|
self.assertGreaterEqual((luminance('#'+color)+.05)/(luminance(foreground)+.05),minimum)
|
|
|
|
async def test_old_editor_preserves_color_and_explicit_auto_clears(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
m=test_portal.ManagerTests().setup_manager(Path(tmp)/'screens.json')
|
|
layout={'title':'Home','tiles':[{'entity':'light.a','options':{'background':'red','inline':'slider'}}]}
|
|
m.save('text.screen',layout)
|
|
m.save('text.screen',{'title':'New','tiles':[{'entity':'light.a','options':{'inline':'none'}}]})
|
|
fresh=test_portal.ManagerTests().setup_manager(m.path)
|
|
tile=fresh.layouts['text.screen']['tiles'][0]
|
|
self.assertEqual(tile['options'],{'background':'red','inline':'none'})
|
|
await fresh.sync_one('text.screen',fresh.layouts['text.screen'])
|
|
self.assertEqual(fresh.ha.messages[1][1]['o']['background'],'red')
|
|
fresh.save('text.screen',{'title':'New','tiles':[{'entity':'light.a','options':{'background':'auto'}}]})
|
|
self.assertEqual(fresh.layouts['text.screen']['tiles'][0]['options']['background'],'auto')
|
|
|
|
def test_none_hides_the_card_and_needs_firmware_0216(self):
|
|
from core import min_firmware
|
|
header=(Path(__file__).resolve().parents[1]/'components/smart_display/tile_palette.h').read_text()
|
|
self.assertIn('name=="none"',header)
|
|
self.assertIsNone(TILE_BACKGROUNDS['none']['color'])
|
|
for entity in ('screen.clock','light.a'):
|
|
layout=validate_layout({'title':'Home','tiles':[{'entity':entity,'options':{'background':'none'}}]})
|
|
self.assertEqual(layout['tiles'][0]['options']['background'],'none')
|
|
self.assertEqual(min_firmware(layout),(0,2,16))
|
|
self.assertEqual(min_firmware({'tiles':[{'entity':'light.a','options':{'background':'red'}}]}),None)
|
|
|
|
def test_unapproved_colors_rejected(self):
|
|
for value in ('#000000','url(test)','unknown',None,{},42):
|
|
with self.assertRaises(ValueError):validate_layout({'title':'Home','tiles':[{'entity':'light.a','options':{'background':value}}]})
|