cdnninja/yoto_ha

Can't use volume +/-

Closed this issue · 10 comments

When I try to use the control volume +/- it does not work and the logs shows the following error

2024-05-23 21:00:23.670 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback Entity._async_write_ha_state_from_call_soon_threadsafe()
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1001, in _async_write_ha_state_from_call_soon_threadsafe
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1132, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1069, in __async_calculate_state
    if state_attributes := self.state_attributes:
                           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 1115, in state_attributes
    if (value := getattr(self, attr)) is not None:
                 ^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/yoto/media_player.py", line 136, in media_title
    return self.player.chapter_title + " - " + self.player.track_title
           ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

I'm using a yoto v2 Firmware: v2.17.5-5 with home assistant running in a container ghcr.io/home-assistant/raspberrypi4-homeassistant:stable which contains Core 2024.5.2 and Frontend 20240501.1

That looks like a title bug. Could you retest while something is playing?

Could you retest while something is playing?

I've actually tested it while playing yoto sleep radio

If you update to "master" it should solve this. Release version will come in next few days.

I created a release. Let me know if fixed!

A super minor comment regarding volume control: when I turn the knob on my mini down to 0 (mute) it still shows 6 in HA. I would expect HA should go to down to 0 as well.

@cdnninja thank you for the fix. It works as expexted.
However, the volume scale seems wrong.
My yoto has the volume from 0 to 16.
Screenshot_20240524-225455.png

The integration shows a volume from 0 to 100
Here is the value from yoto
Screenshot_20240524-225401.png
Here is the value from ha AT the same time.
Screenshot_20240524-225343.png

Unfortunately I can't find a way to change the home assistant scale. It's 0-100. Also 100/16 doesn't fit into a reasonable scale. Interestingly enough the command to send to yoto within the yoto api is also 0-100 with some strange rounding that maps to 0-16.

Looks like with +/- I can't get to 2. Right now I have a value of 6 for steps. I passed 6.25 but I think HA is ignoring the .25.

The value mapping from playing with my yoto is: https://github.com/cdnninja/yoto_api/blob/c0452a31a32f93ca9de3b153930fecb0df4b09d9/yoto_api/const.py#L38-L56

The challenge is that those numbers don't follow the pattern I would expect.

Haven't had a chance to test yet but I think this may be better now.

it is working as expected on my end