From 8b11ffaf86e1e075b877382e60dd3e00a16e175e Mon Sep 17 00:00:00 2001 From: rospogrigio Date: Wed, 1 Jun 2022 18:05:12 +0200 Subject: [PATCH] Turned all 'print' messages into _LOGGER.debug --- custom_components/localtuya/climate.py | 2 +- custom_components/localtuya/cloud_api.py | 18 ++++++++++-------- custom_components/localtuya/common.py | 4 ---- custom_components/localtuya/const.py | 1 + custom_components/localtuya/cover.py | 2 +- custom_components/localtuya/switch.py | 2 +- custom_components/localtuya/vacuum.py | 3 +-- 7 files changed, 15 insertions(+), 17 deletions(-) diff --git a/custom_components/localtuya/climate.py b/custom_components/localtuya/climate.py index 8474a21..1400ec7 100644 --- a/custom_components/localtuya/climate.py +++ b/custom_components/localtuya/climate.py @@ -176,7 +176,7 @@ class LocaltuyaClimate(LocalTuyaEntity, ClimateEntity): self._has_presets = self.has_config(CONF_ECO_DP) or self.has_config( CONF_PRESET_DP ) - print("Initialized climate [{}]".format(self.name)) + _LOGGER.debug("Initialized climate [%s]", self.name) @property def supported_features(self): diff --git a/custom_components/localtuya/cloud_api.py b/custom_components/localtuya/cloud_api.py index 707b2da..6802171 100644 --- a/custom_components/localtuya/cloud_api.py +++ b/custom_components/localtuya/cloud_api.py @@ -3,10 +3,13 @@ import functools import hashlib import hmac import json +import logging import time import requests +_LOGGER = logging.getLogger(__name__) + # Signature algorithm. def calc_sign(msg, key): @@ -55,7 +58,7 @@ class TuyaCloudApi: + "\n/" + url.split("//", 1)[-1].split("/", 1)[-1] # Url ) - # print("PAYLOAD: {}".format(payload)) + # _LOGGER.debug("PAYLOAD: %s", payload) return payload async def async_make_request(self, method, url, body=None, headers={}): @@ -70,7 +73,7 @@ class TuyaCloudApi: "sign_method": "HMAC-SHA256", } full_url = self._base_url + url - # print("\n" + method + ": [{}]".format(full_url)) + # _LOGGER.debug("\n" + method + ": [%s]", full_url) if method == "GET": func = functools.partial( @@ -83,7 +86,7 @@ class TuyaCloudApi: headers=dict(default_par, **headers), data=json.dumps(body), ) - # print("BODY: [{}]".format(body)) + # _LOGGER.debug("BODY: [%s]", body) elif method == "PUT": func = functools.partial( requests.put, @@ -121,14 +124,13 @@ class TuyaCloudApi: r_json = resp.json() if not r_json["success"]: - # print( - # "Request failed, reply is {}".format( - # json.dumps(r_json, indent=2, ensure_ascii=False) - # ) + # _LOGGER.debug( + # "Request failed, reply is %s", + # json.dumps(r_json, indent=2, ensure_ascii=False) # ) return f"Error {r_json['code']}: {r_json['msg']}" self.device_list = {dev["id"]: dev for dev in r_json["result"]} - # print("DEV__LIST: {}".format(self.device_list)) + # _LOGGER.debug("DEV_LIST: %s", self.device_list) return "ok" diff --git a/custom_components/localtuya/common.py b/custom_components/localtuya/common.py index e694869..1b63e8a 100644 --- a/custom_components/localtuya/common.py +++ b/custom_components/localtuya/common.py @@ -74,10 +74,6 @@ async def async_setup_entry( if len(entities_to_setup) > 0: - if dev_id not in hass.data[DOMAIN][TUYA_DEVICES]: - print("STRANO: {}".format(hass.data[DOMAIN][TUYA_DEVICES])) - return - tuyainterface = hass.data[DOMAIN][TUYA_DEVICES][dev_id] dps_config_fields = list(get_dps_for_platform(flow_schema)) diff --git a/custom_components/localtuya/const.py b/custom_components/localtuya/const.py index c1d4248..c940304 100644 --- a/custom_components/localtuya/const.py +++ b/custom_components/localtuya/const.py @@ -39,6 +39,7 @@ CONF_ACTION = "action" CONF_ADD_DEVICE = "add_device" CONF_EDIT_DEVICE = "edit_device" CONF_SETUP_CLOUD = "setup_cloud" +CONF_NO_CLOUD = "no_cloud" # light CONF_BRIGHTNESS_LOWER = "brightness_lower" diff --git a/custom_components/localtuya/cover.py b/custom_components/localtuya/cover.py index 43f59a6..2a3eb8b 100644 --- a/custom_components/localtuya/cover.py +++ b/custom_components/localtuya/cover.py @@ -75,7 +75,7 @@ class LocaltuyaCover(LocalTuyaEntity, CoverEntity): self._state = self._stop_cmd self._previous_state = self._state self._current_cover_position = 0 - print("Initialized cover [{}]".format(self.name)) + _LOGGER.debug("Initialized cover [%s]", self.name) @property def supported_features(self): diff --git a/custom_components/localtuya/switch.py b/custom_components/localtuya/switch.py index f43d910..e884095 100644 --- a/custom_components/localtuya/switch.py +++ b/custom_components/localtuya/switch.py @@ -40,7 +40,7 @@ class LocaltuyaSwitch(LocalTuyaEntity, SwitchEntity): """Initialize the Tuya switch.""" super().__init__(device, config_entry, switchid, _LOGGER, **kwargs) self._state = None - print("Initialized switch [{}]".format(self.name)) + _LOGGER.debug("Initialized switch [%s]", self.name) @property def is_on(self): diff --git a/custom_components/localtuya/vacuum.py b/custom_components/localtuya/vacuum.py index dc75044..7bf4ed6 100644 --- a/custom_components/localtuya/vacuum.py +++ b/custom_components/localtuya/vacuum.py @@ -117,8 +117,7 @@ class LocaltuyaVacuum(LocalTuyaEntity, StateVacuumEntity): self._fan_speed = "" self._cleaning_mode = "" - - print("Initialized vacuum [{}]".format(self.name)) + _LOGGER.debug("Initialized vacuum [%s]", self.name) @property def supported_features(self):