@@ -65,7 +65,7 @@ func ProcessWebhook(plexChan chan<- models.PlexWebhookPayload, vip *viper.Viper)
65
65
return
66
66
}
67
67
clientUUID := decodedPayload .Player .UUID
68
- log .Debugf ( "!!! Your Player UUID is %s !!!!! " , clientUUID )
68
+ log .Infof ( "Got a request from UUID: %s " , clientUUID )
69
69
70
70
log .Debugf ("ProcessWebhook: Media type is: %s" , decodedPayload .Metadata .Type )
71
71
log .Debugf ("ProcessWebhook: Media title is: %s" , decodedPayload .Metadata .Title )
@@ -75,7 +75,16 @@ func ProcessWebhook(plexChan chan<- models.PlexWebhookPayload, vip *viper.Viper)
75
75
// only respond to events on a particular account if you share servers and only for movies and shows
76
76
if userID == "" || decodedPayload .Account .Title == userID {
77
77
if decodedPayload .Metadata .Type == movieItemTitle || decodedPayload .Metadata .Type == showItemTitle {
78
- plexChan <- decodedPayload
78
+ log .Debugf ("Current length of plexChan: %d" , len (plexChan ))
79
+ select {
80
+ case plexChan <- decodedPayload :
81
+ // send succeeded
82
+ case <- time .After (time .Second * 3 ):
83
+ log .Error ("Send on plexChan timed out" )
84
+ http .Error (w , err .Error (), http .StatusTooManyRequests )
85
+ return
86
+ }
87
+ log .Debugf ("Added length of plexChan: %d" , len (plexChan ))
79
88
}
80
89
} else {
81
90
log .Debugf ("userID '%s' does not match filter" , userID )
@@ -134,7 +143,13 @@ func mediaPause(vip *viper.Viper, beqClient *ezbeq.BeqClient, haClient *homeassi
134
143
}
135
144
136
145
// waitForHDMISync will wait until the envy reports a signal to assume hdmi sync. No API to do this with denon afaik
137
- func waitForHDMISync (wg * sync.WaitGroup , skipActions * bool , haClient * homeassistant.HomeAssistantClient , PlexClient * plex.PlexClient ) {
146
+ func waitForHDMISync (wg * sync.WaitGroup , skipActions * bool , haClient * homeassistant.HomeAssistantClient , PlexClient * plex.PlexClient , vip * viper.Viper ) {
147
+ if vip .GetBool ("ezbeq.waitforHDMIsync" ) {
148
+ wg .Done ()
149
+ return
150
+ }
151
+
152
+ log .Debug ("Running HDMI sync wait" )
138
153
defer func () {
139
154
// play item no matter what
140
155
err := PlexClient .PlayPlex ()
@@ -169,6 +184,11 @@ func waitForHDMISync(wg *sync.WaitGroup, skipActions *bool, haClient *homeassist
169
184
log .Debug ("HDMI sync complete" )
170
185
return
171
186
}
187
+ if err != nil {
188
+ log .Errorf ("Error reading envy attributes: %v" , err )
189
+ return
190
+ }
191
+ // otherwise continue
172
192
time .Sleep (1 * time .Second )
173
193
}
174
194
if err != nil {
@@ -193,8 +213,9 @@ func mediaPlay(client *plex.PlexClient, vip *viper.Viper, beqClient *ezbeq.BeqCl
193
213
// if not using denoncodec, do this in background
194
214
if ! useDenonCodec {
195
215
wg .Add (1 )
216
+ // TODO: get this working
196
217
// sets skipActions to false on completion
197
- go waitForHDMISync (wg , skipActions , haClient , client )
218
+ go waitForHDMISync (wg , skipActions , haClient , client , vip )
198
219
}
199
220
200
221
if vip .GetBool ("ezbeq.enabled" ) {
@@ -209,8 +230,8 @@ func mediaPlay(client *plex.PlexClient, vip *viper.Viper, beqClient *ezbeq.BeqCl
209
230
if useDenonCodec {
210
231
// wait for sync
211
232
wg .Add (1 )
212
- waitForHDMISync (wg , skipActions , haClient , client )
213
- // denon needs time to process mutli ch in as atmos first
233
+ waitForHDMISync (wg , skipActions , haClient , client , vip )
234
+ // denon needs time to show mutli ch in as atmos
214
235
// TODO: test this
215
236
time .Sleep (5 * time .Second )
216
237
@@ -454,6 +475,7 @@ func getPlexMovieDb(payload models.PlexWebhookPayload) string {
454
475
455
476
// will change aspect ratio
456
477
func changeAspect (client * plex.PlexClient , payload models.PlexWebhookPayload , vip * viper.Viper , wg * sync.WaitGroup ) {
478
+ defer wg .Done ()
457
479
if vip .GetBool ("homeAssistant.triggerAspectRatioChangeOnEvent" ) && vip .GetBool ("homeAssistant.enabled" ) {
458
480
459
481
// if madvr enabled, only send a trigger via mqtt
@@ -497,6 +519,7 @@ func changeAspect(client *plex.PlexClient, payload models.PlexWebhookPayload, vi
497
519
498
520
// trigger HA for MV change per type
499
521
func changeMasterVolume (vip * viper.Viper , mediaType string , wg * sync.WaitGroup ) {
522
+ defer wg .Done ()
500
523
if vip .GetBool ("homeAssistant.triggerAvrMasterVolumeChangeOnEvent" ) && vip .GetBool ("homeAssistant.enabled" ) {
501
524
log .Debug ("changeMasterVolume: Changing volume" )
502
525
err := mqtt .Publish (vip , []byte (fmt .Sprintf ("{\" type\" :\" %s\" }" , mediaType )), vip .GetString ("mqtt.topicVolume" ))
@@ -508,6 +531,7 @@ func changeMasterVolume(vip *viper.Viper, mediaType string, wg *sync.WaitGroup)
508
531
509
532
// trigger HA for light change given entity and desired state
510
533
func changeLight (vip * viper.Viper , state string , wg * sync.WaitGroup ) {
534
+ defer wg .Done ()
511
535
if vip .GetBool ("homeAssistant.triggerLightsOnEvent" ) && vip .GetBool ("homeAssistant.enabled" ) {
512
536
log .Debug ("changeLight: Changing light" )
513
537
err := mqtt .Publish (vip , []byte (fmt .Sprintf ("{\" state\" :\" %s\" }" , state )), vip .GetString ("mqtt.topicLights" ))
@@ -582,7 +606,12 @@ func PlexWorker(plexChan <-chan models.PlexWebhookPayload, vip *viper.Viper) {
582
606
583
607
// block forever until closed so it will wait in background for work
584
608
for i := range plexChan {
609
+ log .Debugf ("Current length of plexChan in PlexWorker: %d" , len (plexChan ))
585
610
// determine what to do
611
+ log .Debug ("Sending new payload to eventRouter" )
586
612
eventRouter (plexClient , beqClient , haClient , denonClient , useDenonCodec , i , vip , model , skipActions )
613
+ log .Debug ("eventRouter done processing payload" )
587
614
}
615
+
616
+ log .Debug ("Plex worker stopped" )
588
617
}
0 commit comments