Skip to content

Commit

Permalink
Fix idle state
Browse files Browse the repository at this point in the history
  • Loading branch information
mj23000 committed Dec 21, 2022
1 parent 4f9da47 commit 671a7ee
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
20 changes: 10 additions & 10 deletions custom_components/bangolufsen/manifest.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"domain": "bangolufsen",
"name": "Bang & Olufsen",
"documentation": "https://github.com/bang-olufsen/bangolufsen-hacs",
"issue_tracker": "https://github.com/bang-olufsen/bangolufsen-hacs/issues",
"requirements": ["mozart-api==2.3.4.15123.6"],
"zeroconf": ["_bangolufsen._tcp.local."],
"version": "0.5.1",
"codeowners": ["@mj23000"],
"iot_class": "local_push",
"config_flow": true
"domain": "bangolufsen",
"name": "Bang & Olufsen",
"documentation": "https://github.com/bang-olufsen/bangolufsen-hacs",
"issue_tracker": "https://github.com/bang-olufsen/bangolufsen-hacs/issues",
"requirements": ["mozart-api==2.3.4.15123.6"],
"zeroconf": ["_bangolufsen._tcp.local."],
"version": "0.5.2",
"codeowners": ["@mj23000"],
"iot_class": "local_push",
"config_flow": true
}
13 changes: 11 additions & 2 deletions custom_components/bangolufsen/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ async def async_added_to_hass(self) -> None:
f"{self._unique_id}_{WebSocketNotification.PLAYBACK_STATE}",
self._update_playback_state,
),
async_dispatcher_connect(
self.hass,
f"{self._unique_id}_{WebSocketNotification.POWER_STATE}",
self._update_power_state,
),
async_dispatcher_connect(
self.hass,
f"{self._unique_id}_{WebSocketNotification.SOURCE_CHANGE}",
Expand Down Expand Up @@ -642,7 +647,11 @@ async def _update_playback_state(self, data: RenderingState) -> None:
"""Update _playback_state and related."""
self._playback_state = data

# Update entity state based on the playback state.
# Update entity state based on the playback and power state.
# The idle state has higher priority than any other playback state
if self._power_state.value == "networkStandby":
return

self._state = self._playback_state.value

self.async_write_ha_state()
Expand All @@ -653,7 +662,7 @@ async def _update_power_state(self, data: RenderingState) -> None:

# Update entity state based on the power state.
if self._power_state.value == "networkStandby":
self._state = cast(MediaPlayerState, StateEnum[self._power_state])
self._state = cast(MediaPlayerState, StateEnum[self._power_state.value])

self.async_write_ha_state()

Expand Down

0 comments on commit 671a7ee

Please sign in to comment.