From de3c9d51b23e0fe0e3b2f1cfd0a85930a75df49c Mon Sep 17 00:00:00 2001 From: Nicolas Duhamel Date: Wed, 21 Jul 2021 11:21:33 +0200 Subject: [PATCH] Add retry for api state (handling random error) --- setup.py | 3 ++- src/yamaha2mqtt/app.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ad8cd83..70f32cf 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,8 @@ setuptools.setup( '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', 'systemd-python==234', - 'typer==0.3.2' + 'typer==0.3.2', + 'tenacity==8.0.1' ] ) diff --git a/src/yamaha2mqtt/app.py b/src/yamaha2mqtt/app.py index 39054d0..4cd1e28 100644 --- a/src/yamaha2mqtt/app.py +++ b/src/yamaha2mqtt/app.py @@ -2,6 +2,8 @@ import logging import json import requests +from tenacity import retry, stop_after_attempt, wait_fixed + from pyamaha import Device, System, Zone from citadel.mqtt import Client @@ -39,6 +41,7 @@ class Yamaha: for action in senario.deactivate: self.request(action) + @retry(stop=stop_after_attempt(3), wait=wait_fixed(1), reraise=True) def request(self, request): try: r = self._device.request(request)