nbogojevic/midea-beautiful-air

Attempt to change --fan_speed results in TypeError.

blurshot28 opened this issue · 4 comments

Using the CLI, with Python 3.9.2, and Midea-beautiful-air v0.9.14: Any attempt to change fan speed on a Midea U (Model: MAW08V1QWT, current FW) using --fan_speed [int] command line option and value, results in the following unhandled exception resulting in the form of a TypeError.

Command Issued:

midea-beautiful-air-cli set --ip 10.0.1.105 --token [token] --key [key] --mode 5 --fan-speed 60

Traceback:
Traceback (most recent call last):
File "/home/meerb/.local/bin/midea-beautiful-air-cli", line 8, in
sys.exit(cli())
File "/home/meerb/.local/lib/python3.9/site-packages/midea_beautiful/cli.py", line 340, in cli
return function(args)
File "/home/meerb/.local/lib/python3.9/site-packages/midea_beautiful/cli.py", line 263, in _run_set_command
return _process_attr_arguments(args, appliance, cloud)
File "/home/meerb/.local/lib/python3.9/site-packages/midea_beautiful/cli.py", line 222, in _process_attr_arguments
appliance.set_state(**set_args)
File "/home/meerb/.local/lib/python3.9/site-packages/midea_beautiful/lan.py", line 827, in set_state
self.apply(cloud)
File "/home/meerb/.local/lib/python3.9/site-packages/midea_beautiful/lan.py", line 687, in apply
cmd = self.state.apply_command()
File "/home/meerb/.local/lib/python3.9/site-packages/midea_beautiful/appliance.py", line 605, in apply_command
cmd.fan_speed = self.fan_speed
File "/home/meerb/.local/lib/python3.9/site-packages/midea_beautiful/command.py", line 665, in fan_speed
self.data[13] |= speed & 0b01111111
TypeError: unsupported operand type(s) for &: 'str' and 'int'

It appears there is type confusion from an implied type conversion, although it looks as though there is the proper type declaration in the setter method, in command.py:662:

@fan_speed.setter def fan_speed(self, speed: int) -> None: self.data[13] &= ~0b01111111 # Clear the fan speed part self.data[13] |= speed & 0b01111111

self.data[13] |= speed & 0b01111111

There seems a potentially related issue with the fan_speed being set periodically set to "2", while the Cool function is running. If the Midea is running with APP mode OFF, this does not seem to happen. I'll detail further in separate issue.

Original issue updated with direct line reference.

Issue is not resolved. It appears in v0.9.15 and it appears that the code in question was not updated to force type conversion, as was done in other areas in v0.9.15. Attempting to change fan speed per details in original post still results in the same unhandled exception in the form of a TypeError.

Traceback:
Traceback (most recent call last):
File "/home/meerb/.local/bin/midea-beautiful-air-cli", line 8, in
sys.exit(cli())
File "/home/meerb/.local/lib/python3.9/site-packages/midea_beautiful/cli.py", line 340, in cli
return function(args)
File "/home/meerb/.local/lib/python3.9/site-packages/midea_beautiful/cli.py", line 263, in _run_set_command
return _process_attr_arguments(args, appliance, cloud)
File "/home/meerb/.local/lib/python3.9/site-packages/midea_beautiful/cli.py", line 222, in _process_attr_arguments
appliance.set_state(**set_args)
File "/home/meerb/.local/lib/python3.9/site-packages/midea_beautiful/lan.py", line 848, in set_state
self.apply(cloud)
File "/home/meerb/.local/lib/python3.9/site-packages/midea_beautiful/lan.py", line 693, in apply
cmd = self.state.apply_command()
File "/home/meerb/.local/lib/python3.9/site-packages/midea_beautiful/appliance.py", line 609, in apply_command
cmd.fan_speed = self.fan_speed
File "/home/meerb/.local/lib/python3.9/site-packages/midea_beautiful/command.py", line 668, in fan_speed
self.data[13] |= speed & 0b01111111
TypeError: unsupported operand type(s) for &: 'str' and 'int'

Seems like that setter needs to be updated, and it appears a few more within the command.py, that I cannot test as the Midea U AC has no support for humidity setting, etc...

replacing self.data[13] |= speed & 0b01111111 with self.data[13] |= int(speed) & 0b01111111 on line 351 in the midea_beautiful/command.py appears to resolve the error in combination with @teleshoes pull request. Tested and working on Midea MPPD35H

Fixed with #23