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

Documnetation: snapshot FAQ and examples #493

Merged
merged 2 commits into from Apr 19, 2017
Merged

Conversation

DPH
Copy link
Member

@DPH DPH commented Apr 5, 2017

A documentation pull request as discussed - an area with frequent question.
Please check I have changed the faq.rst correctly - not used that before.
Added 2 examples of using snapshot - tested on python 2.7 and 3.5 - feel free to recommend changes.
Cheers David

@coveralls
Copy link

coveralls commented Apr 5, 2017

Coverage Status

Coverage increased (+0.4%) to 60.761% when pulling 1ae9fe1 on DPH:snap_doc into 5ceb384 on SoCo:master.

Copy link
Member

@KennethNielsen KennethNielsen left a comment

Choose a reason for hiding this comment

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

Great addition to the docs. I have only a few minor comments and requests for changes. Let me know if you need any help.

doc/faq.rst Outdated

SoCo provides a snapshot module that captures the current state of a player and
then when requested re-instates that state. Examples of it's use are:
- `basic snap example <https://github.com/SoCo/SoCo/blob/master/examples/snapshot/basic_snap.py>`_
Copy link
Member

Choose a reason for hiding this comment

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

I think the content looks good.

There is a minor syntax error. You should make a blank line after the colon and don't indent the list and I think use * as lists, so it becomes:

SoCo provides a snapshot module that captures the current state of a player and
then when requested re-instates that state. Examples of it's use are:

* `basic snap example  <https://github.com/SoCo/SoCo/blob/master/examples/snapshot/basic_snap.py>`_
* `multi zone example  <https://github.com/SoCo/SoCo/blob/master/examples/snapshot/multi_zone_snap.py>`_

If you have sphinx and napoleon installed you can test the compilation by doing "make html" in the doc directory.

Note: the snap function is designed to be used once, Having taken a snap to
take another re-instantiate the class.
"""

Copy link
Member

Choose a reason for hiding this comment

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

A comment about py2 and 3 compatible code. I guess this was developed on Py3 as you use print as a function. However, the print() only work like it is supposed to in Py2, if there is only one argument. If doing print("more", "strings") it will print out ("more", "strings"). The proper way to do it is to start the file with: from __future__ import print_function. Then print will actually be a function also in Py2.

While you are at it, you might as well also add from __future__ import print_function, unicode_literals. Then you will not need to preface your strings with u to make sure they are unicode.

from soco.snapshot import Snapshot

# something to play on a Sonos player to start (a radio station)
start_uri = u'x-sonosapi-stream:s2846?sid=254&amp;flags=32'
Copy link
Member

Choose a reason for hiding this comment

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

Here, remove the u after having imported unicode_literals

- play an alert mp3 for a few seconds (a poem!)
- re-instate the sonos player to it's previous state (the radio station)

Note: the snap function is designed to be used once, Having taken a snap to
Copy link
Member

Choose a reason for hiding this comment

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

3 things:

Capital after ":"

Calling if function might confuse since it isn't actually a function, so either change to functionality or say that the "Snapshot instance" is only designed to be used once.

"once, Having", change to full stop or make lowercase. Also the last part if that sentence is maybe a little to compactly formulated. What do you think?

This script does not group or un-group any Sonos players. Group management is
a separate subject. For alerts grouping causes delays, so is avoided here.

Note: the snap function is designed to be used once, Having taken a snap to
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.


def play_alert(alert_uri, alert_volume=20, alert_duration=0, fade_back=False):
"""
Demo function using soco.snapshot accrss multiple Sonos players.
Copy link
Member

Choose a reason for hiding this comment

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

across

"""
Demo function using soco.snapshot accrss multiple Sonos players.

:param alert_uri: file that Sonos can play as an alert
Copy link
Member

Choose a reason for hiding this comment

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

Consider using the Napoleon style for sphinc docstrings, which we are trying to switch to in general. Let me know if you need help.

for zone in zones:
if zone.is_coordinator:
zone.play_uri(uri=alert_uri, title='Sonos Alert')
a_coordinator = zone # remember last coordinator for use next
Copy link
Member

Choose a reason for hiding this comment

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

I can't seem to see this being used.

from soco.snapshot import Snapshot


def play_alert(alert_uri, alert_volume=20, alert_duration=0, fade_back=False):
Copy link
Member

Choose a reason for hiding this comment

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

I'd maybe pass zones in as a parameter. What do you think.

@DPH
Copy link
Member Author

DPH commented Apr 16, 2017

Have updated as suggested. Not sure if I have the Napoleon structure right in the multi_zone_snap.py example. Welcome any further comments

Cheers Daivd

@coveralls
Copy link

coveralls commented Apr 16, 2017

Coverage Status

Coverage increased (+0.4%) to 60.761% when pulling 37373b9 on DPH:snap_doc into 5ceb384 on SoCo:master.

@KennethNielsen
Copy link
Member

Looks good. There are still a lot of pylint warnings, but they seem to be caused by a new version of pylint, which included new checks. I'll see about fixing those tonight.

@KennethNielsen KennethNielsen merged commit 36fbf4c into SoCo:master Apr 19, 2017
@KennethNielsen
Copy link
Member

Merged. Can you add a comment about the changes to the release notes #440?

@DPH DPH mentioned this pull request Apr 19, 2017
@stefankoegl stefankoegl added this to the 0.13 milestone Nov 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants