Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cast the volume_level of a universal media_player to a float #29045

Merged

Conversation

michaelarnauts
Copy link
Contributor

Description:

The universal media_player can be configured to fetch it's volume from another sensor's state (like from a mqtt source). Since a sensor state is string, the result of the media_player's volume_level will also be a string.

This causes issues in other parts of the code (like the google_assistant trait that returns the volume) that expect a volume_level to be a float instead of a string.

Config like this:

media_player:
- platform: universal
  name: receiver
  children:
    - media_player.kodi
    - media_player.living_room_chromecast
  commands:
    # ...
  attributes:
    # ...
    volume_level: sensor.avr_volume

sensors:
- platform: mqtt
  name: avr_volume
  state_topic: "media/cec/volume"
  availability_topic: "media/bridge/status"
  value_template: "{{ value_json / 100 | float }}"

Related issue (if applicable): fixes #29044

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the [development checklist][dev-checklist]

@michaelarnauts
Copy link
Contributor Author

Hmm, it seems that the tests assume the output is a string, but the rest Home Assistant doesn't. I assume the tests are wrong.

@balloob balloob merged commit cc346e5 into home-assistant:dev Nov 26, 2019
@lock lock bot locked and limited conversation to collaborators Nov 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error fetching state of media_player in Google Assistant
3 participants