diff options
-rw-r--r-- | ShellyPy/gen2.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/ShellyPy/gen2.py b/ShellyPy/gen2.py index 21ffe84..96747c9 100644 --- a/ShellyPy/gen2.py +++ b/ShellyPy/gen2.py @@ -25,6 +25,7 @@ class ShellyGen2(ShellyBase): super().__init__(ip, port, *args, **kwargs) self.__generation__ = 2 + self.payload_id = 1 def update(self): status = self.settings() @@ -35,8 +36,14 @@ class ShellyGen2(ShellyBase): def post(self, page, values = None): url = "{}://{}:{}/rpc".format(self.__PROTOCOL__, self.__ip__, self.__port__) + # increment payload id globally + self.payload_id += 1 + # but keep a local copy around so we face no race conditions + payload_id = self.payload_id + payload = { - "id": 1, + "jsonrpc": "2.0", + "id": payload_id, "method": page, } @@ -68,6 +75,9 @@ class ShellyGen2(ShellyBase): else: raise BadResponse("{}: {}".format(error_code, error_message)) + if response_data["id"] != payload_id: + raise BadResponse("invalid payload id was returned") + return response_data.get("result", {}) def status(self): |