NEEOInc / neeo-sdk

NEEO Brain SDK
https://neeoinc.github.io/neeo-sdk/
MIT License
49 stars 17 forks source link

getRecipes does not expose roomkey #124

Closed gvdhoven closed 6 years ago

gvdhoven commented 6 years ago

if you call getRecipes you get all sorts of data back, but not the roomkey. Currently i am working my way around this by this NodeJS code; but it's ugly

var roomKey = recipe.url.getPowerState.split('/')[7];
var recipeKey = recipe.url.getPowerState.split('/')[9];

Can the roomKey & recipeKey (including all other info you might need for calling rest API's on the brain itself) be added in the 'discovery' of the recipes?

MichaelKohler commented 6 years ago

What use case are you covering? Instead of just giving more data, it might make more sense for us to add the desired actions to the returned recipes. Depends on the use case though :)

gvdhoven commented 6 years ago

I am creating my own Alexa skill, and in order to turn on or turn off a recipe (via the /execute API) i need to have the roomkey as well. Would that be enough info @MichaelKohler ?

Related: https://planet.neeo.com/t/q5rz0k/the-neeo-brain-is-a-stupid-device-pun-intended

MichaelKohler commented 6 years ago

As far as I can see right now there is recipe.action.powerOn() and recipe.action.powerOff(). I didn't test this right now though.

However, you'd be right that both URLs are the same and integrating that check into those two functions would IMHO make sense.

tmrobert8 commented 6 years ago

Relook at the thread - I posted the API you should be using. That will give you the direct URL (no need to substitute anything or get other keys) for power on/power off of recipes

gvdhoven commented 6 years ago

@tmrobert8 that doesn't help, i am already using this :) point is that there is no distinct 'poweron' and 'poweroff' command.

In addition, the recipe's execute command does not show the animation on the remote (meaning a delay before you see anything happen on the UI, depending on the smart delays)

nklerk commented 6 years ago

some API calls that you might want to use.

Get All recipies per device http://${neeoBrain.host}:3000/v1/api/Recipes

please note that a power on and power off are actually two seperate recipes, you can get them with this API call. Example responce:

{ "type": "launch", "detail": { "devicename": "TV", "roomname": "Testing123", "model": "19LE3400-ZA", "manufacturer": "LG", "devicetype": "TV" }, "url": { "identify": "http://10.2.1.64:3000/v1/systeminfo/identbrain", "setPowerOn": "http://10.2.1.64:3000/v1/projects/home/rooms/6367632568841404416/recipes/6399543812867227648/execute", "setPowerOff": "http://10.2.1.64:3000/v1/projects/home/rooms/6367632568841404416/recipes/6399543812896587776/execute", "getPowerState": "http://10.2.1.64:3000/v1/projects/home/rooms/6367632568841404416/recipes/6399543812867227648/isactive" }, "isCustom": false, "isPoweredOn": false, "uid": "6399543775173017600", "powerKey": "6399543812808507392" }

Is recipe active: http://${brainHostname}:3000/v1/projects/home/rooms/${roomKey}/recipes/${recipeKey}/isactive

Execure recipe: http://${brainHostname}:3000/v1/projects/home/rooms/${roomKey}/recipes/${recipeKey}/execute

gvdhoven commented 6 years ago

@nklerk you guys are missing the point :) i have this exact JSON already examined, i know how to use the URLs, i am trying to point out that there is no way to turn on or turn off a recipe with a DEDICATED URL. Both turn on and turn off have thesame URL :)

nklerk commented 6 years ago

Both turn on and turn off have the same URL :) its not obvious and i personally would have done it differently but no. they don't have the same URL. :-D they do share the same structure as you execure the recipe. Confusingly a recipe in the NEEO UI for a device are actually two seperate recipies. one for power on and one for power off with both having seperate recipekeys.

In my example youll fine the power on and power off URL's:

"http://10.2.1.64:3000/v1/projects/home/rooms/6367632568841404416/recipes/6399543812867227648/execute",
"http://10.2.1.64:3000/v1/projects/home/rooms/6367632568841404416/recipes/6399543812896587776/execute",

the power on recipe has key 6399543812867227648. the power off recipe has key 6399543812896587776.

does this help?

tmrobert8 commented 6 years ago

I'm confused as to what you are asking - as both @nklerk and I have mentioned, the URLs from the api/recipe give you distinct URLs for power on/power off. Maybe we are both misunderstanding what you are asking - you're not asking for a toggle URL are you? I strongly would be against that if you are..

gvdhoven commented 6 years ago

wow... i am totally sorry @nklerk and @tmrobert8 , i have completely missed that!

Question remains:

MichaelKohler commented 6 years ago

Happy you figured it out. Thanks Niels and Tim for the help! Seems like I was confused in my first comment 😅

gvdhoven commented 6 years ago

@MichaelKohler maybe you can clarify this; what is the difference between UID and PowerKey? If i need something unique across the brain i am currently querying, i am assuming i can re-use the UID field?

tmrobert8 commented 6 years ago

The 'powerkey' is really just the related scenario key. Not sure why they called it powerkey here - but it is what it is...

EDIT: UID is the related device key.

nklerk commented 6 years ago

Yeah, its confusing. ;-)

UID = the key pointing to the deviceKey powerKey = the key pointing to the scenarioKey

Get http://${brainIp}:3000/projects/home/ this shows most of the data in one view.

I use notepad++ with the JSON viewer plugin to format the JSON. Then just search these ID's there and you'll find where they point to.

nklerk commented 6 years ago

Sorry fore the duplicate answer:/

nklerk commented 6 years ago

What i use to make a unique id is this:

function newUid() {
    const d = new Date();
    return date.getTime();
}

responce: 1533306389584

tmrobert8 commented 6 years ago

lol - exactly what I do as well (notepad++ with json viewer plugin!).