Skip to content

Commit

Permalink
Merge pull request #11 from maddox/sonos-improvements
Browse files Browse the repository at this point in the history
Sonos Improvements
  • Loading branch information
maddox authored Apr 18, 2018
2 parents fc8f4bf + 92dbc2c commit 0324205
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog
All notable changes to this project will be documented in this file.

## [1.1.1] - 2018-04-18
### Improved
- Sonos queue is cleared before queuing music.

### Fixed
- `repeat` and `shuffle` settings for Sonos Actions actually work now.

## [1.1.0] - 2018-04-17
### Added
- `room` parameter to general config. [Documentation](/docs/install.md#room).
Expand Down
6 changes: 3 additions & 3 deletions config/actions.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
"room": "Living Room",
"playlist": {
"shuffle": "on",
"repeat": "all"
"repeat": "on"
},
"album": {
"shuffle": "off",
"repeat": "all"
"repeat": "off"
},
"song": {
"shuffle": "off",
"repeat": "all"
"repeat": "on"
}
},
"Home Assistant": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "magic-cards",
"version": "1.1.0",
"version": "1.1.1",
"author": "Jon Maddox <jon@jonmaddox.com>",
"license": "MIT",
"bugs": {
Expand Down
35 changes: 25 additions & 10 deletions scanner/actions/SonosAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,34 @@ class SonosAction extends Action {
process() {
const contentConfig = this.config[this.card.type] || {}

const setRepeat = () => {
if (contentConfig.repeat) {
this.repeat(contentConfig.repeat)
}
const request = async () => {
await this.setRepeat(contentConfig.repeat)
await this.clearQueue()
await this.setShuffle(contentConfig.shuffle)

setTimeout(() => {
this.request(this.card.uri)
}, 200)
}

if (contentConfig.shuffle) {
this.shuffle(contentConfig.shuffle)
.then(this.queueAndPlay())
.then(setRepeat())
} else {
this.queueAndPlay().then(setRepeat())
request()
}

async setShuffle(mode) {
if (!mode) {
return
}

return this.shuffle(mode)
}

async setRepeat(mode) {
if (!mode) {
return
}

return this.repeat(mode)
}
async queueAndPlay() {
// this.clearQueue()
// .then(this.request(this.card.uri))
Expand Down Expand Up @@ -48,6 +61,8 @@ class SonosAction extends Action {
const room = encodeURIComponent(this.config.room)
const baseURL = `http://${this.config.host}:${this.config.port}/${room}/${path}`

console.log(`Calling: ${baseURL}`)

let headers = {}
if (this.config.username && this.config.password) {
headers['Authorization'] =
Expand Down

0 comments on commit 0324205

Please sign in to comment.