Skip to content

Check if media commands are actually applicable#7595

Merged
balloob merged 3 commits into
home-assistant:devfrom
bjw-s:sonos
Jun 2, 2017
Merged

Check if media commands are actually applicable#7595
balloob merged 3 commits into
home-assistant:devfrom
bjw-s:sonos

Conversation

@bjw-s
Copy link
Copy Markdown
Contributor

@bjw-s bjw-s commented May 14, 2017

Description:

  • Explicitly allow stop and play on radio streams
  • Disallow media commands when the playlist is empty (doesn't make any sense to play, stop or pause an empty playlist)
  • Check if command is supported when calling turn_on and turn_off

Implementing these checks prevents the UPnP Error 701 (Transition not available)

Related issue (if applicable): fixes #4816

Checklist:

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

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass

@mention-bot
Copy link
Copy Markdown

@Juggels, thanks for your PR! By analyzing the history of the files in this pull request, we identified @pvizeli, @rhooper and @bjarniivarsson to be potential reviewers.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am kind of reluctant to include business logic. What does Sonos do when you call play and there is no playlist size?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Understandable, as I felt the same way at first.

The Sonos controller just says "No music", and the play/pause button does nothing on the surface. From a UPnP standpoint, it's valid for the SoCo package to throw the 701 error as playing or pausing, etc. on an empty playlist is an invalid state transition (because there is nothing to play or pause). So the options were to try/catch the 701 error everywhere, or control the play/pause support based on playlist size.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we start catching 701 errors we wouldn't have to implement any business logic and just make sure we don't log them. That sounds more maintainable. Is there any added value from going down the business logic route?

Copy link
Copy Markdown
Contributor Author

@bjw-s bjw-s May 15, 2017

Choose a reason for hiding this comment

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

There is not necessarily any added value I think. I figured this would be a bit more clean, as this way the logic for when play/pause/etc is supported is explicit. Also I wasn't sure where I would best implement the catch statements. I guess that would be in the self.media_pause() (etc) functions?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll give it a go :)

btw, just noticed that the macOS Sonos Controller app also disables the play/pause button upon an empty playlist (apparently the iOS app doesn't, that's where I checked earlier)

@bjw-s
Copy link
Copy Markdown
Contributor Author

bjw-s commented May 17, 2017

Processed requested changes in latest commit

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add this to the finally block from try…catch so that it's guaranteed to enable logging after it runs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

you can just return the value once you have added the finally block 👍

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is no reason to support an errorcodes being None

bjw-s added 3 commits May 24, 2017 09:53
- Explicitly allow ‘stop’ and ‘play’ on radio streams
- Disallow media commands when the playlist is empty
- Check if command is supported when calling `turn_on` and `turn_off`
Clean up soco_filter_upnperror and fix small bug in support_previous_track determination
@bjw-s
Copy link
Copy Markdown
Contributor Author

bjw-s commented May 24, 2017

Changes processed 😄

@balloob balloob merged commit 12607ae into home-assistant:dev Jun 2, 2017
@balloob balloob mentioned this pull request Jun 2, 2017
@bjw-s bjw-s deleted the sonos branch June 6, 2017 05:54
@home-assistant home-assistant locked and limited conversation to collaborators Sep 4, 2017
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 issues (UPnP Error 701 received)

5 participants