Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

French translation updated #65

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions custom_components/polestar_api/polestar.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from homeassistant.core import HomeAssistant
from homeassistant.util.unit_system import METRIC_SYSTEM, UnitSystem

from .pypolestar.exception import PolestarApiException, PolestarAuthException
from .pypolestar.polestar import PolestarApi

Expand Down
18 changes: 12 additions & 6 deletions custom_components/polestar_api/pypolestar/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class PolestarAuth:
"""base class for Polestar authentication."""

def __init__(self, username: str, password: str) -> None:
"""Initialize the Polestar authentication."""
self.username = username
self.password = password
self.access_token = None
Expand All @@ -23,7 +24,7 @@ def __init__(self, username: str, password: str) -> None:
self._client_session = httpx.AsyncClient()

async def get_token(self, refresh=False) -> None:
# get access / refresh token
"""Get the token from Polestar."""
headers = {"Content-Type": "application/json"}
operationName = "getAuthToken"
if not refresh:
Expand Down Expand Up @@ -51,6 +52,7 @@ async def get_token(self, refresh=False) -> None:
self.latest_call_code = result.status_code
resultData = result.json()
if result.status_code != 200 or ("errors" in resultData and len(resultData["errors"])):
_LOGGER.error(result)
raise PolestarAuthException("Error getting token", result.status_code)
_LOGGER.debug(resultData)

Expand All @@ -68,7 +70,7 @@ async def _get_code(self) -> None:

# check if code is in query_params
if query_params.get('code'):
return query_params.get('code')[0]
return query_params.get('code')

# get the resumePath
if query_params.get('resumePath'):
Expand Down Expand Up @@ -102,6 +104,7 @@ async def _get_code(self) -> None:
self.latest_call_code = result.status_code

if result.status_code != 200:
_LOGGER.error(result)
raise PolestarAuthException("Error getting code callback", result.status_code)

# url encode the code
Expand All @@ -111,13 +114,16 @@ async def _get_code(self) -> None:
return code

async def _get_resume_path(self):
# Get Resume Path
"""Get Resume Path from Polestar."""
params = {
"response_type": "code",
"client_id": "polmystar",
"redirect_uri": "https://www.polestar.com/sign-in-callback"
}
result = await self._client_session.get("https://polestarid.eu.polestar.com/as/authorization.oauth2", params=params, timeout=HTTPX_TIMEOUT)
if result.status_code != 303:
raise PolestarAuthException("Error getting resume path ", result.status_code)
return result.next_request.url.params
if result.status_code in (303, 302):
return result.next_request.url.params

_LOGGER.error(result.text)
raise PolestarAuthException("Error getting resume path ", result.status_code)

13 changes: 6 additions & 7 deletions custom_components/polestar_api/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,20 +548,19 @@ def state(self) -> StateType:

return estimate_range



if self.entity_description.key in ('current_odometer_meters'):
if int(self._attr_native_value) > 1000:
km = self._attr_native_value / 1000
self._attr_native_value = int(km)

# round the value
if self.entity_description.round_digits is not None:
# if the value is integer, remove the decimal
if self.entity_description.round_digits == 0 and isinstance(self._attr_native_value, int):
return int(self._attr_native_value)
return round(float(self._attr_native_value), self.entity_description.round_digits)

if self.entity_description.key in ('current_odometer_meters'):
_LOGGER.info("current_odometer_meters %s", self._attr_native_value)
if int(self._attr_native_value) > 1000:
return self._attr_native_value / 1000


return self._attr_native_value

@property
Expand Down
26 changes: 10 additions & 16 deletions custom_components/polestar_api/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,11 @@
},
"entity": {
"sensor": {
"polestar_estimate_distance_to_empty_miles": {
"name": "Distance restante en miles"
},
"polestar_estimate_distance_to_empty_km": {
"name": "Distance restante en km"
},
"polestar_current_odometer_meters": {
"name": "Odomètre"
},
"polestar_average_speed_km_per_hour": {
"name": "Vitesse moyenne en km/h"
"polestar_average_speed_per_hour": {
"name": "Vitesse moyenne"
},
"polestar_current_trip_meter_automatic": {
"name": "Compteur kilométrique automatique"
Expand All @@ -49,16 +43,16 @@
"name": "État de la recharge"
},
"polestar_charging_power_watts": {
"name": "Puissance de recharge (watts)"
"name": "Puissance de recharge"
},
"polestar_charging_current_amps": {
"name": "Puissance de recharge (Amps)"
"name": "Puissance de recharge"
},
"polestar_charger_connection_status": {
"name": "État de connexion du chargeur"
},
"polestar_average_energy_consumption_kwh_per_100_km": {
"name": "Consommation d'énergie moyenne en kWh/100km"
"polestar_average_energy_consumption_kwh_per_100": {
"name": "Consommation d'énergie moyenne"
},
"polestar_estimated_charging_time_minutes_to_target_distance": {
"name": "Temps de recharge restant pour la distance jusqu'à destination"
Expand All @@ -81,11 +75,11 @@
"polestar_last_updated_battery_data": {
"name": "Dernière mise à jour des données de batterie"
},
"polestar_estimate_full_charge_range_miles": {
"name": "Estimé de l'autonomie complète en miles"
},
"polestar_estimate_full_charge_range": {
"name": "Estimé de l'autonomie complète en km"
"name": "Estimé de l'autonomie complète"
},
"polestar_estimate_range": {
"name": "Estimé de l'autonomie"
},
"polestar_api_status_code": {
"name": "Code d'état de l'API"
Expand Down