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

networkContext.getAllLightsCollection().getLights() returns 0 #12

Open
Eonasdan opened this issue May 16, 2014 · 4 comments
Open

networkContext.getAllLightsCollection().getLights() returns 0 #12

Eonasdan opened this issue May 16, 2014 · 4 comments

Comments

@Eonasdan
Copy link

If use the sample code and do this:

 networkContext  = LFXClient.getSharedInstance(getApplicationContext()).getLocalNetworkContext();
        networkContext.connect();
        bulbList = networkContext.getAllLightsCollection().getLights();
        Log.i(TAG, "Lights: " + bulbList.size());

bublList is 0 where I expected it to be 1

If I use the SampleSDK I can see the bulb in the LFXSDKLightListAdapter and turn it on and off.

If I turn it on using the SampleSDK or the official app, my app returns 1.

Am I doing something incorrectly?

Edit: I just noticed something else. If I close the app, and restart it sometimes it returns a bulb, however if I redeploy the app it returns 0.

Sometimes when I open after sometime, it does return 1.

How long does it take to get the list and how do I know when it gets a response?

@Eonasdan Eonasdan changed the title networkContext.getAllLightsCollection().getLights() returns 0 if lights are off networkContext.getAllLightsCollection().getLights() returns 0 May 17, 2014
@Cakey123445
Copy link
Contributor

You should really add a listener to the getAllLightsCollection() otherwise you are just relying on getting lucky and a bulb being found in between when you connect and when you call get all lights.

You then don't need to worry about timings and such. Some snippets from my controller fragment below:

public class FragmentLIFXController extends Fragment implements LFXLightCollectionListener {

@Override
public void onStart() {
  super.onStart();
  Log.d(TAG,"onStart()");

  if(mLIFXContext==null) {
    mLIFXContext=LFXClient.getSharedInstance(getActivity()).getLocalNetworkContext();
    mLIFXContext.connect();

    LFXLightCollection lc=mLIFXContext.getAllLightsCollection();
    lc.addLightCollectionListener(this);
  }
}

@Override
public void lightCollectionDidAddLight(LFXLightCollection arg0,LFXLight arg1) {
    Log.d(TAG,"lightCollectionDidAddLight() - "+arg1.getLabel()+" - "+arg1.getDeviceID());
}

@Override
public void lightCollectionDidChangeColor(LFXLightCollection arg0,LFXHSBKColor arg1) {
    Log.d(TAG,"lightCollectionDidChangeColor()");       
}

@Override
public void lightCollectionDidChangeFuzzyPowerState(LFXLightCollection arg0, LFXFuzzyPowerState arg1) {
   Log.d(TAG,"lightCollectionDidFuzzyPowerState()");        
}

@Override
public void lightCollectionDidChangeLabel(LFXLightCollection arg0, String arg1) {
    Log.d(TAG,"lightCollectionDidChangeLabel()");
}

@Override
public void lightCollectionDidRemoveLight(LFXLightCollection arg0, LFXLight arg1) {
    Log.d(TAG,"lightCollectionDidRemoveLight()");
}
}

@Eonasdan
Copy link
Author

the log events don't change for me.

I don't get the networkContextDidConnect events either.

@Cakey123445
Copy link
Contributor

If you are going to pick up the nextworkContextDidConnect then that's a different listener, you'll need to add "implements LFXNetworkContextListener" and whilst many things are broken in the libs then the nextworkContextDidConnect/Disconnect() is working here.

According to Jarrod there is a lib update coming soon.

@PercyBoyes
Copy link
Contributor

Thanks for replying here Cakey,

I'm working on an update for the API asap to fix some of the issues you guys are seeing.

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

No branches or pull requests

3 participants