-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add requesting of device state
- Loading branch information
1 parent
d7bb4a8
commit d2d6620
Showing
8 changed files
with
173 additions
and
1 deletion.
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
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
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,40 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"os" | ||
|
||
magichome "github.com/moonliightz/magic-home/pkg" | ||
) | ||
|
||
func checkError(e error) { | ||
if e != nil { | ||
fmt.Println("Error: ", e) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func main() { | ||
// Create a new Magic Home LED Strip Controller | ||
controller, err := magichome.New(net.ParseIP("192.168.42.105"), 5577) | ||
checkError(err) | ||
|
||
// Get device state | ||
var deviceState *magichome.DeviceState | ||
deviceState, err = controller.GetDeviceState() | ||
checkError(err) | ||
|
||
// Work with the response (print it) | ||
fmt.Printf("Device is: ") | ||
if deviceState.State == magichome.On { | ||
fmt.Println("On") | ||
} else { | ||
fmt.Println("Off") | ||
} | ||
fmt.Printf("Color: \tR: %d \n\tG: %d \n\tB: %d \n\tW: %d\n", deviceState.Color.R, deviceState.Color.G, deviceState.Color.B, deviceState.Color.W) | ||
|
||
// And finaly close the connection to LED Strip Controller | ||
err = controller.Close() | ||
checkError(err) | ||
} |
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
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
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 |
---|---|---|
|
@@ -4,4 +4,5 @@ type command struct { | |
on []byte | ||
off []byte | ||
color []byte | ||
state []byte | ||
} |
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
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