mac-zhou / midea-ac-py

Home Assistant Custom Integration for Midea Group(Hualing, Senville, Klimaire, AirCon, Century, Pridiom, Thermocore, Comfee, Toshiba, Carrier, Goodman, Friedrich, Samsung, Kenmore, Trane, Lennox, LG and much more) Air Conditioners via LAN.
MIT License
519 stars 101 forks source link

Outdoor temperature not read correctly #147

Closed gergely-sallai closed 2 years ago

gergely-sallai commented 2 years ago

Describe the bug (描述一下问题) Outdoor temperature reading is static, always 102.5 Celsius. I can reproduce the problem on two different Carrier Extreme devices. The outdoor temperature is accurate if reading from the Carrier Android application.

I believe this is a parsing error of the outdoor_temperature value. Relevant line of code: https://github.com/mac-zhou/midea-msmart/blob/34f20c42f01293d6a854bf9f7611f384fc6d245c/msmart/command.py#L382

I can help with the fix if you can give me clues on how the values should be parsed. Maybe it should look like the same as indoor_temperature parsing logic?

Screenshots / Logs / Pcap File(屏幕截图/日志/抓包文件) Logs from midea-discover -d (some info redacted)

DEBUG:msmart.scanner:{'_name': None, '_lan_service': <msmart.lan.lan object at 0x102158d00>, '_ip': '--REDACTED for privacy--', '_id': --REDACTED for privacy--, '_port': 6444, '_keep_last_known_online_state': False, '_type': 172, '_updating': False, '_defer_update': False, '_half_temp_step': False, '_support': True, '_online': True, '_active': True, '_protocol_version': 3, '_token': bytearray(--REDACTED for privacy--), '_key': bytearray(--REDACTED for privacy--), '_last_responses': [], '_prompt_tone': False, '_power_state': False, '_target_temperature': 25.0, '_operational_mode': <operational_mode_enum.heat: 4>, '_fan_speed': <fan_speed_enum.Auto: 102>, '_swing_mode': <swing_mode_enum.Off: 0>, '_eco_mode': False, '_turbo_mode': False, 'fahrenheit_unit': False, '_on_timer': {'status': False, 'hour': 31, 'minutes': 3}, '_off_timer': {'status': False, 'hour': 31, 'minutes': 3}, '_indoor_temperature': 22.0, '_outdoor_temperature': 102.5}

Indoor temperature is correct, outdoor_temperature is not.

Versions (版本信息)

P.S: Appreciate the work you've done on this project, keep it up! :)

gergely-sallai commented 2 years ago

Okay this is probably not a bug in the parsing... I got this data from the device during initial discovery (added index for easier reading):

index:  00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28
data:   c0 00 89 66 7f 7f 00 00 00 00 00 5e ff 0d 00 00 00 00 00 00 00 00 00 01 00 00 00 00 09 e4 22

This shows that the index: 0x0c contains 0xff, so the device itself reported invalid data it seems.... Not sure why.

gergely-sallai commented 2 years ago

Okay, I may have figured it out. It seems when the AC is off the outdoor_temperature sensor returns a static 0xff value. But when it is on, then the outdoor_temperature has a proper value, and the integration can properly read it.

Device A, switched ON:

DEBUG:msmart.scanner:{'_name': None, '_lan_service': <msmart.lan.lan object at 0x108574d00>, '_ip': '-- REDACTED for privacy (device A)-- ', '_id': -- REDACTED for privacy --, '_port': 6444, '_keep_last_known_online_state': False, '_type': 172, '_updating': False, '_defer_update': False, '_half_temp_step': False, '_support': True, '_online': True, '_active': True, '_protocol_version': 3, '_token': "-- REDACTED for privacy --, '_key': -- REDACTED for privacy --, '_last_responses': [], '_prompt_tone': False, '_power_state': True, '_target_temperature': 23.0, '_operational_mode': <operational_mode_enum.fan_only: 5>, '_fan_speed': <fan_speed_enum.Auto: 102>, '_swing_mode': <swing_mode_enum.Both: 15>, '_eco_mode': False, '_turbo_mode': False, 'fahrenheit_unit': False, '_on_timer': {'status': False, 'hour': 31, 'minutes': 3}, '_off_timer': {'status': False, 'hour': 31, 'minutes': 3}, '_indoor_temperature': 22.4, '_outdoor_temperature': 21.5}

'_outdoor_temperature': 21.5

Device B switched OFF:

DEBUG:msmart.scanner:{'_name': None, '_lan_service': <msmart.lan.lan object at 0x1086022e0>, '_ip': '-- REDACTED for privacy (device B)--', '_id': -- REDACTED for privacy --, '_port': 6444, '_keep_last_known_online_state': False, '_type': 172, '_updating': False, '_defer_update': False, '_half_temp_step': False, '_support': True, '_online': True, '_active': True, '_protocol_version': 3, '_token': -- REDACTED for privacy --, '_key': -- REDACTED for privacy --, '_last_responses': [], '_prompt_tone': False, '_power_state': False, '_target_temperature': 24.0, '_operational_mode': <operational_mode_enum.fan_only: 5>, '_fan_speed': <fan_speed_enum.Auto: 102>, '_swing_mode': <swing_mode_enum.Off: 0>, '_eco_mode': False, '_turbo_mode': False, 'fahrenheit_unit': False, '_on_timer': {'status': False, 'hour': 31, 'minutes': 3}, '_off_timer': {'status': False, 'hour': 31, 'minutes': 3}, '_indoor_temperature': 22.4, '_outdoor_temperature': 102.5}

'_outdoor_temperature': 102.5

So I believe this is a hardware limitation. Does anybody know whether it is the same for every device? Or if this is something that can be changed to show outdoor temperature always?

Can we change the label 'bug' to 'enhancement'?

mac-zhou commented 2 years ago

this is related to the model, some models are supported to return to the outdoor temperature under the power off.

gergely-sallai commented 2 years ago

I understand, thanks for your response.

This is definitely not a bug then! As an enhancement, should the plugin try and handle this? Example: when value is 0xFF always return 0xFF and only try and parse when it is different than 0xFF. Is it safe to use the value 0xFF in this case as an "unknown" value?

This would be very similar to what the def indoor_temperature(self): property read does. https://github.com/mac-zhou/midea-msmart/blob/34f20c42f01293d6a854bf9f7611f384fc6d245c/msmart/command.py#L345