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

New endpoint to show if any speaker is running #781

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

zperee
Copy link

@zperee zperee commented Nov 17, 2020

To be able to show if any speaker is running (e.g in Apple Home Kit as a Switch) created a new endpoint which returns true if any speaker has the playBackState === "PLAYING" otherwise return false.

With the new endpoint it is possible together with homebride and the hombridge-http-switch plugin to stop all speakers from Apple Home Kit. The new endpoint is needed to display the state of the button. So if a speaker is running turn switch on otherwise turn switch off.

{
     "accessory": "HTTP-SWITCH",
     "name": "Sonos",
     "switchType": "stateful",
     "timeout": 3000,
     "offUrl": "http://localhost:5005/pauseall",
     "onUrl": "http://localhost:5005/resumeall",
     "statusUrl": "http://localhost:5005/anyplayeron",
     "statusPattern": "{\"anyOn\":true}"
}

@jsiegenthaler
Copy link
Contributor

jsiegenthaler commented Nov 17, 2020

Excellent, this is exactly what I wanted t do.

I'd also like to have an endpoint that lets me control the speaker LED. It's in the Sonos api but I have not yet found where it could be added in the Sonos-http-api

That would give me a quick visual indication as to the state of the speaker as I'd like to mute it overnight

Copy link
Owner

@jishi jishi left a comment

Choose a reason for hiding this comment

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

I can't really comprehend what this code does, it should be as simple as just running the some() aggregation.

doStateOn(player.system);
}, values[0] * 1000 * 60);
return Promise.resolve();
}
Copy link
Owner

Choose a reason for hiding this comment

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

What's the purpose of this setTimeout?


function doAnyPlayerOn(system) {
const promises = system.zones.some(zone => zone.coordinator.state.playbackState === 'PLAYING');
return {promises};
Copy link
Owner

Choose a reason for hiding this comment

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

Nothing here is a promise, so not sure why you return an object with { promises: bool }


module.exports = function (api) {
api.registerAction('pauseall', pauseAll);
api.registerAction('resumeall', resumeAll);
}
api.registerAction('anyplayeron', anyPlayerOn);
Copy link
Owner

Choose a reason for hiding this comment

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

This should probably be in it's own action file, since it doesn't really have anything to do with play/pause all functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants