Skip to content

Commit

Permalink
Updated search for disconnected devices
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfonso-directnic committed Jul 13, 2019
1 parent 2342972 commit 0e1a104
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
15 changes: 15 additions & 0 deletions broadlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,21 @@ func (b *Broadlink) AddManualDevice(ip string, macs string, deviceType int) erro
return nil
}

func (b Broadlink) DeviceExists(id string) bool {

d := b.getDevice(id)

if(d!=nil){

return true

}

return false


}

func (b Broadlink) getDevice(id string) *device {
d, ok := b.lookup[strings.ToLower(id)]
if !ok {
Expand Down
47 changes: 39 additions & 8 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,12 +759,9 @@ func main() {
}



ticker := time.NewTicker(5 * time.Second)

if(mode=="auto"){


ticker := time.NewTicker(5 * time.Second)

go func() {
for range ticker.C {
Expand Down Expand Up @@ -803,6 +800,8 @@ func main() {

for k,v := range dev {



devicetype := v[1]

ip := v[0]
Expand All @@ -813,13 +812,45 @@ func main() {

broadlink.AddManualDevice(ip, mac, deviceType)



}



}

go func() {

//update the ticker for the manual. mode to look for every 5 minutes
ticker = time.NewTicker(300 * time.Second) //look every 5

for range ticker.C {

if broadlink.Count() < len(dev) {

for k,v := range dev {

if( broadlink.DeviceExists(k) ){

continue
}

fmt.Println("Trying to connect to "+k)

devicetype := v[1]

ip := v[0]

mac := k

deviceType, _ := strconv.Atoi(devicetype)

broadlink.AddManualDevice(ip, mac, deviceType)

}

}

}

}()
}


Expand Down

0 comments on commit 0e1a104

Please sign in to comment.