dan-r / HomeAssistant-Ohme

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

Error message when trying to change target percentage #88

Open kmorrow429 opened 1 month ago

kmorrow429 commented 1 month ago

What happened? When trying to change the target percentage while the car is connected, I get an error message. I don't get the error message if the car is not connected, however the changes do not get applied in the Ohme app

Log Output Screenshot attached

Home Assistant Version 2024.8.1

Integration Version 1.0.0

Screenshot_20240815-223036

richbishop commented 1 week ago

Also getting the same issue.

No matter what I try as a value in YAML inside HA - it seems to always be pushed to the API as a string, which it rejects

AlasdairH commented 6 days ago

Having the same issue. One workaound I found is to set a preconditioning time, as that being missing sems to be what is tripping up the request. Obviously not a great solution though.

richbishop commented 5 days ago

It seems to be caused by this line https://github.com/dan-r/HomeAssistant-Ohme/blob/7bd0d37abca73a075a709fc2cf3daaedbe78742b/custom_components/ohme/api_client.py#L267

As @AlasdairH says, it's needs a precondition value to work, if not it's still None and that gets converted into a string and sent in the query string, which means the whole request is then rejected by the API.

dan-r commented 3 days ago

Apologies all, had a busy few weeks, I'll aim to look at this in the next couple of days

dan-r commented 2 days ago

Are you able to send the full error message from the logs?

richbishop commented 2 days ago

I've monkey patched the code on my install now to work around it, and selfishly don't want to break it again to generate the error 😬 Sorry!

But if you have a look at the original post in this issue, that's the error message.

The Ohme API is saying it can't convert the string "None" into an int, which it needs for the preconditioning length. Python is treating it as a None, but is converting that to a string when it gets added to the querystring on the API call.

I don't know python well enough, or I would have suggested an MR for it. But I believe, you'll need to catch the "None" and replace it with an int (0 is working for me) when setting a new rule.

(also apologies, I got the line reference wrong in my previous comment. It should have been: https://github.com/dan-r/HomeAssistant-Ohme/blob/7bd0d37abca73a075a709fc2cf3daaedbe78742b/custom_components/ohme/api_client.py#L215 )

My monkey patched workaround (starting at line 214) looks like this:

        if pre_condition_length is None:
#            pre_condition_length = self._last_rule[
#                'preconditionLengthMins'] if 'preconditionLengthMins' in self._last_rule else 30
             pre_condition_length = 0

I'm guessing it's only causing an issue for users where their car doesn't support preconditioning with Ohme - as mine doesn't.

Hope that helps?