-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |