Git Product home page Git Product logo

Comments (12)

DanielBlik avatar DanielBlik commented on July 24, 2024 1

@ZeroOne3010 Thank you so much for your patience and help. I managed to figure it out

from yetanotherhueapi.

ZeroOne3010 avatar ZeroOne3010 commented on July 24, 2024

The easiest way to do that is to use a build tool like Apache Maven and to add the library as a dependency into the pom.xml file. Your IDE probably offers a New Project command where you can choose to use Maven. Then just take the dependency definition from the README.md of this project and add it there. If you are not using an IDE then you can also use Maven with the command line by following, say, this tutorial: https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

from yetanotherhueapi.

ZeroOne3010 avatar ZeroOne3010 commented on July 24, 2024

@MrBlik123 Did you get this thing sorted out? For what it's worth, I've got another project called hue2influx where I'm using this library as a dependency. You can see the relevant pom.xml here: https://github.com/ZeroOne3010/hue2influx/blob/master/pom.xml

from yetanotherhueapi.

DanielBlik avatar DanielBlik commented on July 24, 2024

@ZeroOne3010 I managed to figure out how to get the maven project in my package explorer but I just can't seem to figure out how I would inherit / import this library into a different java project. I follow each step of tutorials but I can't seem to figure it out probably because I'm using the wrong search terms idk. But I really appreciate you taking the time to help me :)

from yetanotherhueapi.

zone4182 avatar zone4182 commented on July 24, 2024

Hi,

I really like the package so far, its very easy to use. However I'm struggling with one thing. So i can easily set the status of all light in a room like your example shows: (doing this with a restcontroller)

`@GetMapping(value = "/set-room-light-status")
public ResponseEntity setRoomLightColors(@RequestParam(value = "bridge") String bridge, @RequestParam(value = "room") String room,
@RequestParam(value = "status") Boolean on, @RequestParam(value = "color") String color) {
//get bridge info from repo
HueBridge hBridge = hueService.getByName(bridge);

	final Hue oHue = new Hue(hBridge.getIpaddress(), hBridge.getApikey());
	final Room oRoom = oHue.getRoomByName(room).get();
	
	Color c;
	try {			
		pattern = Pattern.compile(HEX_PATTERN);
		matcher = pattern.matcher(color);
		
		if(matcher.matches()){
			c = Color.decode(color);
		}else{
			c = (Color)Color.class.getField(color).get(null);
		}
		oRoom.setState(State.builder().color(c).on(on));
		
	} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		
		return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
	}		
	
	return new ResponseEntity(HttpStatus.OK);
}`

But I'm trying to figure out how to do this for an individual light. I thought it would be something like this:

`@GetMapping(value = "/set-lights-color")
public ResponseEntity setLightColor(@RequestParam(value = "bridge") String bridge, @RequestParam(value = "lights") String lights, @RequestParam(value = "color") String color) {
//get bridge info from repo
HueBridge hBridge = hueService.getByName(bridge);
final Hue oHue = new Hue(hBridge.getIpaddress(), hBridge.getApikey());
List hLights = Arrays.asList(lights.split(","));

	Color c;
	try {
		pattern = Pattern.compile(HEX_PATTERN);
		matcher = pattern.matcher(color);
		
		if(matcher.matches()){
			c = Color.decode(color);
		}else{
			c = (Color)Color.class.getField(color).get(null);
		}
		
		oHue.getRaw().getLights().forEach((k,v)->{
			if(hLights.contains(v.getName())){
				v.getState().setOn(false);
			}
		});
	} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}		
	
	return new ResponseEntity(HttpStatus.OK);
}`

But it doesnt seem to work. Also I wouldnt know how to actually change the color for instance. Is it even possible like this? Or maybe I'm not understanding the purpose of it ;-)

from yetanotherhueapi.

DanielBlik avatar DanielBlik commented on July 24, 2024

@zone4182 in order to change the color you can only do it per room i believe to set the color of a room use
room.setState(State.builder().color(java.awt.Color.RED).on());

from yetanotherhueapi.

ZeroOne3010 avatar ZeroOne3010 commented on July 24, 2024

@zone4182 Hello there! I'm sorry about the poor documentation, I should improve it. You most definitely can change the colors of individual lights, I'd say just as easily as you can do that for rooms. First, forget about the getRaw() method. You can only read data using it, you cannot change anything. The individual lights are accessed through their Room objects. In your first example you have this line:

oRoom.setState(State.builder().color(c).on(on));

To have it set the color of an individual light named Foo, you'd do it like this:

oRoom.getLightByName("Foo").ifPresent(light -> light.setState(State.builder().color(c).on(on)));

from yetanotherhueapi.

ZeroOne3010 avatar ZeroOne3010 commented on July 24, 2024

@ZeroOne3010 I managed to figure out how to get the maven project in my package explorer but I just can't seem to figure out how I would inherit / import this library into a different java project. I follow each step of tutorials but I can't seem to figure it out probably because I'm using the wrong search terms idk. But I really appreciate you taking the time to help me :)

@MrBlik123 Can you create a repository for your project and push it to GitHub? I might be able to see why it's not working.

from yetanotherhueapi.

DanielBlik avatar DanielBlik commented on July 24, 2024

@ZeroOne3010 i managed to figure out how one inherits stuff but i just cant figure out how i find my group id for a dependencie thank you for your patience in helping me btw

from yetanotherhueapi.

ZeroOne3010 avatar ZeroOne3010 commented on July 24, 2024

For what it's worth, I've now updated the README.md file to define the required import statement and to give an example on how to change the color of an individual light.

from yetanotherhueapi.

ZeroOne3010 avatar ZeroOne3010 commented on July 24, 2024

@ZeroOne3010 i managed to figure out how one inherits stuff but i just cant figure out how i find my group id for a dependencie thank you for your patience in helping me btw

@MrBlik123 The group id for your own project is basically something that you can just make up. It's usually a domain name that you control, but in reverse. In case you don't own a domain name, you can also use something like io.github.mrblik123, or, simply, mrblik123. Do read this short guide on the naming conventions: https://maven.apache.org/guides/mini/guide-naming-conventions.html

from yetanotherhueapi.

ZeroOne3010 avatar ZeroOne3010 commented on July 24, 2024

In 45bfd42 I have now also added Javadocs that should explain where @zone4182 went wrong and what he should try instead.

from yetanotherhueapi.

Related Issues (20)

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.