Search code examples
firebaseqnest-api

When I connect to firebase, I only see the structures and no devices (Nest API)


I am trying to read basic information about thermostats using the methods in the thermostat control example (https://developer.nest.com/documentation/control), but when I connect to firebase I only see the structure object (which only contains name, away, smoke_co_alarms, structure_id and thermostats) in the snapshot– There is no devices object. I am connecting to firebase using

    var nestToken = $.cookie('nest_token');
    var dataRef = new Firebase('wss://developer-api.nest.com/');
    dataRef.auth(nestToken);

I tried to connect directly to devices using wss://developer-api.nest.com/devices, but that only returns an undefined data-structure.

I've also tried connecting to firebase using https://developer-api.nest.com/ and https://developer-api.nest.com/, but they raised an authorization error and caused my javascript to go into an infinite loop sending requests.

I'm reading data using:

dataRef.on('value', function (snapshot) {
    var data = snapshot.val();
    structure = firstChild(data.structures);
    console.log(data);
    console.log(data.structures);
    console.log(data.devices);
    console.log(data.devices.thermostats);
    console.log(structure.thermostats);
};

Lastly, I tried it on an account with real devices and one with virtual devices, so I know that couldn't be causing it (even though I didn't expect it to).

Any ideas what I am doing wrong? The issue couldn't be in my App.js file, could it? Is there some configuration I need to do on the user's end in addition to the authentication? I get the feeling it's probably something really simple that's staring me in the face.


Solution

  • So I figured it out: It's a permissions issue. When my client-profile was setup, it only requested permission to read the away/home status. So when I query Firebase it only returns the a snapshot with structure because that is where the away/home status can be read. So, in summary, if you're not seeing the devices structure, even though devices are associated with the user, check your client permissions.