ollo69 / ha-smartthinq-sensors

HomeAssistant custom integration for SmartThinQ LG devices configurable with Lovelace User Interface.
Apache License 2.0
1.13k stars 158 forks source link

Error while setting up smartthinq_washer platform for sensor #1

Closed boralyl closed 4 years ago

boralyl commented 4 years ago

Using integrations, I created a new one and entered the default values for country (US) and locale en-US and provided my access token. It created the integration w/o any issues but no devices were added. Here is the error from my logs:

Logger: homeassistant.components.sensor
Source: custom_components/smartthinq_washer/wideq.py:826
Integration: Sensor (documentation, issues)
First occurred: 8:21:38 PM (1 occurrences)
Last logged: 8:21:38 PM

Error while setting up smartthinq_washer platform for sensor

ValueError: 202 is not a valid DeviceType

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 179, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/config/custom_components/smartthinq_washer/sensor.py", line 462, in async_setup_entry
    if device.type == DeviceType.WASHER:
  File "/config/custom_components/smartthinq_washer/wideq.py", line 826, in type
    return DeviceType(self.data['deviceType'])
  File "/usr/local/lib/python3.7/enum.py", line 310, in __call__
    return cls.__new__(cls, value)
  File "/usr/local/lib/python3.7/enum.py", line 564, in __new__
    raise exc
  File "/usr/local/lib/python3.7/enum.py", line 548, in __new__
    result = cls._missing_(value)
  File "/usr/local/lib/python3.7/enum.py", line 577, in _missing_
    raise ValueError("%r is not a valid %s" % (value, cls.__name__))
ValueError: 202 is not a valid DeviceType

This was on HA 0.107.6

ollo69 commented 4 years ago

Hi,

SmartThinQ accounts are associated with a specific locale, so be sure to use the country you originally created your account with. Was your LG account created in US? Can you also provide me more info about devices model owned by you and registered in your ThinQ account?

Thanks.

towerhand commented 4 years ago

First of all, thank you for working on this.

I'm getting the same error.

Added the repo to HACS as custom repo, installed it, added the new integration and followed the steps to create a new token.

US and en-US. Model: WM9000HVA

2020-03-26 10:31:26 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up smartthinq_washer platform for sensor
ValueError: 202 is not a valid DeviceType

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 179, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/config/custom_components/smartthinq_washer/sensor.py", line 462, in async_setup_entry
    if device.type == DeviceType.WASHER:
  File "/config/custom_components/smartthinq_washer/wideq.py", line 826, in type
    return DeviceType(self.data['deviceType'])
  File "/usr/local/lib/python3.7/enum.py", line 310, in __call__
    return cls.__new__(cls, value)
  File "/usr/local/lib/python3.7/enum.py", line 564, in __new__
    raise exc
  File "/usr/local/lib/python3.7/enum.py", line 548, in __new__
    result = cls._missing_(value)
  File "/usr/local/lib/python3.7/enum.py", line 577, in _missing_
    raise ValueError("%r is not a valid %s" % (value, cls.__name__))
ValueError: 202 is not a valid DeviceType
ollo69 commented 4 years ago

Please if someone have a working customized version, attach the code to the issue as zip file so that I can compare the code and try to solve it. Problem is that SmartThinQ is different for every country.

boralyl commented 4 years ago

It looks like it's pulling down all devices, even non-washers. 202 refers to a dryer. Here is my wideq.py: https://gist.github.com/boralyl/511a8d669c58331f29b04058214945f6#file-wideq-py-L1556

And my 2 devices from the wideq example.py (with some sensitive info removed)

[{'alias': 'WASHER',
  'appModuleSize': 5328198,
  'appModuleUri': 'https://aic.lgthinq.com:46030/api/webContents/moduleDownload?type=appModule/GWM/DW1207234929121857&fileName=GWM_v_4_8_rev22004.zip&authKey=thinq',
  'appModuleVer': 4.8,
  'appRestartYn': 'Y',
  'curOffset': -4,
  'curOffsetDisplay': '-04:00',
  'deviceCode': 'LA02',
  'deviceId': '---',
  'deviceState': 'D',
  'deviceType': 201,
  'dstOffset': -4,
  'dstOffsetDisplay': '-04:00',
  'fwVer': 'QC_Modem_1.2.79',
  'imageUrl': 'https://aic.lgthinq.com:46030/api/webContents/imageDownload?type=modelType&image=home_appliances_img_wmdrum.png',
  'langPackModelUri': 'https://aic.lgthinq.com:46030/api/webContents/moduleDownload?type=langPack/MP/F3L2CYV5W_WIFI/MP_WM_F3L2CYV5W_WIFI_LANG_WW-WW_VER_1.0_NUTS.json&fileName=MP_WM_F3L2CYV5W_WIFI_LANG_WW-WW_VER_1.0_NUTS&authKey=thinq',
  'langPackModelVer': 1,
  'langPackProductTypeUri': 'https://aic.lgthinq.com:46030/api/webContents/moduleDownload?type=langPack/PP/201/PP_WM_LANG_EN-US_VER_50.3_NUTS.json&fileName=PP_WM_LANG_EN-US_VER_50.3_NUTS&authKey=thinq',
  'langPackProductTypeVer': 50.3,
  'macAddress': '---',
  'modelJsonUrl': 'https://aic.lgthinq.com:46030/api/webContents/modelJSON?modelName=F3L2CYV5W_WIFI&countryCode=WW&contentsId=JS1217232703654216&authKey=thinq',
  'modelJsonVer': 3.3,
  'modelNm': 'F3L2CYV5W_WIFI',
  'networkType': '02',
  'newRegYn': 'N',
  'regDt': 20190520152328,
  'regDtUtc': 20190520192328,
  'remoteControlType': '',
  'sdsGuide': '{"deviceCode":"LA02"}',
  'smallImageUrl': 'https://aic.lgthinq.com:46030/api/webContents/imageDownload?type=modelType/Small&image=home_appliances_img_wmdrum.png',
  'ssid': '---',
  'ssidPass': '',
  'subModelNm': '',
  'timezoneCode': 'America/New_York',
  'timezoneCodeAlias': 'USA/New_York',
  'utcOffset': -5,
  'utcOffsetDisplay': '-05:00',
  'workId': ''},
 {'alias': 'DRYER',
  'appModuleSize': 5328198,
  'appModuleUri': 'https://aic.lgthinq.com:46030/api/webContents/moduleDownload?type=appModule/GWM/DW1207235027336537&fileName=GWM_v_4_8_rev22004.zip&authKey=thinq',
  'appModuleVer': 4.8,
  'appRestartYn': 'Y',
  'curOffset': -4,
  'curOffsetDisplay': '-04:00',
  'deviceCode': 'LA03',
  'deviceId': '---',
  'deviceState': 'E',
  'deviceType': 202,
  'dstOffset': -4,
  'dstOffsetDisplay': '-04:00',
  'fwVer': 'QC_Modem_1.2.79',
  'imageUrl': 'https://aic.lgthinq.com:46030/api/webContents/imageDownload?type=modelType&image=home_appliances_img_wmdrum.png',
  'langPackModelUri': 'https://aic.lgthinq.com:46030/api/webContents/moduleDownload?type=langPack/MP/RV13B6ES_D_US_WIFI/MP_DR_RV13B6ES_D_US_WIFI_LANG_WW-WW_VER_1.3_NUTS.json&fileName=MP_DR_RV13B6ES_D_US_WIFI_LANG_WW-WW_VER_1.3_NUTS&authKey=thinq',
  'langPackModelVer': 1.3,
  'langPackProductTypeUri': 'https://aic.lgthinq.com:46030/api/webContents/moduleDownload?type=langPack/PP/201/PP_WM_LANG_EN-US_VER_50.3_NUTS.json&fileName=PP_WM_LANG_EN-US_VER_50.3_NUTS&authKey=thinq',
  'langPackProductTypeVer': 50.3,
  'macAddress': '',
  'modelJsonUrl': 'https://aic.lgthinq.com:46030/api/webContents/modelJSON?modelName=RV13B6ES_D_US_WIFI&countryCode=WW&contentsId=JS1126002523643729&authKey=thinq',
  'modelJsonVer': 3.5,
  'modelNm': 'RV13B6ES_D_US_WIFI',
  'networkType': '02',
  'newRegYn': 'N',
  'regDt': 20190521195340,
  'regDtUtc': 20190521235340,
  'remoteControlType': '',
  'sdsGuide': '{"deviceCode":"LA03"}',
  'smallImageUrl': 'https://aic.lgthinq.com:46030/api/webContents/imageDownload?type=modelType/Small&image=home_appliances_img_wmdrum.png',
  'ssid': '---',
  'ssidPass': '',
  'subModelNm': '',
  'timezoneCode': 'America/New_York',
  'timezoneCodeAlias': 'USA/New_York',
  'utcOffset': -5,
  'utcOffsetDisplay': '-05:00',
  'workId': ''}]
ollo69 commented 4 years ago

Ok,

it's normal that wideq extract all devices registered, anyway solve this issue seems to be simple, I just update the Class "DeviceType" merging with yours that have complete list. Obviosly (at least for the moment) I only manage washer and other device will not be added.

I alaredy updated the code, let me know.

P.S. To simplify installation if you want you can add this repository to HACS, it should work.

towerhand commented 4 years ago

Thanks for the quick fix. The washer is added and no errors in the logs so far. Will do more testing in the coming days and report any issues.

towerhand commented 4 years ago

Now I'm getting a lot of this error:

2020-03-26 13:33:48 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 284, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 327, in _async_write_ha_state
    attr.update(self.state_attributes or {})
  File "/config/custom_components/smartthinq_washer/sensor.py", line 130, in state_attributes
    data[ATTR_CURRENT_COURSE] = self.current_course
  File "/config/custom_components/smartthinq_washer/sensor.py", line 237, in current_course
    course = self._state.current_course
  File "/config/custom_components/smartthinq_washer/wideq.py", line 1257, in current_course
    course = self.lookup_reference('Course')
  File "/config/custom_components/smartthinq_washer/wideq.py", line 1207, in lookup_reference
    return self.washer.model.reference_name(key, self.data[key])
KeyError: 'Course'

Please let me know if you would like me to open a new issue.

boralyl commented 4 years ago

The above is one of the annoying things about the different washers. I had to add this to resolve that: https://gist.github.com/boralyl/511a8d669c58331f29b04058214945f6#file-wideq-py-L3428-L3437

But you will run into a bunch of those. I just kept monitoring it and updating code until it worked for my specific washer. Not sure how to make it work with every washer.

ollo69 commented 4 years ago

I think that some model have "Course" and other "APCourse". I try to put a fix, I will inform you shortly....

towerhand commented 4 years ago

Awesome. I'm not a developer so I can't help much but with the quarantine I have plenty of time to test and report back.

ollo69 commented 4 years ago

I make a fix, can you try now?

towerhand commented 4 years ago

The 'course' error seems to be gone. Now getting this error:

2020-03-26 15:19:52 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
ValueError: '@WM_OPTION_SPIN_HIGH_W' is not a valid WASHERSPINSPEED

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 284, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 327, in _async_write_ha_state
    attr.update(self.state_attributes or {})
  File "/config/custom_components/smartthinq_washer/sensor.py", line 136, in state_attributes
    data[ATTR_SPIN_OPTION_STATE] = self.spin_option_state
  File "/config/custom_components/smartthinq_washer/sensor.py", line 276, in spin_option_state
    spin_option = self._state.spin_option_state
  File "/config/custom_components/smartthinq_washer/wideq.py", line 1292, in spin_option_state
    return WASHERSPINSPEED(spinspeed)
  File "/usr/local/lib/python3.7/enum.py", line 310, in __call__
    return cls.__new__(cls, value)
  File "/usr/local/lib/python3.7/enum.py", line 564, in __new__
    raise exc
  File "/usr/local/lib/python3.7/enum.py", line 548, in __new__
    result = cls._missing_(value)
  File "/usr/local/lib/python3.7/enum.py", line 577, in _missing_
    raise ValueError("%r is not a valid %s" % (value, cls.__name__))
ValueError: '@WM_OPTION_SPIN_HIGH_W' is not a valid WASHERSPINSPEED
boralyl commented 4 years ago

I don't have any need to run the washer, but it worked for me on adding it and reports off and on correctly at the moment. Next time I run it, I'll let you know if I get any other errors.

boralyl commented 4 years ago

Not sure if this helpful, but from me using my custom component for the last year most of those attributes aren't useful. The only attributes I care about are the state and time remaining. It might make it easier to limit the reported attributes. Just a suggestion, or course.

ollo69 commented 4 years ago

For sure mapping all possible state for all devices is a huge work. I will review a little bit the code to try to avoid errors and return something like "Unknown" when not managed. May be I can write unknown state on some file so that they can be managed id the future.

Let me think about this a little more, I come back when ready.

towerhand commented 4 years ago

Great job with this custom component so far, finally an user friendly ThinQ component.

ollo69 commented 4 years ago

I released a new version that should avoid exception with unknows states. You should see a warnibg in the log when an unknown state is detected. I also added the file "widew_states,py" that should help in adding states from different devices, if possible sending a PR.

Wait for your feedbacks

boralyl commented 4 years ago

Still working well for me (although haven't run the washer since updating)

towerhand commented 4 years ago

Great, updated and turned the washer on just to see what errors show up (we'll be doing laundry on Sunday)

These are the errors so far:

2020-03-27 11:11:45 WARNING (MainThread) [custom_components.smartthinq_washer.wideq] Wideq: received unknown status '@WM_OPTION_SPIN_MEDIUM_W' of type 'spin_option'
2020-03-27 11:11:45 WARNING (MainThread) [custom_components.smartthinq_washer.wideq] Wideq: received unknown status '@WM_OPTION_TEMP_COLD_W' of type 'water_temp'
2020-03-27 11:12:13 WARNING (MainThread) [custom_components.smartthinq_washer.wideq] Wideq: received unknown status '@WM_OPTION_SPIN_HIGH_W' of type 'spin_option'
2020-03-27 11:12:13 WARNING (MainThread) [custom_components.smartthinq_washer.wideq] Wideq: received unknown status '@WM_OPTION_TEMP_WARM_W' of type 'water_temp'
ollo69 commented 4 years ago

That's what was expected, very well. Collect all possible message of this type and report here, than I will add these states for you with next release.

towerhand commented 4 years ago

Ok, I went through the each of the settings and the missing states are:

For 'spin_option': '@WM_OPTION_SPIN_NO_SPIN_W' '@WM_OPTION_SPIN_LOW_W' '@WM_OPTION_SPIN_MEDIUM_W' '@WM_OPTION_SPIN_HIGH_W' '@WM_OPTION_SPIN_EXTRA_HIGH_W'

For 'water_temp': '@WM_OPTION_TEMP_TAP_COLD_W' '@WM_OPTION_TEMP_COLD_W' '@WM_OPTION_TEMP_WARM_W' '@WM_OPTION_TEMP_HOT_W' '@WM_OPTION_TEMP_EXTRA_HOT_W'

ollo69 commented 4 years ago

Have idea of what can be description for '@WM_OPTION_TEMP_TAP_COLD_W'?

towerhand commented 4 years ago

Found these two comments online comparing the cold and tap cold settings. Not sure how long of a description you are thinking about and hopefully this helps.


The “tap cold” setting uses cold water as it comes out of the tap. In cold climates, or in places where your cold water supply is deeply buried, this could be 50F or colder.

The “cold” setting mixes in hot water to reach a standard temperature. Different washer brands mix to different temperatures, I’ve seen references of from 70F to 83F.


"Tap Cold" is straight cold water from your main, it can be soothingly cold in the summer or it can be just above freezing in the winter, if you pick "Cold" or any other setting your washing machine will keep the water temperature within a set range, and that range I have no idea because it depends on your machine, but basically if you put it on "Cold" it will do whatever it has to in order to keep the water at, let's say, 10-15 degrees C for example, so if it drops to 8 degrees, it will add some warm water to bring it back up, "Tap Cold" will just let the water stay at whatever temperature it is coming out of your main at.

ollo69 commented 4 years ago

Just thinking was an abbreviation. I will use "Tap Cold"

towerhand commented 4 years ago

Ah ok. Yes, tap cold is right.

ollo69 commented 4 years ago

Added your states.

towerhand commented 4 years ago

Awesome, thank you very much. I’ll test in a bit.

Edit: tested and no errors anymore. Will do more testing when we do laundry on Sunday.

towerhand commented 4 years ago

So far I have only seen this warning one time:

2020-03-27 21:20:41 WARNING (SyncWorker_5) [custom_components.smartthinq_washer.sensor] Generic Wideq Error. Exiting.

Other than. that, we ran the washer this morning and every worked perfectly. Thank you.

ollo69 commented 4 years ago

Not real issue. Sometime connection close, also due to internet availability. This error is managed, and connection is automatically re-opened.

towerhand commented 4 years ago

No errors showed up after doing a few loads of laundry today. I did notice it was showing “steam” as on when it was off (turbo mode was actually on) so some of the mappings might be wrong due to difference between washers, not a big deal at all just reporting my findings.

Great job. I have a dryer too if you need some testing done in the future.

ollo69 commented 4 years ago

Yes, there are some bit control that change depending on the model, will be not so simple to map all correctly. Please send a picture of your model info from the device page like this:

image

For the dryer, as soon I will have some time. Unfortunatly I don't have one so I will need a lot of support to test.

Ciao.

towerhand commented 4 years ago

9C242D9B-82A0-4DBC-9599-A325161C5CC3

boralyl commented 4 years ago

This has been resolved, thanks!