leeyuentuen / polestar_api

Polestar Api - Home Assistant Component
MIT License
112 stars 18 forks source link

As far as I can tell, if you were setting 'native_unit_of_measurement' to the unit returned by the API, then HA would do the conversion / you would not need the conversion code. #72

Closed leeyuentuen closed 5 months ago

leeyuentuen commented 6 months ago
          As far as I can tell, if you were setting 'native_unit_of_measurement' to the unit returned by the API, then HA would do the conversion / you would not need the conversion code.

If I select the (range or Odometer) entity, and then go into settings, then I can change 'Unit of Measurement' from 'KM' to 'Mi', but when I save nothing happens... the same action in the Nest integration allows me to switch units - I think this works as it knows that native unit, so can apply the conversion within HA (rather than within your code).

_Originally posted by @lucky81 in https://github.com/leeyuentuen/polestar_api/issues/8#issuecomment-1879732369_

leeyuentuen commented 5 months ago

@lucky81, this should possible fix the issue: https://github.com/leeyuentuen/polestar_api/commit/31c424a6748e51c4a47a6c9e79cc54a2b72200c5

leeyuentuen commented 5 months ago

see beta 1.5.0

lucky81 commented 5 months ago

Tested. This is working perfectly - I can now switch units to miles (in Metric mode) in the entity settings. Thank you very much.

Note that as reported elsewhere this change has introduced a bug where Odometer does not initially display (the default unit isn't working), but when I set it to miles is works fine.

leeyuentuen commented 5 months ago

i know the issue. i have set the max limit to 1000000. but the meter was over 1m, so that the reason why it isn't showed. i need to set it to a higher limit. but this is a known issue now

carrel-gr commented 5 months ago

Hmmm, I loaded 1.5.0 and I see 3 issues with non-metric. I am getting the odometer "unknown" issue, but you mentioned that above. However, I still see average speed and energy consumption in km, not miles. Energy consumption is not using a native unit, so that one might need special handling. As for average speed, I'm not sure why that didn't convert from meters to miles.

leeyuentuen commented 5 months ago

Hmmm, I loaded 1.5.0 and I see 3 issues with non-metric. I am getting the odometer "unknown" issue, but you mentioned that above. However, I still see average speed and energy consumption in km, not miles. Energy consumption is not using a native unit, so that one might need special handling. As for average speed, I'm not sure why that didn't convert from meters to miles.

kw/100km is not an 'official' unit at the moment, so to have them in miles, i think i need to manual convert them.

but this first mr is to be sure that native unit is working on odometer and on the trip distance. if this work fine, then i can see for the next step

carrel-gr commented 5 months ago

This helps for the average_speed polestar_api_diff.txt

leeyuentuen commented 5 months ago

This helps for the average_speed polestar_api_diff.txt

you can open mr based from dev