mac-zhou / midea-msmart

This is a library to allow communicating to a Midea AC via the Local area network.
MIT License
147 stars 39 forks source link

[midea_ac -> msmart] home assistant error logs contains lots of throw errors. #66

Closed tinymins closed 2 years ago

tinymins commented 2 years ago
2022-02-08 14:52:05 ERROR (MainThread) [homeassistant.helpers.entity] Update for climate.midea_ac_163827236973635 fails
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 512, in async_update_ha_state
await self.async_device_update()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 716, in async_device_update
raise exc
File "/config/custom_components/midea_ac/climate.py", line 133, in async_update
await self.hass.async_add_executor_job(self._device.refresh)
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.9/site-packages/msmart/device.py", line 198, in refresh
self._send_cmd(cmd)
File "/usr/local/lib/python3.9/site-packages/msmart/device.py", line 208, in _send_cmd
responses = self._lan_service.appliance_transparent_send_8370(data)
File "/usr/local/lib/python3.9/site-packages/msmart/lan.py", line 136, in appliance_transparent_send_8370
data = self.security.encode_8370(data, msgtype)
File "/usr/local/lib/python3.9/site-packages/msmart/security.py", line 120, in encode_8370
data = self.aes_cbc_encrypt(data, self._tcp_key) + sign
File "/usr/local/lib/python3.9/site-packages/msmart/security.py", line 57, in aes_cbc_encrypt
return AES.new(key, AES.MODE_CBC, iv=self.iv).encrypt(raw)
File "/usr/local/lib/python3.9/site-packages/Cryptodome/Cipher/AES.py", line 232, in new
return _create_cipher(sys.modules[__name__], key, mode, *args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/Cryptodome/Cipher/__init__.py", line 79, in _create_cipher
return modes[mode](factory, **kwargs)
File "/usr/local/lib/python3.9/site-packages/Cryptodome/Cipher/_mode_cbc.py", line 274, in _create_cbc_cipher
cipher_state = factory._create_base_cipher(kwargs)
File "/usr/local/lib/python3.9/site-packages/Cryptodome/Cipher/AES.py", line 92, in _create_base_cipher
if len(key) not in key_size:
TypeError: object of type 'NoneType' has no len()

I guess maybe home assistant failed to communicate with air conditioner, the key got empty.

andreasc1 commented 2 years ago

home assistant log is being flooded by all these.

andreasc1 commented 2 years ago
Log Details (ERROR)
This error originated from a custom integration.
Logger: homeassistant.helpers.entity
Source: custom_components/midea_ac/climate.py:133
Integration: midea_ac (documentation)
First occurred: February 10, 2022, 6:12:18 PM (4147 occurrences)
Last logged: 11:30:23 AM

Update for climate.midea_ac_31885837448266 fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 518, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 722, in async_device_update
    raise exc
  File "/config/custom_components/midea_ac/climate.py", line 133, in async_update
    await self.hass.async_add_executor_job(self._device.refresh)
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.9/site-packages/msmart/device.py", line 198, in refresh
    self._send_cmd(cmd)
  File "/usr/local/lib/python3.9/site-packages/msmart/device.py", line 208, in _send_cmd
    responses = self._lan_service.appliance_transparent_send_8370(data)
  File "/usr/local/lib/python3.9/site-packages/msmart/lan.py", line 136, in appliance_transparent_send_8370
    data = self.security.encode_8370(data, msgtype)
  File "/usr/local/lib/python3.9/site-packages/msmart/security.py", line 120, in encode_8370
    data = self.aes_cbc_encrypt(data, self._tcp_key) + sign
  File "/usr/local/lib/python3.9/site-packages/msmart/security.py", line 57, in aes_cbc_encrypt
    return AES.new(key, AES.MODE_CBC, iv=self.iv).encrypt(raw)
  File "/usr/local/lib/python3.9/site-packages/Cryptodome/Cipher/AES.py", line 232, in new
    return _create_cipher(sys.modules[__name__], key, mode, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/Cryptodome/Cipher/__init__.py", line 79, in _create_cipher
    return modes[mode](factory, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/Cryptodome/Cipher/_mode_cbc.py", line 274, in _create_cbc_cipher
    cipher_state = factory._create_base_cipher(kwargs)
  File "/usr/local/lib/python3.9/site-packages/Cryptodome/Cipher/AES.py", line 92, in _create_base_cipher
    if len(key) not in key_size:
TypeError: object of type 'NoneType' has no len()
mac-zhou commented 2 years ago

I guess maybe home assistant failed to communicate with air conditioner, the key got empty.

yes, I didn't consider authentication failure

mac-zhou commented 2 years ago

@tinymins @andreasc1 try pip3 install git+https://github.com/mac-zhou/midea-msmart please feedback

andreasc1 commented 2 years ago

@tinymins @andreasc1 try pip3 install git+https://github.com/mac-zhou/midea-msmart please feedback

install it on HA you mean? have in mind that i already run that tool to fetch the keys. those keys were added to HA. I just have 2 ACs online and 2 ACs offline. system should recognize that those are offline and not generate logs (if indeed those logs are generated due to the offline ACs).

mac-zhou commented 2 years ago

Please update the beta version manually https://github.com/mac-zhou/midea-ac-py/tree/dev/custom_components/midea_ac

andreasc1 commented 2 years ago

Please update the beta version manually https://github.com/mac-zhou/midea-ac-py/tree/dev/custom_components/midea_ac

thanks, i replaced the files but i get:

Platform error: climate - Requirements for midea_ac not found: ['msmart==git+https://github.com/mac-zhou/midea-msmart'].
1:41:17 PM – (ERROR) config.py - message first occurred at 1:41:04 PM and shows up 4 times
Unable to install package msmart==git+https://github.com/mac-zhou/midea-msmart: ERROR: Could not find a version that satisfies the requirement msmart==git+https://github.com/mac-zhou/midea-msmart (from versions: 0.1.8, 0.1.10, 0.1.11, 0.1.12, 0.1.13, 0.1.14, 0.1.15, 0.1.16, 0.1.17, 0.1.18, 0.1.19, 0.1.20, 0.1.21, 0.1.22, 0.1.23, 0.1.24, 0.1.25, 0.1.26, 0.1.27, 0.1.28, 0.1.29, 0.1.30, 0.1.31, 0.1.32, 0.1.33, 0.1.34, 0.1.35, 0.1.36, 0.2.0, 0.2.1) ERROR: No matching distribution found for msmart==git+https://github.com/mac-zhou/midea-msmart WARNING: You are using pip version 20.2.4; however, version 22.0.3 is available. You should consider upgrading via the '/usr/local/bin/python3 -m pip install --upgrade pip' command.
1:41:04 PM – (ERROR) util/package.py - message first occurred at 1:40:02 PM and shows up 3 times

is it because it was not updated via hacs?

mac-zhou commented 2 years ago

New version (0.2.2) has been released, please upgrade and give feedback

tinymins commented 2 years ago
File "/usr/local/lib/python3.9/site-packages/msmart/lan.py", line 135, in appliance_transparent_send_8370
    if self._authenticate() == False:
  File "/usr/local/lib/python3.9/site-packages/msmart/lan.py", line 125, in _authenticate
    raise Exception('missing token key pair')
Exception: missing token key pair
2022-02-28 09:56:41 ERROR (MainThread) [homeassistant.helpers.entity] Update for climate.midea_ac_164926744212639 fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 521, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 725, in async_device_update
    raise exc
  File "/config/custom_components/midea_ac/climate.py", line 139, in async_update
    await self.hass.async_add_executor_job(self._device.refresh)
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.9/site-packages/msmart/device.py", line 204, in refresh
    self._send_cmd(cmd)
  File "/usr/local/lib/python3.9/site-packages/msmart/device.py", line 214, in _send_cmd
    responses = self._lan_service.appliance_transparent_send_8370(data)
  File "/usr/local/lib/python3.9/site-packages/msmart/lan.py", line 135, in appliance_transparent_send_8370
    if self._authenticate() == False:
  File "/usr/local/lib/python3.9/site-packages/msmart/lan.py", line 125, in _authenticate
    raise Exception('missing token key pair')
Exception: missing token key pair
2022-02-28 09:56:56 ERROR (MainThread) [homeassistant.helpers.entity] Update for climate.midea_ac_164926744212621 fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 521, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 725, in async_device_update
    raise exc
  File "/config/custom_components/midea_ac/climate.py", line 139, in async_update
    await self.hass.async_add_executor_job(self._device.refresh)
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.9/site-packages/msmart/device.py", line 204, in refresh
    self._send_cmd(cmd)
  File "/usr/local/lib/python3.9/site-packages/msmart/device.py", line 214, in _send_cmd
    responses = self._lan_service.appliance_transparent_send_8370(data)
  File "/usr/local/lib/python3.9/site-packages/msmart/lan.py", line 135, in appliance_transparent_send_8370
    if self._authenticate() == False:
  File "/usr/local/lib/python3.9/site-packages/msmart/lan.py", line 125, in _authenticate
    raise Exception('missing token key pair')
Exception: missing token key pair
2022-02-28 09:56:56 ERROR (MainThread) [homeassistant.helpers.entity] Update for climate.midea_ac_163827234076359 fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 521, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 725, in async_device_update
    raise exc
  File "/config/custom_components/midea_ac/climate.py", line 139, in async_update
    await self.hass.async_add_executor_job(self._device.refresh)
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.9/site-packages/msmart/device.py", line 204, in refresh
    self._send_cmd(cmd)
  File "/usr/local/lib/python3.9/site-packages/msmart/device.py", line 214, in _send_cmd
    responses = self._lan_service.appliance_transparent_send_8370(data)
  File "/usr/local/lib/python3.9/site-packages/msmart/lan.py", line 135, in appliance_transparent_send_8370
    if self._authenticate() == False:
  File "/usr/local/lib/python3.9/site-packages/msmart/lan.py", line 125, in _authenticate
    raise Exception('missing token key pair')
Exception: missing token key pair
2022-02-28 09:56:56 ERROR (MainThread) [homeassistant.helpers.entity] Update for climate.midea_ac_163827236973635 fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 521, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 725, in async_device_update
    raise exc
  File "/config/custom_components/midea_ac/climate.py", line 139, in async_update
    await self.hass.async_add_executor_job(self._device.refresh)
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.9/site-packages/msmart/device.py", line 204, in refresh
    self._send_cmd(cmd)
  File "/usr/local/lib/python3.9/site-packages/msmart/device.py", line 214, in _send_cmd
    responses = self._lan_service.appliance_transparent_send_8370(data)
  File "/usr/local/lib/python3.9/site-packages/msmart/lan.py", line 135, in appliance_transparent_send_8370
    if self._authenticate() == False:
  File "/usr/local/lib/python3.9/site-packages/msmart/lan.py", line 125, in _authenticate
    raise Exception('missing token key pair')
Exception: missing token key pair
2022-02-28 09:56:56 ERROR (MainThread) [homeassistant.helpers.entity] Update for climate.midea_ac_164926744212639 fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 521, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 725, in async_device_update
    raise exc
  File "/config/custom_components/midea_ac/climate.py", line 139, in async_update
    await self.hass.async_add_executor_job(self._device.refresh)
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.9/site-packages/msmart/device.py", line 204, in refresh
    self._send_cmd(cmd)
  File "/usr/local/lib/python3.9/site-packages/msmart/device.py", line 214, in _send_cmd
    responses = self._lan_service.appliance_transparent_send_8370(data)
  File "/usr/local/lib/python3.9/site-packages/msmart/lan.py", line 135, in appliance_transparent_send_8370
    if self._authenticate() == False:
  File "/usr/local/lib/python3.9/site-packages/msmart/lan.py", line 125, in _authenticate
    raise Exception('missing token key pair')
Exception: missing token key pair

Thanks! I just upgrade and reboot HA, find this in logs.

mac-zhou commented 2 years ago

@tinymins i just push 1 new commit to fix this issue, please update https://github.com/mac-zhou/midea-ac-py/commit/f5a264681816b360cc95e9b96ff2c102612a7719

acburnett commented 2 years ago

@tinymins i just push 1 new commit to fix this issue, please update mac-zhou/midea-ac-py@f5a2646

Fixed it for me! Thank you for the quick update. Greatly appreciate this integration and your hard work. -Adam

mac-zhou commented 2 years ago

The new version(v0.2.2) should solve this problem, please update If there are still questions, please give feedback