Skip to content

Commit

Permalink
Move logging info to debug
Browse files Browse the repository at this point in the history
  • Loading branch information
barban-dev authored Jan 5, 2024
1 parent 6b47d51 commit d8f46b3
Showing 1 changed file with 35 additions and 35 deletions.
70 changes: 35 additions & 35 deletions midea_inventor_lib/midea_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def __init__(self, email, password, sha256password, debug=False, verbose=False,

if not logFile:
logging.basicConfig(level=loglevel)
logging.info("MideaClient: logging to console.")
logging.debug("MideaClient: logging to console.")
else:
logging.basicConfig(filename=logFile, level=loglevel)
logging.info("MideaClient: logging to file: %s", logFile)
logging.debug("MideaClient: logging to file: %s", logFile)

logging.info("MideaClient: logging level set to: %s", loglevelStr)

Expand Down Expand Up @@ -141,7 +141,7 @@ def listAppliances(self):
for dict in result["list"]:
if dict["isDefault"] == "1":
self.default_home = dict
logging.info("MideaClient::listAppliances: homegroupId: %s", dict["id"])
logging.debug("MideaClient::listAppliances: homegroupId: %s", dict["id"])

if self.default_home is None:
logging.error("MideaClient::listAppliances: ERROR: homegroupId not found.")
Expand Down Expand Up @@ -172,7 +172,7 @@ def get_device_status(self, deviceId):
now = time.time()
if now - self.cacheTimeStamp < self.CACHE_TIME:
#Cache results can be used
logging.info("MideaClient::get_device_status (cached): %s", self.deviceStatus.toString())
logging.debug("MideaClient::get_device_status (cached): %s", self.deviceStatus.toString())
return 1


Expand Down Expand Up @@ -222,21 +222,21 @@ def get_device_status(self, deviceId):
self.deviceStatus = response.toMideaDehumidificationDeviceObject(status)
self.cacheTimeStamp = time.time() #Update cacheTimeStamp

logging.info("MideaClient::get_device_status: %s", self.deviceStatus.toString())
logging.debug("MideaClient::get_device_status: %s", self.deviceStatus.toString())
return 1


def send_poweron_command(self, deviceId):
if self.current is None:
logging.info("MideaClient::send_poweron_command: API session is not initialized: please login first.")
logging.debug("MideaClient::send_poweron_command: API session is not initialized: please login first.")
return None

if self.deviceStatus is None:
logging.info("MideaClient::send_poweron_command: device's status unknown: please call get_device_status() first.")
logging.debug("MideaClient::send_poweron_command: device's status unknown: please call get_device_status() first.")
return None

if self.deviceStatus.powerMode == 1:
logging.info("MideaClient::send_poweron_command: device is already on.")
logging.debug("MideaClient::send_poweron_command: device is already on.")
return None

#Create new command request
Expand All @@ -251,15 +251,15 @@ def send_poweron_command(self, deviceId):

def send_poweroff_command(self, deviceId):
if self.current is None:
logging.info("MideaClient::send_poweroff_command: API session is not initialized: please login first.")
logging.debug("MideaClient::send_poweroff_command: API session is not initialized: please login first.")
return 0

if self.deviceStatus is None:
logging.info("MideaClient::send_poweroff_command: device's status unknown: please call get_device_status() first.")
logging.debug("MideaClient::send_poweroff_command: device's status unknown: please call get_device_status() first.")
return 0

if self.deviceStatus.powerMode == 0:
logging.info("MideaClient::send_poweroff_command: device is already off.")
logging.debug("MideaClient::send_poweroff_command: device is already off.")
return 0

#Create new command request
Expand All @@ -284,19 +284,19 @@ def send_fan_speed_high_command(self, deviceId):

def send_fan_speed_command(self, deviceId, speed):
if self.current is None:
loggin.info("MideaClient::send_fan_speed_command: API session is not initialized: please login first.")
loggin.debug("MideaClient::send_fan_speed_command: API session is not initialized: please login first.")
return 0

if self.deviceStatus is None:
logging.info("MideaClient::send_fan_speed_command: device's status unknown: please call get_device_status() first.")
logging.debug("MideaClient::send_fan_speed_command: device's status unknown: please call get_device_status() first.")
return 0

if self.deviceStatus.powerMode == 0:
logging.info("MideaClient::send_fan_speed_command: device is off.")
logging.debug("MideaClient::send_fan_speed_command: device is off.")
return 0

if not (speed > 0 and speed < 100):
logging.info("MideaClient::send_fan_speed_command: speed value is not valid.")
logging.debug("MideaClient::send_fan_speed_command: speed value is not valid.")
return 0

#Create new command request
Expand All @@ -311,19 +311,19 @@ def send_fan_speed_command(self, deviceId, speed):

def send_target_humidity_command(self, deviceId, humidity):
if self.current is None:
logging.info("MideaClient::send_target_humidity_command: API session is not initialized: please login first.")
logging.debug("MideaClient::send_target_humidity_command: API session is not initialized: please login first.")
return None

if self.deviceStatus is None:
logging.info("MideaClient::send_target_humidity_command: device's status unknown: please call get_device_status() first.")
logging.debug("MideaClient::send_target_humidity_command: device's status unknown: please call get_device_status() first.")
return None

if self.deviceStatus.powerMode == 0:
logging.info("MideaClient::send_target_humidity_command: device is off.")
logging.debug("MideaClient::send_target_humidity_command: device is off.")
return None

if not (humidity >= 30 and humidity <= 70):
logging.info("MideaClient::send_target_humidity_command: range for target humidity is not valid.")
logging.debug("MideaClient::send_target_humidity_command: range for target humidity is not valid.")
return None

#Create new command request
Expand Down Expand Up @@ -351,19 +351,19 @@ def send_dryer_mode_command(self, deviceId):

def send_mode_command(self, deviceId, mode):
if self.current is None:
logging.info("MideaClient::send_mode_command: API session is not initialized: please login first.")
logging.debug("MideaClient::send_mode_command: API session is not initialized: please login first.")
return 0

if self.deviceStatus is None:
logging.info("MideaClient::send_mode_command: device's status unknown: please call get_device_status() first.")
logging.debug("MideaClient::send_mode_command: device's status unknown: please call get_device_status() first.")
return 0

if self.deviceStatus.powerMode == 0:
logging.info("MideaClient::send_mode_command: device is off.")
logging.debug("MideaClient::send_mode_command: device is off.")
return 0

if not (mode > 0 and mode < 5):
logging.info("MideaClient::send_mode_command: mode is not valid.")
logging.debug("MideaClient::send_mode_command: mode is not valid.")
return 0

#Create new command request
Expand All @@ -379,19 +379,19 @@ def send_mode_command(self, deviceId, mode):

def send_ion_on_command(self, deviceId):
if self.current is None:
logging.info("MideaClient::send_ion_on_command: API session is not initialized: please login first.")
logging.debug("MideaClient::send_ion_on_command: API session is not initialized: please login first.")
return 0

if self.deviceStatus is None:
logging.info("MideaClient::send_ion_on_command: device's status unknown: please call get_device_status() first.")
logging.debug("MideaClient::send_ion_on_command: device's status unknown: please call get_device_status() first.")
return 0

if self.deviceStatus.powerMode == 0:
logging.info("MideaClient::send_ion_on_command: device is off.")
logging.debug("MideaClient::send_ion_on_command: device is off.")
return 0

if self.deviceStatus.ionSetSwitch == 1:
logging.info("MideaClient::send_ion_on_command: Ion mode is alreay on.")
logging.debug("MideaClient::send_ion_on_command: Ion mode is alreay on.")
return 0

#Create new command request
Expand All @@ -407,19 +407,19 @@ def send_ion_on_command(self, deviceId):

def send_ion_off_command(self, deviceId):
if self.current is None:
logging.info("MideaClient::send_ion_off_command: API session is not initialized: please login first.")
logging.debug("MideaClient::send_ion_off_command: API session is not initialized: please login first.")
return 0

if self.deviceStatus is None:
logging.info("MideaClient::send_ion_off_command: device's status unknown: please call get_device_status() first.")
logging.debug("MideaClient::send_ion_off_command: device's status unknown: please call get_device_status() first.")
return 0

if self.deviceStatus.powerMode == 0:
logging.info("MideaClient::send_ion_off_command: device is off.")
logging.debug("MideaClient::send_ion_off_command: device is off.")
return 0

if self.deviceStatus.ionSetSwitch == 0:
logging.info("MideaClient::send_ion_off_command: Ion mode is alreay off.")
logging.debug("MideaClient::send_ion_off_command: Ion mode is alreay off.")
return 0

#Create new command request
Expand All @@ -437,11 +437,11 @@ def send_update_status_command(self, deviceId, deviceStatus):
""" Generic command to set a new device status """

if self.current is None:
logging.info("MideaClient::send_ion_off_command: API session is not initialized: please login first.")
logging.debug("MideaClient::send_ion_off_command: API session is not initialized: please login first.")
return 0

if self.deviceStatus.powerMode == 0:
logging.info("MideaClient::send_ion_off_command: device is off.")
logging.debug("MideaClient::send_ion_off_command: device is off.")
return 0

#Sanity checks
Expand Down Expand Up @@ -505,7 +505,7 @@ def __send_command(self, request, header, deviceId):
#Process response (get device status)
response = DataBodyDeHumiResponse()
self.deviceStatus = response.toMideaDehumidificationDeviceObject(status)
logging.info("MideaClient::__send_command: %s", self.deviceStatus.toString())
logging.debug("MideaClient::__send_command: %s", self.deviceStatus.toString())
return 1


Expand Down Expand Up @@ -591,7 +591,7 @@ def __send_api_request(self, uri, args):
#Https POST request
response = requests.post(uri, data=args)
logging.debug("MideaClient::send_api_request: response=%s", response.text) #TEXT/HTML
logging.info("MideaClient::send_api_request: response_status=%s, response_reason=%s", response.status_code, response.reason) #HTTP
logging.debug("MideaClient::send_api_request: response_status=%s, response_reason=%s", response.status_code, response.reason) #HTTP

data = response.json()
return data
Expand Down

0 comments on commit d8f46b3

Please sign in to comment.