From 512a2b4a2821a1edadf5530d060e3ae5468d75e8 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Thu, 12 Nov 2026 09:01:06 +0100 Subject: fix(tablet): restore the backlight after a restart or shutdown The server never ran the modules' stop: `deck-it stop` ends it with SIGTERM and nothing called stop_all, so a shutdown left the tablet dim. A SIGTERM handler now runs stop_all before exiting. The settings from before a dim lived only in memory, so a new server's undim had nothing to put back. They are now kept in ~/.cache/deck-it/dim, and a freshly loaded page asks for undim, since it is never dimmed itself. Co-Authored-By: Claude Opus 5.5 --- tests/test_tablet.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/test_tablet.py b/tests/test_tablet.py index 611810a..9f5f007 100644 --- a/tests/test_tablet.py +++ b/tests/test_tablet.py @@ -15,6 +15,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import sys +import tempfile from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) @@ -64,15 +65,19 @@ class Dim(unittest.TestCase): answers = {"settings get system screen_brightness_mode": "1\n", "settings get system screen_brightness": "200\n"} tablet._adb = lambda *a, **k: calls.append(a[-1]) or answers.get(a[-1], "") - try: - m = tablet.make({"tablet": {"dim_brightness": 5}}) - with unittest.mock.patch.object(tablet, "_find_tablet", return_value="x"): + with tempfile.TemporaryDirectory() as d, \ + unittest.mock.patch.object(tablet, "DIM_FILE", Path(d) / "dim"), \ + unittest.mock.patch.object(tablet, "_find_tablet", return_value="x"): + try: + m = tablet.make({"tablet": {"dim_brightness": 5}}) m.actions["dim"]({}) m.actions["dim"]({}) # already dim: the saved level is kept + m = tablet.make({"tablet": {"dim_brightness": 5}}) # a restarted server m.actions["undim"]({}) m.actions["undim"]({}) # already bright: nothing sent - finally: - tablet._adb = orig + self.assertFalse(tablet.DIM_FILE.exists()) + finally: + tablet._adb = orig sets = [c for c in calls if "put" in c] self.assertEqual(sets, [ "settings put system screen_brightness_mode 0; settings put system screen_brightness 5", -- cgit v1.2.3