From 89dabfc10504ecf7880c012d2092384c04d8cabb Mon Sep 17 00:00:00 2001 From: ultratoto14 Date: Tue, 15 Dec 2020 17:12:52 +0100 Subject: [PATCH] Reduce heartbeat interval. --- .gitignore | 3 ++- custom_components/localtuya/common.py | 4 ++-- custom_components/localtuya/pytuya/__init__.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 8546cc7..ecd6feb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *~ __pycache__ .tox -tuyadebug/ \ No newline at end of file +tuyadebug/ +.pre-commit-config.yaml \ No newline at end of file diff --git a/custom_components/localtuya/common.py b/custom_components/localtuya/common.py index e63bd11..f8b84f1 100644 --- a/custom_components/localtuya/common.py +++ b/custom_components/localtuya/common.py @@ -150,10 +150,10 @@ class TuyaDevice(pytuya.TuyaListener, pytuya.ContextualLogger): async def close(self): """Close connection and stop re-connect loop.""" self._is_closing = True - if self._connect_task: + if self._connect_task is not None: self._connect_task.cancel() await self._connect_task - if self._interface: + if self._interface is not None: await self._interface.close() async def set_dp(self, state, dp_index): diff --git a/custom_components/localtuya/pytuya/__init__.py b/custom_components/localtuya/pytuya/__init__.py index 89f2aca..2e9670b 100644 --- a/custom_components/localtuya/pytuya/__init__.py +++ b/custom_components/localtuya/pytuya/__init__.py @@ -74,7 +74,7 @@ MESSAGE_END_FMT = ">2I" # 2*uint32: crc, suffix PREFIX_VALUE = 0x000055AA SUFFIX_VALUE = 0x0000AA55 -HEARTBEAT_INTERVAL = 20 +HEARTBEAT_INTERVAL = 10 # This is intended to match requests.json payload at # https://github.com/codetheweb/tuyapi :