1

The Nest Firebase implementation appears to work differently than the demo Firebase database. In particular, using the JVM-client my completion listener is never called. I found some sample code for this where the functionality works properly:

public class Demo {
    static Firebase ref;

    public static void main(String[] args) throws Exception {
        ref = new Firebase("https://testjava.firebaseio-demo.com/");
        ref.addValueEventListener(new Listener());

        ref.setValue(new Date().toString(), new Firebase.CompletionListener() {
            @Override
            public void onComplete(FirebaseError firebaseError, Firebase firebase) {
                System.out.println(System.currentTimeMillis() + " Done");
            }
        });

        Thread.sleep(5000);
    }

    static class Listener implements ValueEventListener {
        @Override
        public void onCancelled(FirebaseError e) {}

        @Override
        public void onDataChange(DataSnapshot ds) {
            System.out.println("*** Data change: " + ds.getValue());
        }
    }
}

Similar code that works against the Nest API does not work.

public class Demo2 {
    static String path = "/devices/thermostats/zSTIETF037xWx7gRrVeQ2tsHz2-KbKez/name";

    static Firebase ref;

    public static void main(String[] args) throws Exception {
        ref = new Firebase("wss://developer-api.nest.com");
        ref.authWithCustomToken(authCode, null);
        ref.addValueEventListener(new Listener());

        ref.child(path).setValue("Hallway 3", new Firebase.CompletionListener() {
            @Override
            public void onComplete(FirebaseError firebaseError, Firebase firebase) {
                System.out.println("onComplete");
            }
        });

        Thread.sleep(5000);
    }

    static class Listener implements ValueEventListener {
        @Override
        public void onCancelled(FirebaseError e) {}

        @Override
        public void onDataChange(DataSnapshot ds) {
            System.out.println("*** Data change: " + ds.getValue());
        }
    }
}

No matter how long the sleep is, the "onComplete" is never written. Furthermore, when the path is inspected the value has not been changed. Why doesn't this work?

Note that when the code to add the listener is commented out, it does work.

mlohbihler
  • 717
  • 1
  • 7
  • 15

0 Answers0