Comments (12)
@ZeroOne3010 Thank you so much for your patience and help. I managed to figure it out
from yetanotherhueapi.
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.
@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.
@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.
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.
@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.
@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 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.
@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.
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 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.
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)
- Add colorloop effect
- Add group 0, i.e. the "all lights" group
- NPE when bridge doesn't return sensors HOT 5
- could you make a java 11 version which includes a module-info file. THX HOT 2
- Get color of light HOT 1
- Turn on / off room without setState (color, alert, etc...) HOT 2
- Why so restrictive? HOT 7
- Add mDNS support for discovering bridges HOT 1
- Add new light HOT 6
- Server-Sent Events HOT 7
- Implement a findByUiniqueId for lights and sensors HOT 11
- No logging by default HOT 3
- TemperatureSensor#getDegreesCelsius NPE HOT 10
- Get state ... question ? HOT 3
- Why such a restrictive State.Builder? HOT 2
- EffectType from String "prism": not one of the values accepted for Enum HOT 2
- Error when using v2 HOT 2
- JKS not found and java.io.FileNotFoundException: https://discovery.meethue.com/ HOT 28
- Client code generation HOT 2
- save bridge details HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yetanotherhueapi.