Feat: trigger light adoption

This commit is contained in:
kayos@tcp.direct 2022-10-11 22:45:59 -07:00
parent 05ebbae92e
commit 948e448c30
Signed by: kayos
GPG Key ID: 4B841471B4BEE979
2 changed files with 27 additions and 0 deletions

@ -6,6 +6,7 @@ import (
"fmt"
"strconv"
"strings"
"time"
"github.com/amimof/huego"
"github.com/davecgh/go-spew/spew"
@ -245,3 +246,28 @@ func cmdRename(br *ziggy.Bridge, args []string) error {
}
return nil
}
func cmdAdopt(br *ziggy.Bridge, args []string) error {
resp, err := br.FindLights()
if err != nil {
return err
}
log.Debug().Msgf(spew.Sprint(resp.Success))
newLights, err := br.GetNewLights()
if err != nil {
return err
}
print("searching")
for count := 0; count < 10; count++ {
print(".")
time.Sleep(1 * time.Second)
}
if len(newLights.Lights) == 0 {
return errors.New("no new lights found")
}
for _, l := range newLights.Lights {
log.Info().Msgf("[+] %s", l)
log.Trace().Msgf("%v", spew.Sprint(l))
}
return nil
}

@ -79,6 +79,7 @@ func init() {
Commands["delete"] = newZiggsCommand(cmdDelete, "delete objects from bridges", "del", "remove")
Commands["scan"] = newZiggsCommand(cmdScan, "scan for bridges/lights/sensors", "search", "find")
Commands["rename"] = newZiggsCommand(cmdRename, "rename object in bridge", "mv")
Commands["adopt"] = newZiggsCommand(cmdAdopt, "adopt new lights to the bridge")
Commands["set"] = newZiggsCommand(cmdSet, "update object properties in bridge", "update")
initCompletion()
}