Skip to content

Screen state does not work when tv is off #353

@zany130

Description

@zany130

I am trying to rewrite https://github.com/Faceless3882/LG_Buddy to use alga instead of https://github.com/chros73/bscpylgtv as i find alga easier to work with.

One of the things LG_Buddy does is check the state of the tv before sending a command ex: https://github.com/Faceless3882/LG_Buddy/blob/2df3c413eae7640d51226c23c64d193d357006e1/bin/LG_Buddy_Startup#L19

I saw #332 was merged and added a power screen-state option but unlike bscpylgtv eqivulent command it seems to not work if the tv is off

 alga power screen-state                                                                                                                                                                                                         ─╯
╭──────────────────────────────────────────────────────────────────────────────────────────────── Traceback (most recent call last) ─────────────────────────────────────────────────────────────────────────────────────────────────╮
│ /var/home/zany130/.local/share/pipx/venvs/alga/lib/python3.13/site-packages/alga/cli_power.py:48 in screen_state                                                                                                                   │
│                                                                                                                                                                                                                                    │
│   45 def screen_state() -> None:                                                                                                                                                                                                   │
│   46 │   """Show if TV screen is active or off"""                                                                                                                                                                                  │
│   47 │                                                                                                                                                                                                                             │
│ ❱ 48 │   response = client.request("ssap://com.webos.service.tvpower/power/getPowerState")                                                                                                                                         │
│   49 │   print(f"The TV screen is currently: [bold]{response['state']}[/bold]")                                                                                                                                                    │
│   50                                                                                                                                                                                                                               │
│                                                                                                                                                                                                                                    │
│ /var/home/zany130/.local/share/pipx/venvs/alga/lib/python3.13/site-packages/alga/client.py:50 in request                                                                                                                           │
│                                                                                                                                                                                                                                    │
│   47 │   tv = cfg["tvs"][tv_id]                                                                                                                                                                                                    │
│   48 │                                                                                                                                                                                                                             │
│   49 │   with connect(tv["hostname"]) as connection:                                                                                                                                                                               │
│ ❱ 50 │   │   do_handshake(connection, tv["key"])                                                                                                                                                                                   │
│   51 │   │                                                                                                                                                                                                                         │
│   52 │   │   request: dict[str, Any] = {"type": "request", "uri": uri}                                                                                                                                                             │
│   53                                                                                                                                                                                                                               │
│                                                                                                                                                                                                                                    │
│ ╭─────────────────────────────────────────────────────────────────────────────────── locals ────────────────────────────────────────────────────────────────────────────────────╮                                                  │
│ │        cfg = {'version': 2, 'default_tv': 'default', 'tvs': {'default': {'hostname': '192.168.4.48', 'key': 'c9ba71bf47449974ce6fdb52ca3c1e5a', 'mac': 'ac:5a:f0:66:8e:41'}}} │                                                  │
│ │ connection = <websocket._core.WebSocket object at 0x7f4d4a3a5400>                                                                                                             │                                                  │
│ │       data = None                                                                                                                                                             │                                                  │
│ │         tv = {'hostname': '192.168.4.48', 'key': 'c9ba71bf47449974ce6fdb52ca3c1e5a', 'mac': 'ac:5a:f0:66:8e:41'}                                                              │                                                  │
│ │      tv_id = 'default'                                                                                                                                                        │                                                  │
│ │        uri = 'ssap://com.webos.service.tvpower/power/getPowerState'                                                                                                           │                                                  │
│ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                                                  │
│                                                                                                                                                                                                                                    │
│ /var/home/zany130/.local/share/pipx/venvs/alga/lib/python3.13/site-packages/alga/client.py:28 in do_handshake                                                                                                                      │
│                                                                                                                                                                                                                                    │
│   25                                                                                          ╭───────────────────────────── locals ──────────────────────────────╮                                                                │
│   26 def do_handshake(connection: WebSocket, key: str) -> None:                               │ connection = <websocket._core.WebSocket object at 0x7f4d4a3a5400> │                                                                │
│   27 │   connection.send(json.dumps(get_hello_data(key)))                                     │        key = 'c9ba71bf47449974ce6fdb52ca3c1e5a'                   │                                                                │
│ ❱ 28 │   response = json.loads(connection.recv())                                             ╰───────────────────────────────────────────────────────────────────╯                                                                │
│   29 │   if "client-key" not in response["payload"]:                                                                                                                                                                               │
│   30 │   │   raise Exception(                                                                                                                                                                                                      │
│   31 │   │   │   f"Something went wrong with performing a handshake. Response: {response}"                                                                                                                                         │
│                                                                                                                                                                                                                                    │
│ /home/linuxbrew/.linuxbrew/opt/python@3.13/lib/python3.13/json/__init__.py:352 in loads                                                                                                                                            │
│                                                                                                                                                                                                                                    │
│   349 │   if (cls is None and object_hook is None and                                          ╭───────── locals ─────────╮                                                                                                        │
│   350 │   │   │   parse_int is None and parse_float is None and                                │               cls = None │                                                                                                        │
│   351 │   │   │   parse_constant is None and object_pairs_hook is None and not kw):            │                kw = {}   │                                                                                                        │
│ ❱ 352 │   │   return _default_decoder.decode(s)                                                │       object_hook = None │                                                                                                        │
│   353 │   if cls is None:                                                                      │ object_pairs_hook = None │                                                                                                        │
│   354 │   │   cls = JSONDecoder                                                                │    parse_constant = None │                                                                                                        │
│   355 │   if object_hook is not None:                                                          │       parse_float = None │                                                                                                        │
│                                                                                                │         parse_int = None │                                                                                                        │
│                                                                                                │                 s = ''   │                                                                                                        │
│                                                                                                ╰──────────────────────────╯                                                                                                        │
│                                                                                                                                                                                                                                    │
│ /home/linuxbrew/.linuxbrew/opt/python@3.13/lib/python3.13/json/decoder.py:345 in decode                                                                                                                                            │
│                                                                                                                                                                                                                                    │
│   342 │   │   containing a JSON document).                                                     ╭─────────────────────────────── locals ────────────────────────────────╮                                                           │
│   343 │   │                                                                                    │   _w = <built-in method match of re.Pattern object at 0x7f4d4b19b100> │                                                           │
│   344 │   │   """                                                                              │    s = ''                                                             │                                                           │
│ ❱ 345 │   │   obj, end = self.raw_decode(s, idx=_w(s, 0).end())                                │ self = <json.decoder.JSONDecoder object at 0x7f4d4b127770>            │                                                           │
│   346 │   │   end = _w(s, end).end()                                                           ╰───────────────────────────────────────────────────────────────────────╯                                                           │
│   347 │   │   if end != len(s):                                                                                                                                                                                                    │
│   348 │   │   │   raise JSONDecodeError("Extra data", s, end)                                                                                                                                                                      │
│                                                                                                                                                                                                                                    │
│ /home/linuxbrew/.linuxbrew/opt/python@3.13/lib/python3.13/json/decoder.py:363 in raw_decode                                                                                                                                        │
│                                                                                                                                                                                                                                    │
│   360 │   │   try:                                                                             ╭────────────────────────── locals ──────────────────────────╮                                                                      │
│   361 │   │   │   obj, end = self.scan_once(s, idx)                                            │  idx = 0                                                   │                                                                      │
│   362 │   │   except StopIteration as err:                                                     │    s = ''                                                  │                                                                      │
│ ❱ 363 │   │   │   raise JSONDecodeError("Expecting value", s, err.value) from None             │ self = <json.decoder.JSONDecoder object at 0x7f4d4b127770> │                                                                      │
│   364 │   │   return obj, end                                                                  ╰────────────────────────────────────────────────────────────╯                                                                      │
│   365                                                                                                                                                                                                                              │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions