teslamate icon indicating copy to clipboard operation
teslamate copied to clipboard

Setting cost per kWh is applied as total, if enteres as ,x instead of 0,x

Open hierro1981 opened this issue 1 year ago • 10 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

What happened?

When setting the cost of a charge using the cost per kWh mode and saving, it revert the selection to Total cost and keep the value as total cost. You need to change again the selection to cost per kWh and save again to let it work correctly.

Expected Behavior

Using cost per kWh work at first try

Steps To Reproduce

Dashboard -> Charges -> Click on cost cell -> Select cost per kWh -> put a value -> save

Relevant log output

-

Screenshots

No response

Additional data

No response

Type of installation

Docker

Version

v1.27.2

hierro1981 avatar May 29 '23 12:05 hierro1981

Is this still happening for you? I can't reproduce it in 1.27.4, when switching to per kWh and saving it calculates and saves the total just fine.

ayonix avatar Nov 17 '23 23:11 ayonix

Yes it still happen with latest version (1.27.4). After selecting a charge for updating the cost, I select price per kWh, insert the price and push save. Then the UI is updated switching to Total cost in the select and keeping the inserted price per kWh as a total price. I then need to change again the select to cost per kWh and push again save, then the UI is updated again with total price in the select and the correct value for the total cost.

hierro1981 avatar Nov 18 '23 14:11 hierro1981

Can you tell me which locale and browser you're using? I might look into it if I can reproduce it.

ayonix avatar Nov 18 '23 16:11 ayonix

Italian and Chrome, tried using both . and , for decimal but the behavior is the same.

hierro1981 avatar Nov 18 '23 18:11 hierro1981

I think the issue could be on the cost.ex (https://github.com/teslamate-org/teslamate/blob/036aa5b8171de13d71e3d2f478b62b1ee105e445/lib/teslamate_web/live/charge_live/cost.ex) on line 56 and 70 when it parse the value. I don't know how to correctly handle it on elixir but a fix (suggested by chatgpt) could be something like this:

{cost_per_kwh, ""} <- Float.parse(cost, decimals: :significant_digits, digit_grouping: [",", "."]) do

{cost_per_minute, ""} <- Float.parse(cost, decimals: :significant_digits, digit_grouping: [",", "."]) do

to consider both char as a decimal separator.

hierro1981 avatar Nov 18 '23 19:11 hierro1981

Could not reproduce, this is just a neat pre-calculation step, cost is added as total cost as expected.

JakobLichterfeld avatar Nov 30 '23 13:11 JakobLichterfeld

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Jan 30 '24 01:01 github-actions[bot]

Hi,

sorry for late response but I managed to capture a video to show the behavior:

https://github.com/teslamate-org/teslamate/assets/8321605/55fba353-723d-4891-9ed3-cc98ccac1bc3

hierro1981 avatar Jan 30 '24 09:01 hierro1981

If you enter '0,10' instead of ',10' it works as expected.

ayonix avatar Jan 30 '24 09:01 ayonix

Yes, I confirm that using '0,10' work. Would be nice to allow skipping the initial 0 work too

hierro1981 avatar Jan 30 '24 09:01 hierro1981