Skip to content

Commit

Permalink
Added a README and an example
Browse files Browse the repository at this point in the history
  • Loading branch information
Flonja committed Oct 23, 2023
1 parent fded578 commit a9426e1
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# golightmyroom
A go library for controlling Philips Hue light(s) with bluetooth.

My motivation for this project started with not being able to control my light with my laptop, but also that [Philips is now forcing users to make an account in order to use their purchased light(s)](https://www.reddit.com/r/homeassistant/comments/16oaozs/philips_hue_will_soon_force_users_to_create_a_hue/),
so now I've gotten a bigger reason to make this!

## Example
An example can be found at [example.go](./example.go)

## Contributing
Currently, contributing is a bit difficult right now, since a lot the code for controlling a light is shared logic. I haven't gotten around to separating it yet.
46 changes: 46 additions & 0 deletions example.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package golightmyroom

import (
"context"
"sync"
)

func main() {
lights, err := multipleLights("mac address 1", "mac address 2")
if err != nil {
panic(err)
}

runMultiple(lights, func(light Light) {
light.SetBrightness(0.5)
if temperatureControlled, ok := light.(TemperatureControl); ok {
temperatureControlled.SetTemperature(TemperatureWarmWhite)
}
})
}

func multipleLights(macAddresses ...string) (lights []Light, err error) {
for _, macAddress := range macAddresses {
var light Light
light, err = ConnectToBluetoothWithContext(macAddress, context.Background())
if err != nil {
return nil, err
}
lights = append(lights, light)
}
return lights, nil
}

func runMultiple(lights []Light, f func(light Light)) {
var wg sync.WaitGroup
for _, light := range lights {
wg.Add(1)

light := light
go func() {
f(light)
wg.Done()
}()
}
wg.Wait()
}

0 comments on commit a9426e1

Please sign in to comment.