Skip to content

Commit

Permalink
Fix sonos volume always showing 0 (#48685)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Apr 5, 2021
1 parent 30382c3 commit 6dc1414
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions homeassistant/components/sonos/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,9 +885,9 @@ def async_update_content(self, event: Event | None = None) -> None:
self.async_write_ha_state()

@property
def volume_level(self) -> int | None:
def volume_level(self) -> float | None:
"""Volume level of the media player (0..1)."""
return self._player_volume and int(self._player_volume / 100)
return self._player_volume and self._player_volume / 100

@property
def is_volume_muted(self) -> bool | None:
Expand Down
4 changes: 4 additions & 0 deletions tests/components/sonos/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def soco_fixture(music_library, speaker_info, dummy_soco_service):
mock_soco.renderingControl = dummy_soco_service
mock_soco.zoneGroupTopology = dummy_soco_service
mock_soco.contentDirectory = dummy_soco_service
mock_soco.mute = False
mock_soco.night_mode = True
mock_soco.dialog_mode = True
mock_soco.volume = 19

yield mock_soco

Expand Down
15 changes: 15 additions & 0 deletions tests/components/sonos/test_media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pytest

from homeassistant.components.sonos import DOMAIN, media_player
from homeassistant.const import STATE_IDLE
from homeassistant.core import Context
from homeassistant.exceptions import Unauthorized
from homeassistant.helpers import device_registry as dr
Expand Down Expand Up @@ -59,3 +60,17 @@ async def test_device_registry(hass, config_entry, config, soco):
assert reg_device.manufacturer == "Sonos"
assert reg_device.suggested_area == "Zone A"
assert reg_device.name == "Zone A"


async def test_entity_basic(hass, config_entry, discover):
"""Test basic state and attributes."""
await setup_platform(hass, config_entry, {})

state = hass.states.get("media_player.zone_a")
assert state.state == STATE_IDLE
attributes = state.attributes
assert attributes["friendly_name"] == "Zone A"
assert attributes["is_volume_muted"] is False
assert attributes["night_sound"] is True
assert attributes["speech_enhance"] is True
assert attributes["volume_level"] == 0.19

0 comments on commit 6dc1414

Please sign in to comment.