Improve catching polling errors
try/expect around http requests
This commit is contained in:
parent
2b82773070
commit
54e21a4f21
@ -48,8 +48,7 @@ class ZeroconfListener(object):
|
||||
return
|
||||
|
||||
pollTimer = None
|
||||
|
||||
playPoll = False
|
||||
pollFrequency = 40
|
||||
|
||||
def discoverThings(info):
|
||||
if info.thingClassId == receiverThingClassId:
|
||||
@ -314,7 +313,7 @@ def setupThing(info):
|
||||
return
|
||||
|
||||
def pollReceiver(info):
|
||||
global playPoll
|
||||
global pollFrequency
|
||||
if info.thingClassId == zoneThingClassId:
|
||||
# get parent receiver thing, needed to get deviceIp
|
||||
for possibleParent in myThings():
|
||||
@ -333,7 +332,15 @@ def pollReceiver(info):
|
||||
rUrl = 'http://' + deviceIp + ':80/YamahaRemoteControl/ctrl'
|
||||
body = bodyStart + '<Basic_Status>GetParam</Basic_Status>' + bodyEnd
|
||||
headers = {'Content-Type': 'text/xml', 'Accept': '*/*'}
|
||||
try:
|
||||
pr = requests.post(rUrl, headers=headers, data=body)
|
||||
polled = True
|
||||
except:
|
||||
logger.log("Device didn't respond to http request to get basic status", deviceIp, info.name)
|
||||
polled = False
|
||||
logger.log("Temporarily reducing pollfrequency to give the device some rest")
|
||||
pollFrequency = 120
|
||||
if polled == True:
|
||||
pollResponse = pr.text
|
||||
# add distinction between receiver & zone
|
||||
if info.thingClassId == receiverThingClassId:
|
||||
@ -443,7 +450,15 @@ def pollReceiver(info):
|
||||
# Get player info
|
||||
body = '<YAMAHA_AV cmd="GET"><' + inputSource + '><Play_Info>GetParam</Play_Info></' + inputSource + '></YAMAHA_AV>'
|
||||
headers = {'Content-Type': 'text/xml', 'Accept': '*/*'}
|
||||
try:
|
||||
plr = requests.post(rUrl, headers=headers, data=body)
|
||||
polled = True
|
||||
except:
|
||||
logger.log("Device didn't respond to http request to get player status", deviceIp, info.name)
|
||||
polled = False
|
||||
logger.log("Temporarily reducing pollfrequency to give the device some rest")
|
||||
pollFrequency = 120
|
||||
if polled == True:
|
||||
if plr.status_code == requests.codes.ok and powerState == True:
|
||||
playerResponse = plr.text
|
||||
# Get repeat state
|
||||
@ -468,13 +483,13 @@ def pollReceiver(info):
|
||||
responseExtract = playerResponse[stringIndex1+15:stringIndex2]
|
||||
if responseExtract == "Play":
|
||||
playStatus = "Playing"
|
||||
playPoll = True or playPoll
|
||||
pollFrequency = min(10, pollFrequency)
|
||||
elif responseExtract == "Pause":
|
||||
playStatus = "Paused"
|
||||
playPoll = True or playPoll
|
||||
pollFrequency = min(10, pollFrequency)
|
||||
else:
|
||||
playStatus = "Stopped"
|
||||
playPoll = False or playPoll
|
||||
pollFrequency = min(30, pollFrequency)
|
||||
receiver.setStateValue(receiverPlaybackStatusStateTypeId, playStatus)
|
||||
# Get meta info
|
||||
stringIndex1 = playerResponse.find("<Artist>")
|
||||
@ -551,7 +566,15 @@ def pollReceiver(info):
|
||||
# Get player info
|
||||
body = '<YAMAHA_AV cmd="GET"><' + inputSource + '><Play_Info>GetParam</Play_Info></' + inputSource + '></YAMAHA_AV>'
|
||||
headers = {'Content-Type': 'text/xml', 'Accept': '*/*'}
|
||||
try:
|
||||
plr = requests.post(rUrl, headers=headers, data=body)
|
||||
polled = True
|
||||
except:
|
||||
logger.log("Device didn't respond to http request to get player status", deviceIp, info.name)
|
||||
polled = False
|
||||
logger.log("Temporarily reducing pollfrequency to give the device some rest")
|
||||
pollFrequency = 120
|
||||
if polled == True:
|
||||
if plr.status_code == requests.codes.ok and powerState == True:
|
||||
playerResponse = plr.text
|
||||
# Get repeat state
|
||||
@ -576,13 +599,13 @@ def pollReceiver(info):
|
||||
responseExtract = playerResponse[stringIndex1+15:stringIndex2]
|
||||
if responseExtract == "Play":
|
||||
playStatus = "Playing"
|
||||
playPoll = True or playPoll
|
||||
pollFrequency = min(10, pollFrequency)
|
||||
elif responseExtract == "Pause":
|
||||
playStatus = "Paused"
|
||||
playPoll = True or playPoll
|
||||
pollFrequency = min(10, pollFrequency)
|
||||
else:
|
||||
playStatus = "Stopped"
|
||||
playPoll = False or playPoll
|
||||
pollFrequency = min(30, pollFrequency)
|
||||
zone.setStateValue(zonePlaybackStatusStateTypeId, playStatus)
|
||||
# Get meta info
|
||||
stringIndex1 = playerResponse.find("<Artist>")
|
||||
@ -617,17 +640,12 @@ def pollReceiver(info):
|
||||
def pollService():
|
||||
logger.log("pollService!!!")
|
||||
global pollTimer
|
||||
global playPoll
|
||||
# restart the timer for next poll (if player was playing at previous poll, increase poll frequency)
|
||||
# we start the timer before polling the receivers to test if this avoids the timer not restarting due to request errors in pollReceiver
|
||||
if playPoll == True:
|
||||
interval = 10
|
||||
else:
|
||||
interval = 30
|
||||
logger.log("Restarting timer @ pollService")
|
||||
pollTimer = threading.Timer(interval, pollService)
|
||||
global pollFrequency
|
||||
# restart the timer for next poll
|
||||
logger.log("Restarting timer @ pollService, with frequency", pollFrequency)
|
||||
pollTimer = threading.Timer(pollFrequency, pollService)
|
||||
pollTimer.start()
|
||||
playPoll = False
|
||||
pollFrequency = 30
|
||||
# Poll all receivers we know
|
||||
for thing in myThings():
|
||||
if thing.thingClassId == receiverThingClassId or thing.thingClassId == zoneThingClassId:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user