Show binary sensors in Home Assistant's words and grey out what is off (0.2.62)

A binary sensor's tile and card now say what Home Assistant says for its
device class, such as Open or Closed for a door and Wet or Dry for a leak
sensor. The screen maps the class it already receives, with the same words
as the top bar and the history card; a test keeps both tables equal. A
history card still waiting for its answer no longer shows the previous
card's word.

Lights and binary sensors that are off turn grey, as in Home Assistant, and
a light without an icon of its own shows a crossed-out bulb while it is off,
on the tile and in the top bar. A chosen icon stays and turns grey.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Max Gramser
2026-09-17 08:32:22 +02:00
parent 8a587303d7
commit 7311a1cdce
18 changed files with 256 additions and 10 deletions
+9 -3
View File
@@ -632,6 +632,7 @@ inline std::string detail_state(const Tile &t){
if(t.domain()=="sun")return t.state=="above_horizon"?"Above the horizon":"Below the horizon";
if(t.domain()=="timer")return timer_text(t);
if(t.domain()=="script"||t.domain()=="scene"||t.domain()=="button"||t.domain()=="input_button")return t.state=="on"?"Running...":last_run_text(t.last_run);
if(t.domain()=="binary_sensor"&&(t.state=="on"||t.state=="off"))return tile_controls::binary_state_text(t.device_class,t.state=="on");
if(t.state=="on")return "On";
if(t.state=="off")return "Off";
if(t.state=="docked")return "Docked";
@@ -1235,10 +1236,11 @@ inline bool history_fits(const Tile &t){
return history.entity==t.entity&&history.hours==history_hours&&
(history_answered||esphome::millis()-history_received_at<60000);
}
// Home Assistant's word for the state now: from the history's words, else the card's own.
// Home Assistant's word for the state now: from this entity's history words, else the card's own. The history can
// still be the previous card's while this one waits for its answer.
inline std::string history_words(const Tile &t){
if(!t.available())return "Unavailable";
for(const auto &pair:history.words)if(pair.first==t.state)return pair.second;
if(history.entity==t.entity)for(const auto &pair:history.words)if(pair.first==t.state)return pair.second;
return detail_state(t);
}
inline std::string history_clock(uint32_t epoch,bool weekday){
@@ -1651,6 +1653,8 @@ inline const char *weather_text(const std::string &condition) {
inline const char *icon_for(const Tile &tile) {
if (!tile.icon.empty()) return tile.icon.c_str();
auto d = tile.domain();
// Home Assistant's own icon: a bulb, crossed out while off. A chosen icon stays, as in Home Assistant.
if (d == "light" && tile.state == "off") return "\U000F0E4F";
if (d == "light") return "\U000F0335";
if (d == "climate") return "\U000F001B";
if (d == "vacuum") return "\U000F070D";
@@ -2371,6 +2375,7 @@ inline void render_slot(size_t slot) {
else if (d == "sun") value = !t.extra().sunrise.empty() && !t.extra().sunset.empty() ? t.extra().sunrise+" - "+t.extra().sunset : t.state=="above_horizon"?"Above the horizon":"Below the horizon";
else if (d == "timer") value = timer_text(t);
else if (d == "script" || d == "scene" || d == "button" || d == "input_button") value = t.state == "on" ? "Running..." : last_run_text(t.last_run);
else if (d == "binary_sensor" && (value == "on" || value == "off")) value = tile_controls::binary_state_text(t.device_class, value == "on");
else if (value == "on") value = "On";
else if (value == "off") value = "Off";
else if (value == "cleaning") value = "Cleaning";
@@ -2469,7 +2474,8 @@ inline void render_slot(size_t slot) {
if (w.cached_active == palette_state && !w.panel_dirty) { lap(swipe_profile::GEOMETRY); return; }
w.cached_active = palette_state;w.panel_dirty=false;
uint32_t accent = domain_accent(t);
auto color=lv_color_hex((t.is_switch()||d=="person"||d=="timer") && !on ? 0x9E9E9E : accent);
// Off is grey, as in Home Assistant, so a light or a door sensor shows its state at a glance.
auto color=lv_color_hex((t.is_switch()||d=="light"||d=="binary_sensor"||d=="person"||d=="timer") && !on ? 0x9E9E9E : accent);
if(d=="light" && on && t.has_hs_color)
color=lv_color_hsv_to_rgb(t.hue%360,t.saturation,100);
auto circle_color=available?lv_color_mix(color,lv_color_hex(0xFFFFFF),38):lv_color_hex(0xF0F0F0);
+21
View File
@@ -135,6 +135,27 @@ inline const char *media_state_text(const std::string &state) {
if (state == "off") return "Off";
return state.c_str();
}
// A binary sensor's state in Home Assistant's words for its device class: a door is Open or Closed, a leak sensor
// Wet or Dry. The same words as the add-on's header_bar.BINARY_STATES, which the top bar and the history card show;
// tests/test_binary_words.py keeps the two tables equal. Without a class, or with one this table lacks: On and Off.
struct BinaryWords { const char *device_class, *on, *off; };
constexpr BinaryWords BINARY_WORDS[] = {
{"battery", "Low", "Normal"}, {"battery_charging", "Charging", "Not charging"},
{"carbon_monoxide", "Danger", "Safe"}, {"cold", "Cold", "Normal"}, {"connectivity", "Connected", "Disconnected"},
{"door", "Open", "Closed"}, {"garage_door", "Open", "Closed"}, {"gas", "Danger", "Safe"},
{"heat", "Hot", "Normal"}, {"light", "Light", "Dark"}, {"lock", "Open", "Locked"}, {"moisture", "Wet", "Dry"},
{"motion", "Motion", "No motion"}, {"moving", "Moving", "Still"}, {"occupancy", "Occupied", "Clear"},
{"opening", "Open", "Closed"}, {"plug", "Plugged in", "Unplugged"}, {"power", "On", "Off"},
{"presence", "Home", "Away"}, {"problem", "Problem", "OK"}, {"running", "Active", "Inactive"},
{"safety", "Unsafe", "Safe"}, {"smoke", "Smoke", "No smoke"}, {"sound", "Sound", "Silent"},
{"tamper", "Tampering", "OK"}, {"update", "Update", "Up to date"}, {"vibration", "Vibration", "Still"},
{"window", "Open", "Closed"},
};
inline const char *binary_state_text(const std::string &device_class, bool on) {
for (const auto &words : BINARY_WORDS)
if (device_class == words.device_class) return on ? words.on : words.off;
return on ? "On" : "Off";
}
// Status line beside a control panel: what Home Assistant shows under the name.
inline std::string status_text(const Tile &t) {
auto d = t.domain(); char b[48];
@@ -190,6 +190,7 @@ inline constexpr Named NAMES[] = {
{"monitor", 0xF0379},
{"information-outline", 0xF02FD},
{"restart", 0xF0709},
{"lightbulb-off", 0xF0E4F},
};
inline constexpr size_t NAME_COUNT = sizeof(NAMES) / sizeof(NAMES[0]);
// Codepoint of a name the fonts carry; 0 for any other name.
+24
View File
@@ -176,6 +176,30 @@ icons sit off-center in the browser); run `generate_packages.py` afterward.
The `MDI_GLYPH_*` substitutions are retired: `TILEn_ICON` in manual
profiles must come from the set. No changed preferences or keys.
### Compatibility 0.2.62 / firmware 0.2.53
Firmware (`components/smart_display`), the icon fonts and the top bar's icon. Storage, tile protocol, preferences and
keys are unchanged; nothing new on the wire.
- A binary sensor's tile (`render_slot`) and card (`detail_state`) turn `on`/`off` into words with
`tile_controls::binary_state_text(device_class, on)`, from the `device_class` attribute every state message has
carried since app 0.2.23. `BINARY_WORDS` is a copy of the app's `header_bar.BINARY_STATES` (top bar, history card
`states` and `words`); `tests/test_binary_words.py` keeps them equal, so change a word in both in one release.
- The screen maps the class itself instead of the app sending words: it works with every app since 0.2.23 (screens
build from `ref: main`, so new firmware can meet an older app), costs the CYD no RAM per tile (the table lives in
flash, the class was already kept), and adds no field for older firmware to ignore.
- `history_words` reads `history.words` only for the card's own entity. A card waiting for its history used to take
the previous card's words (a motion sensor opened after a door read "Open", a switch too).
- Off looks off, as Home Assistant's frontend does it (checked on the `dev` branch and on a live dashboard):
`light/icons.json` gives `mdi:lightbulb`, and `mdi:lightbulb-off` while off; anything off takes
`--state-inactive-color` (grey); an entity's own icon never changes. `icon_for` draws F0E4F for a light without
`tile.icon` while it is off (its own `if`, so `test_tile_icons` still reads the domain default), `render_slot` greys
lights and binary sensors that are not active, as it did for switches, people and timers, and
`header_bar.auto_icon` gives an off light the same bulb. `lightbulb-off` joins `tile_icons.FIXED`: one glyph more in
the three icon fonts of both boards and in the editor font.
- App 0.2.62 with firmware 0.2.52 or older: tiles unchanged; an off light's top bar item shows without an icon, since
that firmware drops a glyph its font lacks (`has_icon_glyph`).
### Compatibility 0.2.60 / firmware 0.2.52
`components/smart_display` and both board profiles; the app only raises `FIRMWARE_VERSION`. Storage, tile protocol,
+56
View File
@@ -0,0 +1,56 @@
# Test results app 0.2.62 / firmware 0.2.53 (2026-09-17)
A binary sensor tile read "On" or "Off" where Home Assistant says "Open" or "Closed", and a user (Remco) asked for a
different icon for lights that are off. Max asked to do it the way Home Assistant's web interface does. See CHANGELOG
0.2.62 and the compatibility note in docs/RELEASING.md.
## Home Assistant's own behaviour
- Source, `dev` branch: `homeassistant/components/light/icons.json` gives `mdi:lightbulb`, and `mdi:lightbulb-off`
for state off (switch, fan and input_boolean have the same pattern); the frontend colours active lights
`--state-light-active-color` (amber) and anything off `--state-inactive-color` (grey).
- Live on Max's dashboard: lights that are on have an amber icon on a pastel amber circle; lights that are off are grey,
with a crossed-out icon where the icon has one; a light with its own icon (a mirror) keeps it and turns grey.
## Automated
- Python (`.venv-portal`): all tests OK. New `tests/test_binary_words.py` (5): the firmware's `BINARY_WORDS` equals
`header_bar.BINARY_STATES`; the top bar and the history card give the same words for all 28 classes, and On/Off
without a class or with an unknown one; every state message already carries `device_class` (no `x`); the tile, the
card and the history heading use the words for binary sensors only, and the heading only takes its own entity's
history words; all five text fonts of both profiles and packages carry every letter. New `tests/test_off_look.py`
(3): `lightbulb-off` (F0E4F) in the fonts of both profiles and packages; the firmware's off bulb and grey rule; the
top bar's off bulb, a light's own icon kept, no accent while off.
- C++ (`clang++ -std=c++17 -Wall -Wextra -Werror -I. -I components/smart_display`): 15/15 PASS;
`test_tile_controls` checks door, motion, moisture, battery charging, battery, no class, an unknown class and a
wrongly cased class.
- `generate_packages.py --check` and `generate_icons.py --check` (150 pickable icons, 184 glyphs) green.
## Builds (ESPHome 2026.6.2)
Check profiles with the generated packages and local components, as for 0.2.59. No warnings from `runtime_tiles.h`
or `tile_controls.h`.
| Profile | RAM | Flash | vs 0.2.59 |
|---|---|---|---|
| CYD | 23.5% (77,060 B) | 77.8% (1,428,127 B) | +0 B RAM, +1,112 B flash (0.2.60 and 0.2.61 included) |
| Guition | 24.5% (80,436 B) | 18.9% (1,531,911 B) | +0 B RAM, +1,580 B flash (0.2.60 and 0.2.61 included) |
## Firmware on the Mac (host builds, driven over the ESPHome API)
A demo home with fifteen binary sensors of every kind, lights on and off, and the front door and a light in the top
bar (`.esphome/readme-render/binary/`), with a probe that logs each card's text and colours:
- Before (0.2.52 code): every binary sensor read On or Off in amber, while the top bar said Open and Motion; the door
card said "On" until its history arrived and then "Open"; the motion card opened after the door card said "Open".
- After, Guition and CYD: Open, Closed, Motion, Dry, Smoke, Disconnected, Not charging, Low, Problem, Up to date,
Plugged in (also as a large value); a sensor without a class and an unknown class still say On. The door card says
"Open" while loading and after the answer, and "Closed" once the door closes with the card open; the motion card says
"Motion" while loading. The longest words fit a single CYD tile.
- Off look (Guition): an off light without an icon shows a grey crossed-out bulb, an off light with a chosen lamp icon
a grey lamp, a closed door and a dry leak sensor grey circles; the open door, motion and a light at 50 % stay amber;
the top bar shows the crossed-out bulb for the off light.
## Not tested
- Physical screens: not flashed in this round.
+2 -1
View File
@@ -2,7 +2,7 @@
# Source profile for packages/guition.yaml (tools/generate_packages.py); see docs/GUITION.md.
# A screen gets its tiles from the ESP Screen Manager add-on while it runs. The CYD is its own profile.
substitutions:
SCREEN_FIRMWARE_VERSION: "0.2.52"
SCREEN_FIRMWARE_VERSION: "0.2.53"
# 0: no drift limit; LVGL decides, releasing inside the tile is a tap, leaving it is not
# (like iOS). The CYD keeps a limit because its resistive panel jumps.
TOUCH_MOVE_LIMIT_PX: "0"
@@ -984,6 +984,7 @@ font:
- "\U000F0379" # monitor
- "\U000F02FD" # information-outline
- "\U000F0709" # restart
- "\U000F0E4F" # lightbulb-off
- file: 'fonts/materialdesignicons-webfont.ttf'
id: materialdesign_icons_mini
+2 -1
View File
@@ -17,7 +17,7 @@
############################################################
substitutions:
SCREEN_FIRMWARE_VERSION: "0.2.52"
SCREEN_FIRMWARE_VERSION: "0.2.53"
# A tap survives a finger that drifts up to this far (320 px over 58 mm: 1 cm); further is a swipe.
TOUCH_MOVE_LIMIT_PX: "56"
# Shortest contact that counts as a tap; a resistive panel bounces, a capacitive one does not.
@@ -1102,6 +1102,7 @@ font:
- "\U000F0379" # monitor
- "\U000F02FD" # information-outline
- "\U000F0709" # restart
- "\U000F0E4F" # lightbulb-off
- file: 'fonts/materialdesignicons-webfont.ttf'
id: materialdesign_icons_mini
+2 -1
View File
@@ -18,7 +18,7 @@
############################################################
substitutions:
SCREEN_FIRMWARE_VERSION: "0.2.52"
SCREEN_FIRMWARE_VERSION: "0.2.53"
# A tap survives a finger that drifts up to this far (320 px over 58 mm: 1 cm); further is a swipe.
TOUCH_MOVE_LIMIT_PX: "56"
# Shortest contact that counts as a tap; a resistive panel bounces, a capacitive one does not.
@@ -1091,6 +1091,7 @@ font:
- "\U000F0379" # monitor
- "\U000F02FD" # information-outline
- "\U000F0709" # restart
- "\U000F0E4F" # lightbulb-off
- file: "https://raw.githubusercontent.com/MaxGramser/homeassistant_espscreen/main/fonts/materialdesignicons-webfont.ttf"
id: materialdesign_icons_mini
+2 -1
View File
@@ -3,7 +3,7 @@
# Source profile for packages/guition.yaml (tools/generate_packages.py); see docs/GUITION.md.
# A screen gets its tiles from the ESP Screen Manager add-on while it runs. The CYD is its own profile.
substitutions:
SCREEN_FIRMWARE_VERSION: "0.2.52"
SCREEN_FIRMWARE_VERSION: "0.2.53"
# 0: no drift limit; LVGL decides, releasing inside the tile is a tap, leaving it is not
# (like iOS). The CYD keeps a limit because its resistive panel jumps.
TOUCH_MOVE_LIMIT_PX: "0"
@@ -973,6 +973,7 @@ font:
- "\U000F0379" # monitor
- "\U000F02FD" # information-outline
- "\U000F0709" # restart
- "\U000F0E4F" # lightbulb-off
- file: "https://raw.githubusercontent.com/MaxGramser/homeassistant_espscreen/main/fonts/materialdesignicons-webfont.ttf"
id: materialdesign_icons_mini
+9
View File
@@ -1,3 +1,12 @@
## 0.2.62 (firmware 0.2.53)
On or off at a glance, in Home Assistant's words and colours.
- **A door says Open or Closed.** A binary sensor's tile and card use the words of its kind, the same ones the top bar and the history card show: a door or window Open or Closed, motion Motion or No motion, a leak sensor Wet or Dry, and so on for smoke, battery, connectivity, plugs and the rest. A sensor without a kind still says On or Off.
- **Off looks off.** A light or binary sensor that is off turns grey, as in Home Assistant, and a light without an icon of its own shows a crossed-out bulb while it is off, in the top bar too. An icon you chose stays the same and turns grey, as Home Assistant does with an icon of its own.
- **The history card's heading is right while it loads.** It said On until the history arrived, and a card opened after another one could show that card's word for a moment, such as Open on a motion sensor.
- Needs firmware 0.2.53: press **Update** on the screen. Older firmware keeps On, Off and its colours, and shows an off light in the top bar without an icon.
## 0.2.61 (firmware 0.2.52)
Your own YAML for one screen, kept through updates.
+1 -1
View File
@@ -17,7 +17,7 @@ WEEKDAYS = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su']
REPO = 'https://github.com/MaxGramser/homeassistant_espscreen'
REFS = {'cyd': 'main', 'guition': 'main'}
# Firmware shipped with this app release; screens below it get an update offer.
FIRMWARE_VERSION = '0.2.52'
FIRMWARE_VERSION = '0.2.53'
# The Auto standby switch a screen offers Home Assistant automations.
AUTO_STANDBY_MIN_FIRMWARE = '0.2.41'
# The settings page the screen opens itself, and the screen.settings tile that opens it.
+4 -1
View File
@@ -38,7 +38,8 @@ STATES = {
'armed_vacation': 'Armed vacation', 'armed_custom_bypass': 'Armed', 'arming': 'Arming', 'pending': 'Pending',
'triggered': 'Triggered', 'active': 'Active', 'above_horizon': 'Up', 'below_horizon': 'Down',
}
# device_class: (on, off)
# device_class: (on, off). Tiles and cards show the same words from the screen's own copy, BINARY_WORDS in
# components/smart_display/tile_controls.h (firmware 0.2.53+); tests/test_binary_words.py keeps the two equal.
BINARY_STATES = {
'battery': ('Low', 'Normal'), 'battery_charging': ('Charging', 'Not charging'), 'carbon_monoxide': ('Danger', 'Safe'),
'cold': ('Cold', 'Normal'), 'connectivity': ('Connected', 'Disconnected'), 'door': ('Open', 'Closed'),
@@ -245,6 +246,8 @@ def auto_icon(entity, state):
domain, device_class = entity.split('.')[0], attrs.get('device_class')
if domain == 'weather':
name = tile_icons.WEATHER.get(raw, 'weather-partly-cloudy')
elif domain == 'light' and raw == 'off':
name = 'lightbulb-off'
elif domain == 'sun':
name = 'weather-sunset-down' if raw == 'above_horizon' else 'weather-sunset-up'
elif domain == 'binary_sensor' and device_class in BINARY_ICONS:
Binary file not shown.
+2
View File
@@ -224,6 +224,8 @@ FIXED = (
('monitor', 'F0379'),
('information-outline', 'F02FD'),
('restart', 'F0709'),
# A light that is off, as Home Assistant shows one without an icon of its own (firmware 0.2.53+).
('lightbulb-off', 'F0E4F'),
)
# Pickable icons by name, and every glyph the firmware fonts contain.
+1 -1
View File
@@ -1,5 +1,5 @@
name: ESP Screen Manager
version: "0.2.61"
version: "0.2.62"
slug: esp_screen_manager
description: Choose tiles for your CYD and Guition touchscreen, without reflashing.
url: https://github.com/MaxGramser/homeassistant_espscreen
+74
View File
@@ -0,0 +1,74 @@
"""Binary sensors in Home Assistant's words (app 0.2.62 / firmware 0.2.53): a door tile says Open or Closed.
The screen maps the device class itself (`tile_controls::binary_state_text`), from the `device_class` attribute every
state message has carried since app 0.2.23: nothing new on the wire, so it works with older apps too. These tests keep
its table equal to the add-on's `header_bar.BINARY_STATES`, which the top bar and the history card use.
"""
import re
import sys
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / 'screen_manager/app'))
import header_bar # noqa: E402
import history_card # noqa: E402
from core import state_message # noqa: E402
CONTROLS = (ROOT / 'components/smart_display/tile_controls.h').read_text()
TILES = (ROOT / 'components/smart_display/runtime_tiles.h').read_text()
PROFILES = ('guition-4848s040.yaml', 'home-like-2432s028.yaml', 'packages/cyd.yaml', 'packages/guition.yaml')
def firmware_words():
block = re.search(r'constexpr BinaryWords BINARY_WORDS\[\] = \{(.*?)\n\};', CONTROLS, re.S)
return {device_class: (on, off) for device_class, on, off in re.findall(r'\{"(\w+)", "([^"]*)", "([^"]*)"\}', block.group(1))}
class BinaryWords(unittest.TestCase):
def test_the_screen_carries_the_add_on_s_words(self):
self.assertEqual(firmware_words(), header_bar.BINARY_STATES)
def test_top_bar_and_history_card_say_the_same(self):
for device_class, (on, off) in header_bar.BINARY_STATES.items():
attrs = {'device_class': device_class}
for raw, words in (('on', on), ('off', off)):
self.assertEqual(header_bar.value('binary_sensor.x', {'state': raw, 'attributes': attrs}), (words, None))
self.assertEqual(history_card.state_label('binary_sensor', raw, attrs), words)
# Without a class, or with one Home Assistant adds later, all of them say On and Off.
for attrs in ({}, {'device_class': 'future_class'}):
self.assertEqual(header_bar.value('binary_sensor.x', {'state': 'on', 'attributes': attrs}), ('On', None))
self.assertEqual(history_card.state_label('binary_sensor', 'off', attrs), 'Off')
self.assertIn('return on ? "On" : "Off";', CONTROLS)
def test_the_state_message_already_carries_the_class(self):
tile = {'entity': 'binary_sensor.front_door', 'name': ''}
states = {'binary_sensor.front_door': {'state': 'on', 'attributes': {'device_class': 'door', 'friendly_name': 'Front door'}}}
message = state_message(0, tile, states)
self.assertEqual((message['state'], message['a']['device_class']), ('on', 'door'))
self.assertNotIn('x', message)
self.assertIn('tile.device_class=string(a["device_class"],24);', TILES)
self.assertLessEqual(max(map(len, header_bar.BINARY_STATES)), 24)
def test_tile_card_and_heading_use_them_for_binary_sensors_only(self):
self.assertIn('else if (d == "binary_sensor" && (value == "on" || value == "off")) '
'value = tile_controls::binary_state_text(t.device_class, value == "on");', TILES)
self.assertIn('if(t.domain()=="binary_sensor"&&(t.state=="on"||t.state=="off"))'
'return tile_controls::binary_state_text(t.device_class,t.state=="on");', TILES)
# A card still waiting for its history must not take the words of the card opened before it.
self.assertIn('if(history.entity==t.entity)for(const auto &pair:history.words)', TILES)
def test_the_fonts_carry_every_word(self):
letters = set(''.join(on + off for on, off in header_bar.BINARY_STATES.values()))
self.assertLessEqual(letters, set(header_bar.GLYPHS))
for name in PROFILES:
text = (ROOT / name).read_text()
for font in ('headline', 'watch_value', 'label', 'sublabel', 'sublabel_big'):
block = re.search(r'id: ' + font + r'\n size: \d+\n bpp: 4\n glyphs: \[(.*?)\]\n', text, re.S)
self.assertIsNotNone(block, (name, font))
glyphs = {a or b for a, b in re.findall(r"'([^'])'|\"(')\"", block.group(1))}
self.assertLessEqual(letters, glyphs, (name, font))
if __name__ == '__main__':
unittest.main()
+38
View File
@@ -0,0 +1,38 @@
"""An off light and an off binary sensor look off, as in Home Assistant (app 0.2.62 / firmware 0.2.53).
Home Assistant's own light icon is a bulb that is crossed out while off (`mdi:lightbulb-off`), and every entity that is
off is grey. An icon of its own, or one chosen in ESP Screens, stays the same and turns grey, as in Home Assistant.
"""
import sys
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / 'screen_manager/app'))
import header_bar # noqa: E402
import tile_icons # noqa: E402
TILES = (ROOT / 'components/smart_display/runtime_tiles.h').read_text()
class OffLook(unittest.TestCase):
def test_the_fonts_carry_the_bulb_that_is_off(self):
self.assertEqual(tile_icons.GLYPHS['lightbulb-off'], 'F0E4F')
for name in ('guition-4848s040.yaml', 'home-like-2432s028.yaml', 'packages/cyd.yaml', 'packages/guition.yaml'):
self.assertIn('"\\U000F0E4F" # lightbulb-off', (ROOT / name).read_text(), name)
def test_the_screen_crosses_out_its_own_bulb_and_greys_what_is_off(self):
self.assertIn('if (d == "light" && tile.state == "off") return "\\U000F0E4F";', TILES)
self.assertIn('(t.is_switch()||d=="light"||d=="binary_sensor"||d=="person"||d=="timer") && !on ? 0x9E9E9E : accent', TILES)
def test_the_top_bar_does_the_same(self):
light = lambda state, **attrs: {'state': state, 'attributes': attrs}
self.assertEqual(header_bar.auto_icon('light.hall', light('off')), tile_icons.GLYPHS['lightbulb-off'])
self.assertEqual(header_bar.auto_icon('light.hall', light('on')), tile_icons.GLYPHS['lightbulb'])
self.assertEqual(header_bar.auto_icon('light.hall', light('unavailable')), tile_icons.GLYPHS['lightbulb'])
self.assertEqual(header_bar.auto_icon('light.lamp', light('off', icon='mdi:lamp')), tile_icons.GLYPHS['lamp'])
self.assertIsNone(header_bar.accent('light.hall', light('off')))
if __name__ == '__main__':
unittest.main()
+8
View File
@@ -170,5 +170,13 @@ int main() {
assert(old_robot2.choice('s') && old_robot2.choice('s')->labels[1] == "Normal" && old_robot2.choice('s')->current == "balanced");
rows = vacuum_rows(old_robot2, 0);
assert(rows.suction && !rows.water && !choice_action(old_robot2, 'm', "mop").valid());
// Binary sensors (firmware 0.2.53+) in the words of their device class; no class or an unknown one says On and Off.
assert(!strcmp(binary_state_text("door", true), "Open") && !strcmp(binary_state_text("door", false), "Closed"));
assert(!strcmp(binary_state_text("motion", true), "Motion") && !strcmp(binary_state_text("motion", false), "No motion"));
assert(!strcmp(binary_state_text("moisture", true), "Wet") && !strcmp(binary_state_text("moisture", false), "Dry"));
assert(!strcmp(binary_state_text("battery_charging", false), "Not charging") && !strcmp(binary_state_text("battery", true), "Low"));
assert(!strcmp(binary_state_text("", true), "On") && !strcmp(binary_state_text("", false), "Off"));
assert(!strcmp(binary_state_text("future_class", true), "On") && !strcmp(binary_state_text("Door", true), "On"));
return 0;
}