Skip to content

Commit 0a99389

Browse files
authored
Merge pull request #15 from vishen/10_basic_retry_for_device_interaction
application: added a basic retry for if the device becomes unavailable
2 parents 54e4a0c + 4b7c646 commit 0a99389

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

application/application.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,18 @@ func (a *Application) writePlayedItems() error {
182182
}
183183

184184
func (a *Application) Update() error {
185-
recvStatus, err := a.getReceiverStatus()
185+
var recvStatus *cast.ReceiverStatusResponse
186+
var err error
187+
// Simple retry. We need this for when the device isn't currently
188+
// available, but it is likely that it will come up soon.
189+
for i := 0; i < 5; i++ {
190+
recvStatus, err = a.getReceiverStatus()
191+
if err == nil {
192+
break
193+
}
194+
a.log("unable to get status from device; attempt %d/5, retrying...", i+1)
195+
time.Sleep(time.Second * 2)
196+
}
186197
if err != nil {
187198
return err
188199
}

cmd/ls.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var lsCmd = &cobra.Command{
2727
Short: "List devices",
2828
RunE: func(cmd *cobra.Command, args []string) error {
2929
dnsEntries := castdns.FindCastDNSEntries()
30-
fmt.Printf("Found %d cast dns entries\n", len(dnsEntries))
30+
fmt.Printf("Found %d cast devices\n", len(dnsEntries))
3131
for i, d := range dnsEntries {
3232
fmt.Printf("%d) device=%q device_name=%q address=\"%s:%d\" status=%q uuid=%q\n", i+1, d.Device, d.DeviceName, d.AddrV4, d.Port, d.Status, d.UUID)
3333
}

cmd/status.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ var statusCmd = &cobra.Command{
2929
if err != nil {
3030
return err
3131
}
32-
if err := app.Update(); err != nil {
33-
return err
34-
}
3532
castApplication, castMedia, castVolume := app.Status()
3633
if castApplication == nil {
3734
fmt.Printf("Idle, volume=%0.2f muted=%t\n", castVolume.Level, castVolume.Muted)

0 commit comments

Comments
 (0)