sampsyo / hass-smartthinq

Home Assistant component for LG SmartThinQ HVAC devices
MIT License
282 stars 98 forks source link

Energy Saver Mode is not a valid ACMode #15

Open bifurcated opened 5 years ago

bifurcated commented 5 years ago

I just set up SmartThinQ on HomeAssistant, and was having trouble seeing the entity. After some fiddling around, I realized that it was because my AC unit was set to Energy Saver/Eco mode, and hass-smartthinq didn't like it. I changed the mode to "cool" and was able to add the entity.

Here's the homeassistant log from when my AC unit was in Energy Saver mode:

2019-05-25 15:16:16 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved ValueError: '@AC_MAIN_OPERATION_MODE_ENERGY_SAVER_W' is not a valid ACMode

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/src/app/homeassistant/helpers/entity.py", line 225, in async_update_ha_state self._async_write_ha_state() File "/usr/src/app/homeassistant/helpers/entity.py", line 248, in _async_write_ha_state state = self.state File "/usr/src/app/homeassistant/components/climate/init.py", line 192, in state if self.current_operation: File "/config/custom_components/smartthinq/climate.py", line 161, in current_operation mode = self._state.mode File "/config/deps/lib/python3.7/site-packages/wideq.py", line 1028, in mode return ACMode(self.lookup_enum('OpMode')) 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: '@AC_MAIN_OPERATION_MODE_ENERGY_SAVER_W' is not a valid ACMode 2019-05-25 15:18:44 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.140432664712304] '@AC_MAIN_OPERATION_MODE_ENERGY_SAVING_W'

When trying to set the operation mode to "Eco" (which appears as a valid operation mode in the HA dropdown) via HA, this is the error I received:

Traceback (most recent call last): File "/usr/src/app/homeassistant/components/websocket_api/commands.py", line 121, in handle_call_service connection.context(msg)) File "/usr/src/app/homeassistant/core.py", line 1141, in async_call self._execute_service(handler, service_call)) File "/usr/src/app/homeassistant/core.py", line 1163, in _execute_service await handler.func(service_call) File "/usr/src/app/homeassistant/helpers/entity_component.py", line 194, in handle_service required_features File "/usr/src/app/homeassistant/helpers/service.py", line 316, in entity_service_call future.result() # pop exception if have File "/usr/src/app/homeassistant/helpers/service.py", line 337, in _handle_service_platform_call await getattr(entity, func)(*data) File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run result = self.fn(self.args, **self.kwargs) File "/config/custom_components/smartthinq/climate.py", line 181, in set_operation_mode self._ac.set_mode(mode) File "/config/deps/lib/python3.7/site-packages/wideq.py", line 914, in set_mode mode_value = self.model.enum_value('OpMode', mode.value) File "/config/deps/lib/python3.7/site-packages/wideq.py", line 688, in enum_value return options_inv[name] KeyError: '@AC_MAIN_OPERATION_MODE_ENERGY_SAVING_W'

sampsyo commented 5 years ago

Huh; that's really strange! I don't have a great answer for why this would happen on your system. For the first error, that error indicates that the given key isn't in the ACMode enum that I wrote. But at least here on my machine, it really does seem to be present:

>>> import wideq
>>> wideq.ACMode
<enum 'ACMode'>
>>> wideq.ACMode('@AC_MAIN_OPERATION_MODE_ENERGY_SAVING_W')
<ACMode.ENERGY_SAVING: '@AC_MAIN_OPERATION_MODE_ENERGY_SAVING_W'>

In contrast, this is what an invalid key does:

>>> wideq.ACMode('foo')
ValueError: 'foo' is not a valid ACMode
[...]

Any chance you have a modified or out-of-date version of the library?

bifurcated commented 5 years ago

I wouldn't rule out user malfunction on my end.

I installed hass-smartthinq today from this git repository, so it should be up to date. I'm referencing wideq this way in climate.py:

REQUIREMENTS = ['https://github.com/sampsyo/wideq/archive/master.zip#wide1==0.0.1']. Maybe that's the issue?

sampsyo commented 5 years ago

Yeah, it's possible—can you attempt with the latest version on master? Otherwise, I'm not exactly sure—I wish I had a way to reproduce the problem locally…

bifurcated commented 5 years ago

I changed climate.py to REQUIREMENTS = ['wideq']

I have what I think is the latest version of wideq in ~ha/deps/lib/python3.7/site-packages/, and no joy. When I try to set "Eco", I get this error:

2019-05-25 16:39:11 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.140005121156264] '@AC_MAIN_OPERATION_MODE_ENERGY_SAVING_W' Traceback (most recent call last): File "/usr/src/app/homeassistant/components/websocket_api/commands.py", line 121, in handle_call_service connection.context(msg)) File "/usr/src/app/homeassistant/core.py", line 1141, in async_call self._execute_service(handler, service_call)) File "/usr/src/app/homeassistant/core.py", line 1163, in _execute_service await handler.func(service_call) File "/usr/src/app/homeassistant/helpers/entity_component.py", line 194, in handle_service required_features File "/usr/src/app/homeassistant/helpers/service.py", line 316, in entity_service_call future.result() # pop exception if have File "/usr/src/app/homeassistant/helpers/service.py", line 337, in _handle_service_platform_call await getattr(entity, func)(*data) File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run result = self.fn(self.args, **self.kwargs) File "/config/custom_components/smartthinq/climate.py", line 181, in set_operation_mode self._ac.set_mode(mode) File "/config/deps/lib/python3.7/site-packages/wideq.py", line 914, in set_mode mode_value = self.model.enum_value('OpMode', mode.value) File "/config/deps/lib/python3.7/site-packages/wideq.py", line 688, in enum_value return options_inv[name] KeyError: '@AC_MAIN_OPERATION_MODE_ENERGY_SAVING_W'

sampsyo commented 5 years ago

Hmm. That latter issue might be explained by the LG servers not reporting this as a valid setting, but that doesn't quite align with the fact that you were able to set it to "Eco" manually.

Sorry I'm mystified here! One annoying thing about this project is that the API has zero documentation, so I reverse-engineered it based on how my own AC model works. I tried to make reasonable guesses about how more general models might also work, but gaps like this are really hard to resolve without access to the actual hardware. :confused:

bifurcated commented 5 years ago

I apologize, I may not have been clear about "Eco" manual settings and results. When I tried to add the LG entity in HA the first time, the unit was already set to "Energy Saver" mode (which is how my manual refers to it), and the entity didn't appear. I set it to "Cool" and all was well.

When I then tried to change the unit to "Eco", which is what appears in the HA entity interface, I got an error. It does seem that LG sees "Eco" as "Energy Saver", but there's some kind of problem somewhere.

Ah, well. It's cool that it works at all!

jsmath commented 5 years ago

I am getting the same error message when trying to set the mode to "Eco". How can I figure out what this should be for my AC?

'@AC_MAIN_OPERATION_MODE_ENERGY_SAVING_W' Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 121, in handle_call_service connection.context(msg)) File "/usr/src/homeassistant/homeassistant/core.py", line 1150, in async_call self._execute_service(handler, service_call)) File "/usr/src/homeassistant/homeassistant/core.py", line 1172, in _execute_service await handler.func(service_call) File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 194, in handle_service required_features File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 316, in entity_service_call future.result() # pop exception if have File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 337, in _handle_service_platform_call await getattr(entity, func)(*data) File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run result = self.fn(self.args, **self.kwargs) File "/config/custom_components/smartthinq/climate.py", line 209, in set_operation_mode self._ac.set_mode(mode) File "/usr/local/lib/python3.7/site-packages/wideq/ac.py", line 137, in set_mode mode_value = self.model.enum_value('OpMode', mode.value) File "/usr/local/lib/python3.7/site-packages/wideq/client.py", line 346, in enum_value return options_inv[name] KeyError: '@AC_MAIN_OPERATION_MODE_ENERGY_SAVING_W'

gulfy32 commented 4 years ago

I am getting the same error too. I turned on debug logging and this is what it says.

`2019-07-19 15:08:14 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] Received {'type': 'call_service', 'domain': 'climate', 'service': 'set_operation_mode', 'service_data': {'operation_mode': '$ 2019-07-19 15:08:14 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=climate, service=set_operation_mode, service_data=operation_mode=eco, entity_id=climate.air_conditioner> 2019-07-19 15:08:14 INFO (SyncWorker_3) [custom_components.smartthinq.climate] Setting mode to ACMode.ENERGY_SAVING... 2019-07-19 15:08:14 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] '@AC_MAIN_OPERATION_MODE_ENERGY_SAVING_W'

KeyError: '@AC_MAIN_OPERATION_MODE_ENERGY_SAVING_W'`

jsmath commented 4 years ago

It looks a new energy saver mode was added to wideq (ENERGY_SAVER = "@AC_MAIN_OPERATION_MODE_ENERGY_SAVER_W", https://github.com/sampsyo/wideq/pull/32), but I'm unsure how to pull in this change.

I am running hass.io. I think I have modified my climate.py file to use the latest wideq by changing the "REQUIREMENTS" to the line below as mentioned here https://github.com/sampsyo/hass-smartthinq/issues/9: REQUIREMENTS = ["https://github.com/sampsyo/wideq/archive/master.zip#wide1==0.0.1"]

I'm not sure if this actually grabs the latest wideq. I have also tried cloning the repo and releasing my own version to pull down, but I'm not sure it is even grabbing the latest when I do this. Does anyone have advice on how to do this?

Note: I also tried to modify climate.py to comment-out 'ENERGY_SAVING' and use 'ENERGY_SAVER' instead as shown below:

'ENERGY_SAVING: c_const.STATE_ECO,

'ENERGY_SAVER': c_const.STATE_ECO,

sampsyo commented 4 years ago

I have now published v1.0.3, which includes this change, to PyPI.