Skip to content

Commit

Permalink
Added simple Sonos support
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniCodeMonkey committed Aug 27, 2015
1 parent bf7c255 commit b2272a0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 25 deletions.
12 changes: 8 additions & 4 deletions app/Intents/SpeakerIntent.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ protected function stop() {
}
}

protected function play($playlistName) {
protected function play($track) {
$hjemClient = app()->make('HjemClient');
$response = $hjemClient->post('set/speaker/playlist/' . $playlistName);
if ($response->getStatusCode() != 200) {
$response = $hjemClient->post('set/play_track/' . urlencode($track));

if ($response->getStatusCode() == 422) {
$json = json_decode($response->getBody());
return $json->error;
} elseif ($response->getStatusCode() != 200) {
throw new \RuntimeException('Could not communicate with hjem and/or speaker');
}

$json = json_decode($response->getBody());

return $json->value;
return 'Now playing ' . $json->value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@

use RuntimeException;

class SpeakerPlayPlaylistIntent extends SpeakerIntent {
class SpeakerPlayTrackIntent extends SpeakerIntent {

public function handle(Request $request) {
$playlistName = $request->slots['playlist'];
$query = $request->slots['query'];

try {
$playlistName = $this->play($playlistName);
$playResponse = $this->play($query);
} catch (RuntimeException $e) {
return $this->response->respond($e->getMessage());
}

return $this->response
->respond('Now playing ' . $playlistName);
->respond($playResponse);
}

}
1 change: 1 addition & 0 deletions app/Providers/HjemApiServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function register()
$client = new Client([
'base_uri' => env('HJEM_API_BASE_URL') . '/v1/',
'timeout' => 10.0,
'exceptions' => FALSE
]);

return $client;
Expand Down
4 changes: 2 additions & 2 deletions schema/speaker/intents.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"slots": []
},
{
"intent": "SpeakerPlayPlaylistIntent",
"intent": "SpeakerPlayTrackIntent",
"slots": [
{
"name": "playlist",
"name": "query",
"type": "LITERAL"
}
]
Expand Down
30 changes: 15 additions & 15 deletions schema/speaker/utterances.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
SpeakerPlayPlaylistIntent play {new age|playlist} playlist
SpeakerPlayPlaylistIntent play {new age|playlist}
SpeakerPlayPlaylistIntent I want to hear {new age|playlist}
SpeakerPlayPlaylistIntent I want to listen to {new age|playlist}
SpeakerPlayPlaylistIntent play me some {new age|playlist}
SpeakerPlayPlaylistIntent play {harder better faster stronger|playlist} playlist
SpeakerPlayPlaylistIntent play {harder better faster stronger|playlist}
SpeakerPlayPlaylistIntent I want to hear {harder better faster stronger|playlist}
SpeakerPlayPlaylistIntent I want to listen to {harder better faster stronger|playlist}
SpeakerPlayPlaylistIntent play me some {harder better faster stronger|playlist}
SpeakerPlayPlaylistIntent play {jet set groove|playlist} playlist
SpeakerPlayPlaylistIntent play {jet set groove|playlist}
SpeakerPlayPlaylistIntent I want to hear {jet set groove|playlist}
SpeakerPlayPlaylistIntent I want to listen to {jet set groove|playlist}
SpeakerPlayPlaylistIntent play me some {jet set groove|playlist}
SpeakerPlayTrackIntent play {are you gonna be my soul girl|query} playlist
SpeakerPlayTrackIntent play {are you gonna be my soul girl|query}
SpeakerPlayTrackIntent I want to hear {are you gonna be my soul girl|query}
SpeakerPlayTrackIntent I want to listen to {are you gonna be my soul girl|query}
SpeakerPlayTrackIntent play me some {are you gonna be my soul girl|query}
SpeakerPlayTrackIntent play {harder better faster stronger|query} playlist
SpeakerPlayTrackIntent play {harder better faster stronger|query}
SpeakerPlayTrackIntent I want to hear {harder better faster stronger|query}
SpeakerPlayTrackIntent I want to listen to {harder better faster stronger|query}
SpeakerPlayTrackIntent play me some {harder better faster stronger|query}
SpeakerPlayTrackIntent play {maps|query} playlist
SpeakerPlayTrackIntent play {maps|query}
SpeakerPlayTrackIntent I want to hear {maps|query}
SpeakerPlayTrackIntent I want to listen to {maps|query}
SpeakerPlayTrackIntent play me some {maps|query}

SpeakerStopIntent stop
SpeakerStopIntent stop music
Expand Down

0 comments on commit b2272a0

Please sign in to comment.