Created
July 29, 2020 22:55
-
-
Save kcollasarundell/0769c59ff0c80ebe880363c5801cd94f to your computer and use it in GitHub Desktop.
ring the doorbell
This file contains hidden or 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
package main | |
import ( | |
"sync" | |
"time" | |
"github.com/evalphobia/google-home-client-go/googlehome" | |
"github.com/hashicorp/mdns" | |
) | |
func main() { | |
wg := sync.WaitGroup{} | |
entriesCh := make(chan *mdns.ServiceEntry, 4) | |
wg.Add(1) | |
go func() { | |
defer wg.Done() | |
mdns.Lookup("_googlerpc._tcp", entriesCh) | |
close(entriesCh) | |
}() | |
for g := range entriesCh { | |
wg.Add(1) | |
go func(address string) { | |
defer wg.Done() | |
cli, err := googlehome.NewClientWithConfig(googlehome.Config{ | |
Hostname: address, | |
Lang: "en", | |
Accent: "GB", | |
}) | |
if err != nil { | |
panic(err) | |
} | |
oldvolume, _ := cli.GetVolume() | |
// Speak text on Google Home. | |
cli.SetVolume(0.5) | |
cli.Notify("There is someone at the door") | |
time.Sleep(4 * time.Second) | |
//Kills the running Application (Disconnects from Google Home) | |
cli.SetVolume(oldvolume) | |
cli.QuitApp() | |
}(g.AddrV4.String()) | |
} | |
wg.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment