amimof / huego Goto Github PK
View Code? Open in Web Editor NEWAn extensive Philips Hue client library for Go with an emphasis on simplicity
License: MIT License
An extensive Philips Hue client library for Go with an emphasis on simplicity
License: MIT License
First, thanks for this library: the work is outstanding and I really, really love it! Impressive work!
I am integrating Huego (and many other libraries) into a library for my home-automation hub. My goal is to provide a technology-agnostic REST web-service.
A very common pattern for web-services, is to handle properly requests lifetime by honoring the status of the context.Context
that is attached to *http.Request
instances. Since this context automatically expires when the client underlying connection closes (or any other fatal network condition), this allows for circuit-breaking: for instance, if I use the context.Context
from the HTTP request and pass it in an underlying "turn this light on" operation, and the initiating request closes early, it gives a chance to the program to avoid doing unnecessary work by also stopping the "turn this light on" operation sooner.
It is as simple as doing:
req = req.WithContext(ctx)
Before issuing a HTTP request.
The current Huego APIs don't expose a way of passing in a context.Context
for each operation. Is that something you'd be interested in? I can probably make a pull-request for it, but I figured I'd discuss it with you first.
There is a way to do that without breaking the API by "overloading" each operation method with a Ctx
suffix. Say:
// Context creation: can be done in many ways.
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
// Example call.
light.OnCtx(ctx) // Guaranteed to complete when the operation is over or one second passes by, whichever happens first.
Please let me know what you think of this.
This is a little bug.
The light is off.
If you set the brightness to 254 for a light, the light will be switched on, but the State will remain off.
So, this code will never work...
if light.IsOn() {
light.Off()
} else {
light.Bri(254)
}
problem seems to be that the BriContext Method on the light object will not parse the response of the bridge. NOr does it directly change to state.on parameter. (Because it's not possible to set the bri to a light with state off...)
I found that this project already supports Go modules. But sadly, the tags doesn't follow Semantic Versioning, which means that all tags of this project will be ignored by Go modules and replaced by pseudo-versions, go get acts weirdly when tags are not in that form. It would be great to have the tagged release be named in the format vX.X.X format so that go mod can read it.
github.com/amimof/huego v0.0.0-20200504200310-b4a8f71aa2e3
Else the mod file shows something like github.com/amimof/huego v0.0.0-20200504200310-b4a8f71aa2e3
which is not very readable and difficult to upgrade. It’s hard to verify which version is in use. This is not conducive to version control
So, I propose this project to follow Semantic Versioning in future versions. For example, v1.0.1
, v2.0.0
, v3.1.0-alpha
, v3.1.0-beta.2
etc.
Entertainment groups have additional properties returned by the hue bridge, would be helpful to have them exposed
I get the following error when trying to call group.Rename()
: ERROR 6 [/groups/9/state]: "parameter, state, not available"
Is this a change in the API perhaps? Using the version of this code.
Probably related to #45 -- the recycle
parameter is marked as bool
without any omit
directive. It works for creating the scene but not for updating it.
Steps to reproduce the issue:
Describe the results you received:
I am implementing a terraform provider, this is the JSON:
{"name":"Testing","recycle":false}
│ Error: ERROR 8 [/scenes/jeU0J-6kXNVvnnL/recycle]: "parameter, recycle, is not modifiable"
Describe the results you expected:
Hue Bridge Version
"apiversion": "1.48.0",
"swversion": "1948086000",
Can I help?
I am learning go as I write this provider, if you provide me some pointers I can contribute towards the solution.
My naive solution would be adding a map to the "update" instead of using the struct so we have fine control over the elements -- but I think the solution from #45 would solve this in a better way.
Hi,
on some other SDKs (mainly directly from philips/Signify) there are some utility methods to convert RGB colors into XY.
It would be nice, if you can add this to your lib. Some background informations:
https://developers.meethue.com/develop/application-design-guidance/color-conversion-formulas-rgb-to-xy-and-back/
Some boolean attributes are annotated with json:"attributename,omitempty"
, which means they are omitted from requests when set to the default value for their type, i.e. false
. This means that it is impossible to set a boolean attribute to false using a Create* or Update* method.
AutoDelete
in Schedule
is one example of an affected attribute. It defaults to true when not provided, and there currently appears to be no way in huego to set it to false.
Here's a quick program that reproduces this:
package main
import (
"fmt"
"encoding/json"
"github.com/amimof/huego"
)
func main() {
bridge := huego.New("192.168.0.221", "[redacted]")
schedule := huego.Schedule{
Name: "Test schedule",
Command: &huego.Command{
Address: "/api/0/lights/4/state",
Method: "PUT",
Body: map[string]bool{
"on": true,
},
},
LocalTime: "PT00:00:03",
AutoDelete: false,
}
schedule_json, err := json.Marshal(schedule)
if err != nil {
fmt.Printf("error: %v\n", err)
return
}
fmt.Printf("JSONd schedule looks like this:\n%v\n", string(schedule_json))
response, err := bridge.CreateSchedule(&schedule)
if err != nil {
fmt.Printf("error: %v\n", err)
return
}
fmt.Printf("response: %v\n", response)
}
and here's what it outputs on my machine:
JSONd schedule looks like this:
{"name":"Test schedule","description":"","command":{"address":"/api/0/lights/4/state","method":"PUT","body":{"on":true}},"localtime":"PT00:00:03"}
response: &{map[id:2]}
Checking the Bridge API manually confirms that this schedule has autodelete: true
, and three seconds later it's gone.
Client ID is used with the entertainment API. we should expose or return the value.
https://developers.meethue.com/develop/hue-entertainment/philips-hue-entertainment-api/
I'm able to use the "discover -> create user" when I press the button on the bridge, but I'm not able to get the "new" command to work. Each time I run the line it says "ERROR 1 [/lights]: "unauthorized user"
But I know I've created that user ( by pushing the button and running the other code ) many times! Help.
bridge := huego.New("192.168.1.4", "tyler")
Running the example from the readme I get an error:
func main() {
bridge, _ := huego.Discover()
user, _ := bridge.CreateUser("my awesome hue app") // Link button needs to be pressed
bridge = bridge.Login(user)
light, _ := bridge.GetLight(3)
light.Off()
}
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x8 pc=0x60ab3b]
goroutine 1 [running]:
github.com/amimof/huego.(*Bridge).getAPIPath(0x0, 0xc042089d60, 0x3, 0x3, 0x40, 0x0, 0x0, 0x62a740)
C:/Go/bin/src/github.com/amimof/huego/bridge.go:21 +0x4b
github.com/amimof/huego.(*Bridge).SetLightState(0x0, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
C:/Go/bin/src/github.com/amimof/huego/bridge.go:487 +0x181
github.com/amimof/huego.(*Light).Off(0xc0421da0a0, 0x3, 0xc0421da0a0)
C:/Go/bin/src/github.com/amimof/huego/light.go:59 +0xa7
main.main()
C:/Users/Julian/Documents/WaterCan/main/main.go:16 +0x126
exit status 2
the create user example in README.md doesnt work for me. bridge.CreateUser fails with
Post "http:///api": http: no Host in request URL
Hello,
According to https://golang.org/ref/mod the Git tag format should be vX.Y.Z
.
So the tag for the version 1.2.0 should be v1.2.0
instead of 1.2.0
.
Currently the versions are not displayed here https://pkg.go.dev/github.com/amimof/huego?tab=versions
and all the links to the source code are broken https://pkg.go.dev/github.com/amimof/huego
(pkg.go.dev is replacing godoc.org)
Description
Hi. Really love this library. I was wondering if you have any plans to support the v2 Hue API. I can’t see anything browsing from my mobile. Thanks for any feedback you can provide.
Additional information
Hue now has the Entertainment API which allows for faster syncing through their DTLS/UDP protocol. https://developers.meethue.com/develop/hue-entertainment/philips-hue-entertainment-api/
Looking at this Go project, it seems like some of the stuff has been already worked on (creating user registration with generateclientkey set to true and groups light support). The only thing left seems to be getting a nice interface surrounding the DTLS/UDP part of the entertainment API. I'm wondering if anyone on this project has attempted to do this?
Hello,
Could you give an example of Remote Authentication, or add it to the readme? Thank you!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.