leeyuentuen / polestar_api

Polestar Api - Home Assistant Component
MIT License
131 stars 23 forks source link

Range in Miles as well as KM #8

Closed nthbooth closed 9 months ago

nthbooth commented 10 months ago

It would be lovely if the range was available in Miles as an option rather than KM.

Also thank you this plugin is awesome!

leeyuentuen commented 10 months ago

can you take a look at this beta version if miles works correctly? https://github.com/leeyuentuen/polestar_api/releases/tag/0.2.1

leeyuentuen commented 10 months ago

@nthbooth can you take a look the version above?

nthbooth commented 10 months ago

looks good thankyou

lucky81 commented 9 months ago

Did this make it into 1.4.0? I see a selectable 'unit_of_measurement' including 'mi', but changing it does not do anything... are we missing 'native_unit_of_measurement' or 'device_class' etc. required for HA to be able to convert?

leeyuentuen commented 9 months ago

you need to take a look at this page: https://polestarid.eu.polestar.com/as/authorization.oauth2?response_type=code&client_id=polmystar&redirect_uri=https%3A%2F%2Fwww.polestar.com%2Fsign-in-callback&scope=openid%20profile%20email%20customer:attributes%20customer:attributes:write

and then go to cars, and see what there their value of. the KM/Miles, could be that polestar didn't update the value from the car

edit: i'm wrong, the value will change normally if you change your system settings from metric to imperial

lucky81 commented 9 months ago

Hi, I checked the Polestar page and it is correctly in Miles for range and Odometer. The only options I see in the HA Settings are Metric (Celsius, kilograms) or US Customary (Fahrenheit, pounds)... what I am looking for is Celsius and Miles which is mostly the norm in the UK. If the API is returning it in miles is there no way for this integration to override it? For example with the Nest integration when I change 'unit_of_measurement' for the entity I can switch between Celsius and Fahrenheit.

leeyuentuen commented 9 months ago

the code check if it is us customary (included miles) it will convert the km into miles

lucky81 commented 9 months ago

Which would suit most countries/people, but the UK is a bit of a confused mixture of metric and imperial. I am set to metric which is good for everything else (Celsius, kg) except for distance which should be miles. Is there no other way to prevent that conversion / override it - like the way the Nest integration just lets me choose?

leeyuentuen commented 9 months ago

maybe rollback as before from this issue?

https://github.com/leeyuentuen/polestar_api/issues/49

lucky81 commented 9 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).

leeyuentuen commented 9 months ago

i have open an issue, i'll take a look on it

lucky81 commented 9 months ago

Thank you so much.