Add retry for api state (handling random error)
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Nicolas Duhamel 2021-07-21 11:21:33 +02:00
parent e9f0dd3f87
commit de3c9d51b2
2 changed files with 5 additions and 1 deletions

View File

@ -5,7 +5,8 @@ setuptools.setup(
'pyamaha @ git+https://github.com/nduhamel/pyamaha.git@citadel#egg=pyamaha', 'pyamaha @ git+https://github.com/nduhamel/pyamaha.git@citadel#egg=pyamaha',
'citadel.mqtt @ git+https://git.quimbo.fr/citadel/mqtt.git@master#egg=citadel.mqtt', 'citadel.mqtt @ git+https://git.quimbo.fr/citadel/mqtt.git@master#egg=citadel.mqtt',
'systemd-python==234', 'systemd-python==234',
'typer==0.3.2' 'typer==0.3.2',
'tenacity==8.0.1'
] ]
) )

View File

@ -2,6 +2,8 @@ import logging
import json import json
import requests import requests
from tenacity import retry, stop_after_attempt, wait_fixed
from pyamaha import Device, System, Zone from pyamaha import Device, System, Zone
from citadel.mqtt import Client from citadel.mqtt import Client
@ -39,6 +41,7 @@ class Yamaha:
for action in senario.deactivate: for action in senario.deactivate:
self.request(action) self.request(action)
@retry(stop=stop_after_attempt(3), wait=wait_fixed(1), reraise=True)
def request(self, request): def request(self, request):
try: try:
r = self._device.request(request) r = self._device.request(request)