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

michaelarnauts commented Nov 25, 2019

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

This comment has been minimized.

Copy link
Contributor Author

michaelarnauts commented Nov 25, 2019

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
11 checks passed
11 checks passed
CI #20191125.82 succeeded
Details
CI (FullCheck Mypy) FullCheck Mypy succeeded
Details
CI (FullCheck Pylint) FullCheck Pylint succeeded
Details
CI (Overview CheckFormat) Overview CheckFormat succeeded
Details
CI (Overview Lint) Overview Lint succeeded
Details
CI (Overview Validate) Overview Validate succeeded
Details
CI (Tests PyTest Python36) Tests PyTest Python36 succeeded
Details
CI (Tests PyTest Python37) Tests PyTest Python37 succeeded
Details
cla-bot Everyone involved has signed the CLA
codecov/patch 100% of diff hit (target 94.47%)
Details
codecov/project 94.47% (target 90%)
Details
@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.
Projects
None yet
3 participants
You can’t perform that action at this time.