GithubHelp home page GithubHelp logo

jeelight's Introduction

Jeelight

Build Status

Jeelight is a simple implementation of Yeelight Inter operation specification. The aim of jeelight is to manage for you the discovery and communication with differents Yeelight devices.

Requirement

To use the Lib, you need to have oppened the developer mode in your bulb.

To do this, open your Yeelight mobile application,

  • Click in the button that look like an Up Arrow
  • Check that the button Control on local network is checked

Dependencies

The Jeelight only depends on log4j2 library.

Discovering devices

The device discovery is based on SSDP protocol. Jeelight provide a simple implementation.

List<Light> devices = new ArrayList<>();
SSDPClient client = new SSDPClient(5000,'wifi_bulb',1982);
client.addListener(new PropertyChangeListener() {
	@Override
	public void propertyChange(PropertyChangeEvent evt) {
		if (SSDPClient.ADD.equals(evt.getPropertyName())) {
			Light l = (Light) evt.getNewValue();
			devices.add(l);					
		}
	}
});
client.startDiscovering();

With this simple code, you start discovering new devices on network and add it in a list.

Communication

Jeelight offers two way to communicate with Yeelight devices. An expert way, where you control each data asynchronously and an easy way where you call methods in a synchronnous way.

The expert way

For the expert way, you need to get a MessageManager.

Then you interact in this way:

Light light = ...
MessageManager manager = MessageManager.getInstance(l);
Future<Boolean> future = manager.send(Method.method, param1, param2,...);
while(!future.isDone()){// Wait}
// Command was executed, can get the result
if(future.get()){
	// Command correctly executed
} else {
	// Command not executed
}

// Or in this way
future = manager.send(Method.method, new Object[]{param1, param2,...});
while(!future.isDone()){// Wait}
// Command was executed, can get the result
if(future.get()){
	// Command correctly executed
} else {
	// Command not executed
}

When an operation modify a parameter of the light, the object is modified when the light send a notification, no need to directly modify object.

The simple way

With the simple way, no need to manage asynchronously your data, everithing is encapsulate in the EasyLight object.

EasyLight eLight = new EasyLight(light);
//Call the method
eLight.toggle();

I most of the cases, the method call return the new value of the modified attribute.

When an operation modify a parameter of the light, the object is modified when the light send a notification, no need to directly modify object.

Listen to light modification

Because Lights are in network, they can be modified by someone else, so you need to listen your lights to be updated with its real state.

Light light = ...;

light.addListener(new PropertyChangeListener() {
	@Override
	public void propertyChange(PropertyChangeEvent evt) {
		if (null != evt) {
			// manage the event.
			// the property name is the modified property annotated in the Light object
			// the old value is the old value (obviously)
			// the new value is the new value
		}
	}
});

Don't forger to remove the listener.

TODO

Actually I need to manage music and scenes methods.

Conclusion

Try it yourself and enjoy

jeelight's People

Contributors

y0annd avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.