Repository: jschlyter/ttls (language: python)

Issue:
Playlist mode
Hello,

currently this client seems to be hardcoded to start lights in the movie mode: https://github.com/jschlyter/ttls/blob/707e860109f7aacc613e8d9aa98038498d9e37ff/ttls/client.py#L261

Can it be possible to start the lights in playlist mode instead if that was last selected mode (mode where you set up a playlist in the Twinkly app and then lights follow that sequence)? Or maybe to allow to choose in with mode it should start?





Discussion / hints:

Fix patch:
diff --git a/ttls/client.py b/ttls/client.py
index 16290b8..9d5c6a8 100644
--- a/ttls/client.py
+++ b/ttls/client.py
@@ -43,7 +43,15 @@
 TwinklyResult = Optional[dict]
 
 
-TWINKLY_MODES = ["rt", "movie", "off", "demo", "effect"]
+TWINKLY_MODES = [
+    "color",
+    "demo",
+    "effect",
+    "movie",
+    "off",
+    "playlist",
+    "rt",
+]
 RT_PAYLOAD_MAX_LIGHTS = 300
 
 TWINKLY_MUSIC_DRIVERS_OFFICIAL = {
@@ -107,6 +115,7 @@ def __init__(
         self._expires = None
         self._token = None
         self._details: Dict[str, Union[str, int]] = {}
+        self._default_mode = "movie"
 
     @property
     def base(self) -> str:
@@ -116,6 +125,18 @@ def base(self) -> str:
     def length(self) -> int:
         return int(self._details["number_of_led"])
 
+    @property
+    def default_mode(self) -> str:
+        return self._default_mode
+
+    @default_mode.setter
+    def default_mode(self, mode: str) -> str:
+        if mode not in TWINKLY_MODES:
+            raise ValueError("Invalid mode")
+        if mode == "off":
+            _LOGGER.warning("Setting default mode to off")
+        self._default_mode = mode
+
     async def close(self) -> None:
         if not self._shared_session:
             await self._session.close()
@@ -256,7 +277,7 @@ async def is_on(self) -> Optional[bool]:
         return mode.get("mode", "off") != "off"
 
     async def turn_on(self) -> Any:
-        return await self.set_mode("movie")
+        return await self.set_mode(self._default_mode)
 
     async def turn_off(self) -> Any:
         return await self.set_mode("off")


Test patch:
diff --git a/tests/test_config.py b/tests/test_config.py
new file mode 100644
index 0000000..f2088e0
--- /dev/null
+++ b/tests/test_config.py
@@ -0,0 +1,14 @@
+import unittest
+
+from ttls.client import Twinkly
+
+
+class TestTwinklyConfig(unittest.TestCase):
+    def setUp(self):
+        self.client = Twinkly(host="192.0.2.1")
+
+    def test_set_default_mode(self):
+        self.client.default_mode = "movie"
+        self.assertEqual(self.client.default_mode, "movie")
+        with self.assertRaises(ValueError):
+            self.client.default_mode = "b0rken"