Skip to content

Sonos idle#32712

Merged
balloob merged 4 commits intodevfrom
sonos-clean-attributes
Mar 12, 2020
Merged

Sonos idle#32712
balloob merged 4 commits intodevfrom
sonos-clean-attributes

Conversation

@balloob
Copy link
Copy Markdown
Member

@balloob balloob commented Mar 12, 2020

Breaking change

Sonos devices will now report idle instead of paused if they do not have any current artist metadata available. This can happen when you were playing Spotify on your Sonos and use the Spotify app to play on another device.

Proposed change

If there are no music title/artist, don't store an empty string but store None so the attributes are filtered out.

Also make sure that if there is no media title, we don't consider ourselves paused but instead mark ourselves as idle, which is more appropriate.

For background, see #32701

Fixes #32701

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

Comment thread homeassistant/components/sonos/media_player.py Outdated
@amelchio
Copy link
Copy Markdown
Contributor

I guess this is a breaking change if automations rely on the state.

@balloob balloob added this to the 0.107.0 milestone Mar 12, 2020
@balloob
Copy link
Copy Markdown
Member Author

balloob commented Mar 12, 2020

Tagged this for 107 because it fixes Sonos with the new media control card.

Copy link
Copy Markdown
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Comments are indeed on existing code, highlighted now because of the indent change.

I think right now, having a bug fixed/improved user experience is more important.

Copy link
Copy Markdown
Contributor

@amelchio amelchio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had some time to read the patch now. I am still not strongly opinionated but to me, this looks a bit like a fix in the wrong place.

self._media_image_url = self._radio_artwork(media_info["CurrentURI"])

self._media_artist = track_info.get("artist")
self._media_artist = track_info.get("artist") or None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be better to add these or None to the property getters for less duplication. We already do that for media_image_url.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this change made the PR miss its target because the state property reads from self._media_title which is no longer set to None.

I have included a proposal to fix that in #34311 (by using self.media_title).

def state(self):
"""Return the state of the entity."""
if self._status in ("PAUSED_PLAYBACK", "STOPPED"):
if self._media_title is not None and self._status in (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure that it can fail but honestly, this makes me feel odd. It seems to conflate concerns. Maybe we paused some untagged media? Even if that cannot happen with Sonos (I am unsure), it seems like a situation the frontend should be able to handle?

Copy link
Copy Markdown
Member Author

@balloob balloob Mar 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I consider it a bug in Home Assistant if a media player is claiming to have media loaded (being in a paused/playing state) and it cannot describe that media and it normally can.

Especially since Sonos does have the transitioning state to indicate that it's between songs, which we will still consider being playing.

Even if you play MP3s there is a title (the filename)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, in that case we have a bug in update_media_linein() :)

Maybe it would look less out of place as a guard.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, with MP3 I meant one from a local server. You're right linein is different. Do we know the transport info if it's linein / TV ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a guard, do you mean that you want to see the if be inside the other if ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line-in currently has

        self._media_artist = source

that we can just change to

        self._media_title = source

and it is hard-coded as "TV" or "Line-in".

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant

    if self._media_title is None:
        return STATE_IDLE

but don't change it just for me, I'm fine with whatever :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done and done!

@balloob balloob merged commit 1fe26c7 into dev Mar 12, 2020
@balloob balloob deleted the sonos-clean-attributes branch March 12, 2020 21:48
balloob added a commit that referenced this pull request Mar 13, 2020
* Sonos idle

* F-string

* Add to properties

* Fixes
@lock lock Bot locked and limited conversation to collaborators Mar 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sonos: idle player showing as paused

6 participants