Skip to content

Commit

Permalink
Pivot 'sonos.py' to use 'api.run_command()'
Browse files Browse the repository at this point in the history
This also allows multiple sequential actions to proceed in the
event of a failed action
  • Loading branch information
pwt committed Feb 5, 2021
1 parent c9499f8 commit 0184bb3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
v0.3.22 -
v0.3.22 - Multiple sequential actions will attempt to proceed in the event of
an action in the sequence failing
v0.3.21 - Bugfixes
v0.3.20 - Add the ability to save, load, and overwrite shell aliases from
text files
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ Multiple commands can be run as part of the same `sonos` invocation by using the

The benefit of using this approach instead of multiple separate `sonos` commands is that cost of starting the program is only incurred once.

An arbitrary number of commands can be supplied as part of a single `sonos` invocation. If a failure is encountered with any command, `sonos` will terminate and will not execute the remaining commands.
An arbitrary number of commands can be supplied as part of a single `sonos` invocation. If a failure is encountered with any command, `sonos` will report the error, and will generally attempt to execute subsequent commands.

**Example:** `sonos Kitchen volume 25 : Kitchen play`

Expand Down
42 changes: 19 additions & 23 deletions soco_cli/sonos.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

import soco

from soco_cli.action_processor import list_actions, process_action
from soco_cli.action_processor import list_actions
from soco_cli.aliases import AliasManager
from soco_cli.api import run_command
from soco_cli.cmd_parser import CLIParser
from soco_cli.interactive import interactive_loop
from soco_cli.speakers import Speakers
Expand Down Expand Up @@ -390,32 +391,27 @@ def main():
)
)
print(speaker.player_name)
if not process_action(
speaker, action, args, use_local_speaker_list
):
if ":" in action:
error_and_exit(
"Action '{}' not found ... spaces missing around ':'?".format(
action
)
)
else:
error_and_exit("Action '{}' not found".format(action))
exit_code, output_msg, error_msg = run_command(
speaker,
action,
*args,
use_local_speaker_list=use_local_speaker_list,
)
if exit_code == 0:
print(output_msg)
else:
print(error_msg)
else:
speaker = get_speaker(speaker_name, use_local_speaker_list)
if not speaker:
error_and_exit("Speaker '{}' not found".format(speaker_name))
if not process_action(
speaker, action, args, use_local_speaker_list=use_local_speaker_list
):
if ":" in action:
error_and_exit(
"Action '{}' not found ... spaces missing around ':'?".format(
action
)
)
else:
error_and_exit("Action '{}' not found".format(action))
exit_code, output_msg, error_msg = run_command(
speaker, action, *args, use_local_speaker_list=use_local_speaker_list
)
if exit_code == 0:
print(output_msg)
else:
print(error_msg)

except Exception as e:
error_and_exit(str(e))
Expand Down

0 comments on commit 0184bb3

Please sign in to comment.