Skip to content

Fix KeyError: 'volume' & KeyError: 'muted' for alga volume get#73

Closed
MrJarnould wants to merge 1 commit intoTenzer:mainfrom
MrJarnould:fix_volume_get
Closed

Fix KeyError: 'volume' & KeyError: 'muted' for alga volume get#73
MrJarnould wants to merge 1 commit intoTenzer:mainfrom
MrJarnould:fix_volume_get

Conversation

@MrJarnould
Copy link
Copy Markdown

Running alga volume get results in these errors:

╭─────────────────────────────────────────────────────────────────────────────────────── Traceback (most recent call last) ───────────────────────────────────────────────────────────────────────────────────────╮
│ ~/.local/pipx/venvs/alga/lib/python3.12/site-packages/alga/cli_volume.py:25 in get                                                                                                                   │
│                                                                                                                                                                                                                 │
│   22 │                                                                                                                                                                                                          │
│   23 │   response = client.request("ssap://audio/getVolume")                                                                                                                                                    │
│   24 │   print(                                                                                                                                                                                                 │
│ ❱ 25 │   │   f"Volume is currently set to [bold]{response['volume']}[/bold] and is currently                                                                                                                    │
│   26 │   )                                                                                                                                                                                                      │
│   27                                                                                                                                                                                                            │
│   28                                                                                                                                                                                                            │
│                                                                                                                                                                                                                 │
│ ╭──────────────────────────────────────────────────────────────────────────────────── locals ─────────────────────────────────────────────────────────────────────────────────────╮                             │
│ │ response = {                                                                                                                                                                    │                             │
│ │            │   'volumeStatus': {                                                                                                                                                │                             │
│ │            │   │   'activeStatus': True,                                                                                                                                        │                             │
│ │            │   │   'adjustVolume': True,                                                                                                                                        │                             │
│ │            │   │   'maxVolume': 100,                                                                                                                                            │                             │
│ │            │   │   'muteStatus': True,                                                                                                                                          │                             │
│ │            │   │   'volume': 17,                                                                                                                                                │                             │
│ │            │   │   'mode': 'normal',                                                                                                                                            │                             │
│ │            │   │   'soundOutput': 'tv_speaker'                                                                                                                                  │                             │
│ │            │   },                                                                                                                                                               │                             │
│ │            │   'returnValue': True,                                                                                                                                             │                             │
│ │            │   'callerId': 'secondscreen.client'                                                                                                                                │                             │
│ │            }                                                                                                                                                                    │                             │
│ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                             │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
KeyError: 'volume'
╭─────────────────────────────────────────────────────────────────────────────────────── Traceback (most recent call last) ───────────────────────────────────────────────────────────────────────────────────────╮
│ ~/.local/pipx/venvs/alga/lib/python3.12/site-packages/alga/cli_volume.py:25 in get                                                                                                                   │
│                                                                                                                                                                                                                 │
│   22 │                                                                                                                                                                                                          │
│   23 │   response = client.request("ssap://audio/getVolume")                                                                                                                                                    │
│   24 │   print(                                                                                                                                                                                                 │
│ ❱ 25 │   │   f"Volume is currently set to [bold]{response['volumeStatus']['volume']}[/bold] a                                                                                                                   │
│   26 │   )                                                                                                                                                                                                      │
│   27                                                                                                                                                                                                            │
│   28                                                                                                                                                                                                            │
│                                                                                                                                                                                                                 │
│ ╭──────────────────────────────────────────────────────────────────────────────────── locals ─────────────────────────────────────────────────────────────────────────────────────╮                             │
│ │ response = {                                                                                                                                                                    │                             │
│ │            │   'volumeStatus': {                                                                                                                                                │                             │
│ │            │   │   'activeStatus': True,                                                                                                                                        │                             │
│ │            │   │   'adjustVolume': True,                                                                                                                                        │                             │
│ │            │   │   'maxVolume': 100,                                                                                                                                            │                             │
│ │            │   │   'muteStatus': True,                                                                                                                                          │                             │
│ │            │   │   'volume': 17,                                                                                                                                                │                             │
│ │            │   │   'mode': 'normal',                                                                                                                                            │                             │
│ │            │   │   'soundOutput': 'tv_speaker'                                                                                                                                  │                             │
│ │            │   },                                                                                                                                                               │                             │
│ │            │   'returnValue': True,                                                                                                                                             │                             │
│ │            │   'callerId': 'secondscreen.client'                                                                                                                                │                             │
│ │            }                                                                                                                                                                    │                             │
│ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                             │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
KeyError: 'muted'

Updating the print statement to response['volumeStatus']['volume'] and response['volumeStatus']['muteStatus'] fixes it.

@Tenzer
Copy link
Copy Markdown
Owner

Tenzer commented Dec 2, 2024

Thank you for submitting this. I'll have to test it with my TV, as it's possible different versions of webOS have different response payloads.

The existing code at least works for my TV. In case the changes here doesn't match the response payloads on my TV, I'll probably have to check both.

@Tenzer
Copy link
Copy Markdown
Owner

Tenzer commented Dec 2, 2024

I tested it on my TV now, and I can see the response payload from it is:

{"returnValue": true, "scenario": "mastervolume_tv_speaker", "volume": 15, "muted": false}

which isn't compatible with your proposed changes.

I'll try to get it to support both formats, possibly tonight.

Are you able to check as many other of the alga commands as you can, to see if they have incompatible payloads too?

Also, if you don't mind, could you tell me what model of TV you have, so I have some idea of if this is a newer or older response format compared to what I have tested against.

Tenzer added a commit that referenced this pull request Dec 2, 2024
The response use a slightly different format for newer webOS versions than what
I have available, so I haven't been aware of this difference until it was
reported in #73.
@Tenzer
Copy link
Copy Markdown
Owner

Tenzer commented Dec 2, 2024

Would you be able to test out the changes in #75 to check it works for you as well? It should support both the old and new response formats.

Tenzer added a commit that referenced this pull request Dec 9, 2024
…and (#75)

The response use a slightly different format for newer webOS versions than what
I have available, so I haven't been aware of this difference until it was
reported in #73.
@Tenzer
Copy link
Copy Markdown
Owner

Tenzer commented Dec 9, 2024

I have merged the other PR, it will be out in a release a bit later today.

@Tenzer Tenzer closed this Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants