Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#50 : Fix potential AttributeError for new configurations #59

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion tuya_iot/openmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(self, api: TuyaOpenAPI) -> None:
self.mq_config = None
self.message_listeners = set()

# https://developer.tuya.com/en/docs/cloud/c2c2630d7c?id=Kb68mozbi3foh
def _get_mqtt_config(self) -> Optional[TuyaMQConfig]:
response = self.api.post(
TO_C_CUSTOM_MQTT_CONFIG_API
Expand Down Expand Up @@ -160,7 +161,6 @@ def run(self):
try:
self.__run_mqtt()
backoff_seconds = 1

# reconnect every 2 hours required.
time.sleep(self.mq_config.expire_time - 60)
except RequestException as e:
Expand All @@ -175,6 +175,8 @@ def __run_mqtt(self):
mq_config = self._get_mqtt_config()
if mq_config is None:
logger.error("error while get mqtt config")
if self.mq_config is None: # if we have no initial mq_config this is a big problem.
raise RequestException()
return

self.mq_config = mq_config
Expand Down