Files
homeassistant_espscreen/tests/test_twenty_tiles.py
T
Max Gramser 3e959b3df9 Put ESP Screens in English and keep layouts when entity IDs change (0.2.40)
Everything a user sees or reads is now English: both boards' labels,
status replies and logs, the ESP Screens editor and Alerts cheatsheet,
and the README and guides (docs/TILES.md, CALIBRATING.md, ACCEPTANCE.md
and TROUBLESHOOTING.md replace the Dutch file names). Labels follow
Home Assistant's own English names (Heat/Cool modes, Heating/Cooling
actions, Away, Returning to dock, weather conditions), dates use English
abbreviations and the top bar writes numbers the English way. Docs use
HA 2026.9's menu names (Settings -> Apps, App store, Settings -> Tools).
Unused legacy files (home-like.yaml, buttons.yaml, a.out) are removed.

Firmware 0.2.34 names its entities in English. Home Assistant registers
a renamed ESPHome entity under a new entity ID, so the inbox
text.<screen>_tegelinstellingen becomes text.<screen>_tile_settings and
the layout stored under the old ID would be lost. The manager now
recognises the screen by its device, during a run or after a restart,
and moves its layout and update history along; the Update button and
the nightly round follow the screen through the rename. Screens that
still run 0.2.33 or older keep working: both languages are matched.

Main is the only release branch from now on.

Tested on a Home Assistant Yellow (HA 2026.9.1) with both bench boards:
see docs/TEST_RESULTS_0240.md.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 02:08:43 +02:00

35 lines
1.9 KiB
Python

import json
import tempfile
import unittest
from pathlib import Path
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)