Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/atotto/wemo-emulator
Alexa Multiple Belkin wemo switch emulator for Go
https://github.com/atotto/wemo-emulator
alexa belkin-wemo go wemo
Last synced: 22 days ago
JSON representation
Alexa Multiple Belkin wemo switch emulator for Go
- Host: GitHub
- URL: https://github.com/atotto/wemo-emulator
- Owner: atotto
- License: mit
- Created: 2021-12-09T10:58:10.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-03-16T13:50:22.000Z (almost 3 years ago)
- Last Synced: 2024-10-15T13:37:06.219Z (2 months ago)
- Topics: alexa, belkin-wemo, go, wemo
- Language: Go
- Homepage:
- Size: 4.88 KB
- Stars: 2
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Alexa Multiple Belkin wemo switch emulator
Package wemo provides a library that emulates the belkin wemo switch.
In this library, it is possible to define multiple switches and implement their behavior with callback functions.example/hello/main.go:
```go
package mainimport (
"context"
"log"
"os/signal"
"syscall"wemo "github.com/atotto/wemo-emulator"
)func main() {
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()light1 := wemo.ConfigSwitchService("my light 1", "8080", "1234", "abcd",
func(ctx context.Context, state bool) bool {
log.Println("light 1 on")
// write code
return true
}, func(ctx context.Context, state bool) bool {
log.Println("light 1 off")
// write code
return false
})light2 := wemo.ConfigSwitchService("my light 2", "8081", "123", "abc",
func(ctx context.Context, state bool) bool {
log.Println("light 2 on")
// write code
return true
}, func(ctx context.Context, state bool) bool {
log.Println("light 2 off")
// write code
return false
})if err := wemo.StartSwitchServices(ctx, light1, light2); err != nil {
if err != context.Canceled {
log.Fatal(err)
}
}
}
```How to use:
1. Run `go install github.com/atotto/wemo-emulator@latest`
2. Copy the `example/hello/main.go` code from this repository.
3. Define switches and callbacks.
4. Run `go run main.go`
5. Enjoy