dan-r / HomeAssistant-Ohme

Unofficial Home Assistant integration for interacting with Ohme EV chargers (EVSE) 🚗⚡️
MIT License
33 stars 9 forks source link

Number/time controls don't work #78

Open nyordanov opened 3 weeks ago

nyordanov commented 3 weeks ago

What happened?

Changing the Target Percentage, Target Time, or Preconditioning results in this TypeError

To Reproduce

Drag the Target Percentage range input:

Error message:

Log Output

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 239, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2543, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2580, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 971, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1043, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/number/__init__.py", line 112, in async_set_value
    await entity.async_set_native_value(native_value)
  File "/config/custom_components/ohme/number.py", line 76, in async_set_native_value
    await self._client.async_apply_session_rule(target_percent=int(value))
  File "/config/custom_components/ohme/api_client.py", line 203, in async_apply_session_rule
    max_price = self._last_rule['settings'][0]['enabled'] if 'settings' in self._last_rule and len(
                                                                                               ^^^^
TypeError: object of type 'NoneType' has no len()

Home Assistant Version

Core 2024.4.3 Supervisor 2024.04.0 Operating System 12.2 Frontend 20240404.2

Integration Version

0.8.2

dan-r commented 3 weeks ago

Interesting - was there a car plugged in when you saw this?

nyordanov commented 3 weeks ago

Yes

dan-r commented 2 weeks ago

I haven't been able to replicate this, do you have any more details you can share? Any errors in the logs beforehand? Any general network issues?

nyordanov commented 2 weeks ago

I have this other TypeError in the logs, no idea if it's related to the above and I can't reproduce it on demand like the other error:

[homeassistant.components.switch] ohme: Error on device update!
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 707, in _async_add_entity
await entity.async_device_update(warning=False)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1293, in async_device_update
await self.async_update()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 530, in async_update
await self.coordinator.async_request_refresh()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 265, in async_request_refresh
await self._debounced_refresh.async_call()
File "/usr/src/homeassistant/homeassistant/helpers/debounce.py", line 117, in async_call
await task
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 291, in async_refresh
await self._async_refresh(log_failures=True)
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 414, in _async_refresh
self.async_update_listeners()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 168, in async_update_listeners
update_callback()
File "/config/custom_components/ohme/number.py", line 255, in _handle_coordinator_update
self._state = self.coordinator.data["userSettings"]["chargeSettings"][0]["value"]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
TypeError: 'NoneType' object is not subscriptable

Other than that, all I can say is that the error on api_client.py line 203 happens every time the car is plugged in and I try to change a number or time control. But, weirdly, all these controls work just fine if the car isn't plugged in.

For example, I can change the target time from 7:00 to 7:30 with the car unplugged, and it will have stored this value next time I plug the car in. I can also change the target percentage, etc. But I get a TypeError and the value doesn't change if the car is plugged in.

I tried disabling the VW API integration since it mostly doesn't work - didn't make any difference.

I also don't have a tariff selected in the Ohme app as my tariff isn't listed.

dan-r commented 1 week ago

@nyordanov think I've figured it out. Would you mind trying out v0.8.3-beta.3? (beta instructions)

nyordanov commented 1 week ago

Works for me now.

Weirdly, the approve charge button didn't work when I tried it (was able to approve it in the Ohme app), but looking at the code I can't see how that could be related. I'll try again next time.

Thanks a lot. With this change I can now have two automations:

  1. Auto approvals based on car location (if the button works, that is)
  2. Automatically set target percentage based on car SoC and avoid Ohme's flaky integration with VW's API (e.g., add 25% instead of relying on charge from 55% to 80%)
Begie1605 commented 2 days ago

Had the same problem, and with beta release it works now....