alandtse / alexa_media_player

This is a custom component to allow control of Amazon Alexa devices in Home Assistant using the unofficial Alexa API.
Apache License 2.0
1.54k stars 291 forks source link

Exception when attempting to modify volume of echo dot #490

Closed treydock closed 4 years ago

treydock commented 4 years ago

Describe the bug A clear and concise description of what the bug is.

Exception:

    if self.volume_level < 1 and self.supported_features & SUPPORT_VOLUME_SET:
TypeError: '<' not supported between instances of 'NoneType' and 'int'

Full trace:

'<' not supported between instances of 'NoneType' and 'int'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 133, in handle_call_service
    connection.context(msg),
  File "/usr/src/homeassistant/homeassistant/core.py", line 1235, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/usr/src/homeassistant/homeassistant/core.py", line 1260, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 205, in handle_service
    self._platforms.values(), func, call, service_name, required_features
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 336, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 358, in _handle_service_platform_call
    await getattr(entity, func)(**data)
  File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 743, in async_volume_up
    if self.volume_level < 1 and self.supported_features & SUPPORT_VOLUME_SET:
TypeError: '<' not supported between instances of 'NoneType' and 'int'

To Reproduce Steps to reproduce the behavior:

  1. Go to Developer Tools -> Services
  2. Select Service of media_player.volume_up
  3. Choose entity, mine is media_player.upstrairs_echo_dot
  4. Content of YAML is entity_id: media_player.upstairs_echo_dot
  5. Click "Call Service"
  6. Get error

Expected behavior Be able to adjust volume

System details

alandtse commented 4 years ago

Thanks. Can you confirm the affected echo dot actually is displaying media info? The error is reporting the volume_level doesn't exist which may mean the echo dot isn't reporting any information so other things should be broken.

You can see this under Developer Tools -> States.

Please also confirm this isn't happening while you're playing through an Alexa group.

treydock commented 4 years ago

Under states there is state for this device:

is_volume_muted: false
media_content_type: standby
media_position_updated_at: '2019-12-24T22:59:11.677625+00:00'
source: Local Speaker
source_list:
  - Local Speaker
available: true
last_called: true
friendly_name: Upstairs Echo Dot
supported_features: 56253

I was trying to adjust the volume of the device for notifications, does the volume only work when actually playing media?

alandtse commented 4 years ago

No, it should work. However, the fact it doesn't have a volume_level is strange. Does the media player show anything when you play music on it?

alandtse commented 4 years ago

Looking at this closer, the error is coming from HA and not from the custom_component. The standard HA media player requires the volume_level to be set before a volume command will work. However, there is a case where the volume level may not be known yet by the component because it hasn't received any volume info from a device. This can happen if the device has never reported its volume through a websocket update, has never played media that reports volume while the component was running. (i.e., Amazon music gives volume while Spotify doesn't.) We can probably set a default volume and not clear out volume data moving forward.

energywave commented 3 years ago

I was looking about a similar problem so I've read this that's actual even now in 2021. When HA restarts volume of all my Echo Dot devices go to 0. Inspecting the state of the entities this is the result:

source_list:
  - Local Speaker
is_volume_muted: false
media_content_type: standby
media_position_updated_at: '2021-10-31T11:30:09.199819+00:00'
source: Local Speaker
available: true
last_called: false
last_called_timestamp: null
last_called_summary: null
connected_bluetooth: null
bluetooth_list: []
friendly_name: Alexa mansarda
supported_features: 56253

As you see I'm missing the volume_level too. And it remains so until I change the volume explicitly using HA.

So the question is: isn't there a way to detect the current volume_level when Home Assistant starts? Possibly in your integration but even a workaround that I can trigget at start to let Amazon send the volume_level of my devices will be ok. Is there something I can do to force a volume_level refresh? Otherwise I'll be forced to set a volume level when HA starts.... :(

terzo33 commented 3 years ago

I have the same problem when restart home assistant, volume_level is missing

calas80 commented 3 years ago

Me too. Same problem