teslamate
teslamate copied to clipboard
Setting cost per kWh is applied as total, if enteres as ,x instead of 0,x
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
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.
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.
Can you tell me which locale and browser you're using? I might look into it if I can reproduce it.
Italian and Chrome, tried using both . and , for decimal but the behavior is the same.
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.
Could not reproduce, this is just a neat pre-calculation step, cost is added as total cost as expected.
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.
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
If you enter '0,10' instead of ',10' it works as expected.
Yes, I confirm that using '0,10' work. Would be nice to allow skipping the initial 0 work too