From c4642db24f5c3fff0937931f3f737c20eeaee9e5 Mon Sep 17 00:00:00 2001 From: Tuen Lee Date: Tue, 26 Dec 2023 16:03:23 +0100 Subject: [PATCH 1/9] add localization of sensor value fix #28 --- custom_components/polestar_api/polestar.py | 3 + .../polestar_api/pypolestar/polestar.py | 2 + custom_components/polestar_api/sensor.py | 28 +++-- .../polestar_api/translations/de.json | 112 ++++++++++++++--- .../polestar_api/translations/en.json | 119 ++++++++++++++---- .../polestar_api/translations/nl.json | 98 +++++++++++++++ .../polestar_api/translations/no.json | 112 ++++++++++++++--- .../polestar_api/translations/sv.json | 114 ++++++++++++++--- .../polestar_api/translations/uk.json | 117 +++++++++++++---- 9 files changed, 593 insertions(+), 112 deletions(-) create mode 100644 custom_components/polestar_api/translations/nl.json diff --git a/custom_components/polestar_api/polestar.py b/custom_components/polestar_api/polestar.py index 32f3e21..4fe6300 100644 --- a/custom_components/polestar_api/polestar.py +++ b/custom_components/polestar_api/polestar.py @@ -35,6 +35,9 @@ async def init(self): self.id = vin[:8] self.name = "Polestar " + vin[-4:] + def get_token_expiry(self): + return self.polestarApi.auth.token_expiry + def get_latest_data(self, query: str, field_name: str): return self.polestarApi.get_latest_data(query, field_name) diff --git a/custom_components/polestar_api/pypolestar/polestar.py b/custom_components/polestar_api/pypolestar/polestar.py index 741459b..81257a9 100644 --- a/custom_components/polestar_api/pypolestar/polestar.py +++ b/custom_components/polestar_api/pypolestar/polestar.py @@ -109,6 +109,8 @@ async def get_ev_data(self, vin: str): self.updating = True try: + if self.auth.token_expiry is None: + raise PolestarAuthException("No token expiry found") if self.auth.token_expiry < datetime.now(): await self.auth.get_token() except PolestarAuthException as e: diff --git a/custom_components/polestar_api/sensor.py b/custom_components/polestar_api/sensor.py index 700f8dd..461fa63 100644 --- a/custom_components/polestar_api/sensor.py +++ b/custom_components/polestar_api/sensor.py @@ -82,7 +82,7 @@ class PolestarSensorDescription( state_class=SensorStateClass.MEASUREMENT, device_class=SensorDeviceClass.DISTANCE, max_value=None, - dict_data=None + dict_data=None, ), PolestarSensorDescription( key="estimate_distance_to_empty_km", @@ -354,6 +354,17 @@ class PolestarSensorDescription( max_value=None, dict_data=API_STATUS_DICT ), + PolestarSensorDescription( + key="api_token_expires_at", + name="API token expired at", + icon="mdi:heart", + query=None, + field_name=None, + unit=None, + round_digits=None, + max_value=None, + dict_data=None + ), ) @@ -382,7 +393,7 @@ async def async_setup_entry( PolestarSensor(device, description) for description in POLESTAR_SENSOR_TYPES ] async_add_entities(sensors) - platform = entity_platform.current_platform.get() + entity_platform.current_platform.get() class PolestarSensor(PolestarEntity, SensorEntity): @@ -399,9 +410,11 @@ def __init__(self, # get the last 4 character of the id unique_id = device.vin[-4:] self.entity_id = f"{POLESTAR_API_DOMAIN}.'polestar_'.{unique_id}_{description.key}" - self._attr_name = f"{description.name}" + #self._attr_name = f"{description.name}" self._attr_unique_id = f"polestar_{unique_id}-{description.key}" self.description = description + self.translation_key = f"polestar_{description.key}" + self.has_entity_name = True self.entity_description = description if description.state_class is not None: @@ -430,11 +443,6 @@ def unique_id(self) -> str: """Return a unique ID.""" return f"{self._device.id}-{self.entity_description.key}" - @property - def name(self) -> str: - """Return the name of the sensor.""" - return self._attr_name - @property def icon(self) -> str | None: """Return the icon of the sensor.""" @@ -462,6 +470,10 @@ def state(self) -> StateType: return self.entity_description.dict_data.get( self._attr_native_value, self._attr_native_value) + if self.entity_description.key == 'api_token_expires_at': + if self._device.get_token_expiry() is None: + return None + return self._device.get_token_expiry().strftime("%Y-%m-%d %H:%M:%S") if self._attr_native_value != 0 and self._attr_native_value in (None, False): return None diff --git a/custom_components/polestar_api/translations/de.json b/custom_components/polestar_api/translations/de.json index 37b4aaf..2119d31 100644 --- a/custom_components/polestar_api/translations/de.json +++ b/custom_components/polestar_api/translations/de.json @@ -1,22 +1,98 @@ { - "config": { - "step": { - "user": { - "title": "Konfiguriere Deinen Polestar", - "description": "Eingabe der Zugangsdaten Deines Polestar", - "data": { - "name": "Anzeigename", - "username": "Benutzername", - "password": "Passwort", - "vin": "VIN" - } - } - }, - "abort": { - "api_timeout": "Zeitüberschreitung bei der Verbindung mit der API.", - "api_failed": "Unerwarteter Fehler beim Erstellen der API.", - "already_configured": "Die Polestar API ist bereits konfiguriert", - "no_token": "Kein Token in der Antwort gefunden. Bitte überprüfe Deine Anmeldeinformationen." + "config": { + "step": { + "user": { + "title": "Konfiguriere Deinen Polestar", + "description": "Eingabe der Zugangsdaten Deines Polestar", + "data": { + "name": "Anzeigename", + "username": "Benutzername", + "password": "Passwort", + "vin": "VIN" } + } + }, + "abort": { + "api_timeout": "Zeitüberschreitung bei der Verbindung mit der API.", + "api_failed": "Unerwarteter Fehler beim Erstellen der API.", + "already_configured": "Die Polestar API ist bereits konfiguriert", + "no_token": "Kein Token in der Antwort gefunden. Bitte überprüfe Deine Anmeldeinformationen." } + }, + "entity": { + "sensor": { + "polestar_estimate_distance_to_empty_miles": { + "name": "Reichweite (Meilen)" + }, + "polestar_estimate_distance_to_empty_km": { + "name": "Reichweite (km)" + }, + "polestar_current_odometer_meters": { + "name": "Kilometerstand" + }, + "polestar_average_speed_km_per_hour": { + "name": "Durchschnittsgeschwindigkeit (km/h)" + }, + "polestar_current_trip_meter_automatic": { + "name": "Trip Meter Automatisch" + }, + "polestar_current_trip_meter_manual": { + "name": "Trip Meter Manuell" + }, + "polestar_battery_charge_level": { + "name": "Batterieladestand" + }, + "polestar_estimated_charging_time_to_full_minutes": { + "name": "Geschätzte Ladezeit bis zur vollen Batterie" + }, + "polestar_charging_status": { + "name": "Ladezustand" + }, + "polestar_charging_power_watts": { + "name": "Ladeleistung" + }, + "polestar_charging_current_amps": { + "name": "Ladestrom" + }, + "polestar_charger_connection_status": { + "name": "Ladestatus" + }, + "polestar_average_energy_consumption_kwh_per_100_km": { + "name": "Durchschnittlicher Energieverbrauch (kWh/100km)" + }, + "polestar_estimated_charging_time_minutes_to_target_distance": { + "name": "Geschätzte Ladezeit bis zur Zielentfernung" + }, + "polestar_vin": { + "name": "VIN" + }, + "polestar_registration_number": { + "name": "Registrierungsnummer" + }, + "polestar_estimated_fully_charged_time": { + "name": "Geschätzte vollständig geladene Zeit" + }, + "polestar_model_name": { + "name": "Modellname" + }, + "polestar_last_updated_odometer_data": { + "name": "Letzte Aktualisierung der Kilometerstanddaten" + }, + "polestar_last_updated_battery_data": { + "name": "Letzte Aktualisierung der Batteriedaten" + }, + "polestar_estimate_full_charge_range_miles": { + "name": "Geschätzte Reichweite bei voller Ladung (Meilen)" + }, + "polestar_estimate_full_charge_range": { + "name": "Geschätzte Reichweite bei voller Ladung" + }, + "polestar_api_status_code": { + "name": "API Status Code" + }, + "polestar_api_token_expires_at": { + "name": "API Token läuft ab" + } + } + } } diff --git a/custom_components/polestar_api/translations/en.json b/custom_components/polestar_api/translations/en.json index 8ec0462..233e762 100644 --- a/custom_components/polestar_api/translations/en.json +++ b/custom_components/polestar_api/translations/en.json @@ -1,29 +1,98 @@ { - "config": { - "step": { - "user": { - "title": "Configure Polestar EV", - "description": "Enter Authentication of Polestar EV", - "data": { - "name": "Friendly name", - "username": "Username", - "password": "Password", - "vin": "VIN" - } - } - }, - "abort": { - "api_timeout": "Timeout connecting to the api.", - "api_failed": "Unexpected error creating api.", - "already_configured": "Polestar API is already configured", - "no_token": "No token found in response. Please check your credentials." + "config": { + "step": { + "user": { + "title": "Configure Polestar EV", + "description": "Enter Authentication of Polestar EV", + "data": { + "name": "Friendly name", + "username": "Username", + "password": "Password", + "vin": "VIN" } + } }, - "entity": { - "sensor": { - "polestar_api_estimate_distance_to_empty_km": { - "name": "Distance km Remaining" - } - } + "abort": { + "api_timeout": "Timeout connecting to the api.", + "api_failed": "Unexpected error creating api.", + "already_configured": "Polestar API is already configured", + "no_token": "No token found in response. Please check your credentials." + } + }, + "entity": { + "sensor": { + "polestar_estimate_distance_to_empty_miles": { + "name": "Distance Miles Remaining" + }, + "polestar_estimate_distance_to_empty_km": { + "name": "Distance km Remaining" + }, + "polestar_current_odometer_meters": { + "name": "Odometer Meters" + }, + "polestar_average_speed_km_per_hour": { + "name": "Average Speed km/h" + }, + "polestar_current_trip_meter_automatic": { + "name": "Trip Meter Automatic" + }, + "polestar_current_trip_meter_manual": { + "name": "Trip Meter Manual" + }, + "polestar_battery_charge_level": { + "name": "Battery Charge Level" + }, + "polestar_estimated_charging_time_to_full_minutes": { + "name": "Estimated Charging Time to Full Minutes" + }, + "polestar_charging_status": { + "name": "Charging Status" + }, + "polestar_charging_power_watts": { + "name": "Charging Power Watts" + }, + "polestar_charging_current_amps": { + "name": "Charging Current Amps" + }, + "polestar_charger_connection_status": { + "name": "Charger Connection Status" + }, + "polestar_average_energy_consumption_kwh_per_100_km": { + "name": "Average Energy Consumption kWh/100km" + }, + "polestar_estimated_charging_time_minutes_to_target_distance": { + "name": "Estimated Charging Time Minutes to Target Distance" + }, + "polestar_vin": { + "name": "VIN" + }, + "polestar_registration_number": { + "name": "Registration Number" + }, + "polestar_estimated_fully_charged_time": { + "name": "Estimated Fully Charged Time" + }, + "polestar_model_name": { + "name": "Model Name" + }, + "polestar_last_updated_odometer_data": { + "name": "Last Updated Odometer Data" + }, + "polestar_last_updated_battery_data": { + "name": "Last Updated Battery Data" + }, + "polestar_estimate_full_charge_range_miles": { + "name": "Estimate Full Charge Range Miles" + }, + "polestar_estimate_full_charge_range": { + "name": "Estimate Full Charge Range" + }, + "polestar_api_status_code": { + "name": "API Status Code" + }, + "polestar_api_token_expires_at": { + "name": "API Token Expires At" + } } -} \ No newline at end of file + } +} diff --git a/custom_components/polestar_api/translations/nl.json b/custom_components/polestar_api/translations/nl.json new file mode 100644 index 0000000..f574ce9 --- /dev/null +++ b/custom_components/polestar_api/translations/nl.json @@ -0,0 +1,98 @@ +{ + "config": { + "step": { + "user": { + "title": "Configure Polestar EV", + "description": "Enter Authentication of Polestar EV", + "data": { + "name": "Friendly name", + "username": "Username", + "password": "Password", + "vin": "VIN" + } + } + }, + "abort": { + "api_timeout": "Timeout connecting to the api.", + "api_failed": "Unexpected error creating api.", + "already_configured": "Polestar API is already configured", + "no_token": "No token found in response. Please check your credentials." + } + }, + "entity": { + "sensor": { + "polestar_distance_to_empty_miles": { + "name": "Resterende afstand (mijl)" + }, + "polestar_estimate_distance_to_empty_km": { + "name": "Resterende afstand (km)" + }, + "polestar_current_odometer_meters": { + "name": "Huidige kilometerstand" + }, + "polestar_average_speed_km_per_hour": { + "name": "Gemiddelde snelheid (km/u)" + }, + "polestar_current_trip_meter_automatic": { + "name": "Huidige trip meter (automatisch)" + }, + "polestar_current_trip_meter_manual": { + "name": "Huidige trip meter (manueel)" + }, + "polestar_battery_charge_level": { + "name": "Batterij niveau" + }, + "polestar_estimated_charging_time_to_full_minutes": { + "name": "Geschatte laadtijd tot vol (min)" + }, + "polestar_charging_status": { + "name": "Laadstatus" + }, + "polestar_charging_power_watts": { + "name": "Laadvermogen (W)" + }, + "polestar_charging_current_amps": { + "name": "Laadstroom (A)" + }, + "polestar_charger_connection_status": { + "name": "Laadkabel status" + }, + "polestar_average_energy_consumption_kwh_per_100_km": { + "name": "Gemiddeld verbruik (kWh/100km)" + }, + "polestar_estimated_charging_time_minutes_to_target_distance": { + "name": "Geschatte laadtijd tot doelafstand (min)" + }, + "polestar_vin": { + "name": "VIN" + }, + "polestar_registration_number": { + "name": "Registratienummer" + }, + "polestar_estimated_fully_charged_time": { + "name": "Geschatte volledig opgeladen tijd" + }, + "polestar_model_name": { + "name": "Model" + }, + "polestar_last_updated_odometer_data": { + "name": "Laatst geüpdatete kilometerstand" + }, + "polestar_last_updated_battery_data": { + "name": "Laatst geüpdatete batterijgegevens" + }, + "polestar_estimate_full_charge_range_miles": { + "name": "Geschatte volledige laadafstand (mijl)" + }, + "polestar_estimate_full_charge_range": { + "name": "Geschatte volledige laadafstand (km)" + }, + "polestar_api_status_code": { + "name": "API Status Code" + }, + "polestar_api_token_expires_at": { + "name": "API Token vervalt op" + } + } + } +} diff --git a/custom_components/polestar_api/translations/no.json b/custom_components/polestar_api/translations/no.json index 6c4ed5c..b2ed9be 100644 --- a/custom_components/polestar_api/translations/no.json +++ b/custom_components/polestar_api/translations/no.json @@ -1,22 +1,98 @@ { - "config": { - "step": { - "user": { - "title": "Konfigurer din Polestar", - "description": "Autentiseringsdetaljer", - "data": { - "name": "Visningsnavn", - "username": "Brukernavn", - "password": "Passord", - "vin": "VIN" - } - } - }, - "abort": { - "api_timeout": "Tidsavbrudd for API-tilkobling.", - "api_failed": "Uventet feil under oppretting av API.", - "already_configured": "Polestar API er allerede konfigurert", - "no_token": "Ingen token mottatt fra serveren. Vennligst kontroller inntastet informasjon." + "config": { + "step": { + "user": { + "title": "Konfigurer din Polestar", + "description": "Autentiseringsdetaljer", + "data": { + "name": "Visningsnavn", + "username": "Brukernavn", + "password": "Passord", + "vin": "VIN" } + } + }, + "abort": { + "api_timeout": "Tidsavbrudd for API-tilkobling.", + "api_failed": "Uventet feil under oppretting av API.", + "already_configured": "Polestar API er allerede konfigurert", + "no_token": "Ingen token mottatt fra serveren. Vennligst kontroller inntastet informasjon." } + }, + "entity": { + "sensor": { + "polestar_estimate_distance_to_empty_miles": { + "name": "Avstand Miles gjenværende" + }, + "polestar_estimate_distance_to_empty_km": { + "name": "Avstand Km gjenværende" + }, + "polestar_current_odometer_meters": { + "name": "Kilometerstand" + }, + "polestar_average_speed_km_per_hour": { + "name": "Gjennomsnittsfart Km/t" + }, + "polestar_current_trip_meter_automatic": { + "name": "Trip Meter Automatisk" + }, + "polestar_current_trip_meter_manual": { + "name": "Trip Meter Manuell" + }, + "polestar_battery_charge_level": { + "name": "Batteri Ladningsnivå" + }, + "polestar_estimated_charging_time_to_full_minutes": { + "name": "Estimert ladetid til fullt batteri" + }, + "polestar_charging_status": { + "name": "Ladestatus" + }, + "polestar_charging_power_watts": { + "name": "Ladeeffekt Watt" + }, + "polestar_charging_current_amps": { + "name": "Ladeeffekt Ampere" + }, + "polestar_charger_connection_status": { + "name": "Ladekobling" + }, + "polestar_average_energy_consumption_kwh_per_100_km": { + "name": "Gjennomsnittlig energiforbruk kWh/100km" + }, + "polestar_estimated_charging_time_minutes_to_target_distance": { + "name": "Estimert ladetid til ønsket avstand" + }, + "polestar_vin": { + "name": "VIN" + }, + "polestar_registration_number": { + "name": "Registreringsnummer" + }, + "polestar_estimated_fully_charged_time": { + "name": "Estimert fulladetid" + }, + "polestar_model_name": { + "name": "Modellnavn" + }, + "polestar_last_updated_odometer_data": { + "name": "Sist oppdatert kilometerstand" + }, + "polestar_last_updated_battery_data": { + "name": "Sist oppdatert batteridata" + }, + "polestar_estimate_full_charge_range_miles": { + "name": "Estimert rekkevidde ved fullt batteri Miles" + }, + "polestar_estimate_full_charge_range": { + "name": "Estimert rekkevidde ved fullt batteri" + }, + "polestar_api_status_code": { + "name": "API-statuskode" + }, + "polestar_api_token_expires_at": { + "name": "API-token utløper" + } + } + } } diff --git a/custom_components/polestar_api/translations/sv.json b/custom_components/polestar_api/translations/sv.json index 05d87da..3dde2f6 100644 --- a/custom_components/polestar_api/translations/sv.json +++ b/custom_components/polestar_api/translations/sv.json @@ -1,22 +1,98 @@ { - "config": { - "step": { - "user": { - "title": "Konfigurera din Polestar", - "description": "Ange autentisering av din Polestar", - "data": { - "name": "Namn på displayen", - "username": "Användernam", - "password": "Lösenord", - "vin": "VIN" - } - } - }, - "abort": { - "api_timeout": "Timeout för anslutning till API.", - "api_failed": "Oväntat fel vid skapande av API.", - "already_configured": "Polestar API är redan konfigurerat", - "no_token": "Ingen token hittades i svaret. Vänligen kontrollera dina uppgifter." + "config": { + "step": { + "user": { + "title": "Konfigurera din Polestar", + "description": "Ange autentisering av din Polestar", + "data": { + "name": "Namn på displayen", + "username": "Användernam", + "password": "Lösenord", + "vin": "VIN" } + } + }, + "abort": { + "api_timeout": "Timeout för anslutning till API.", + "api_failed": "Oväntat fel vid skapande av API.", + "already_configured": "Polestar API är redan konfigurerat", + "no_token": "Ingen token hittades i svaret. Vänligen kontrollera dina uppgifter." } -} \ No newline at end of file + }, + "entity": { + "sensor": { + "polestar_estimate_distance_to_empty_miles": { + "name": "Avstånd Miles kvar" + }, + "polestar_estimate_distance_to_empty_km": { + "name": "Avstånd km kvar" + }, + "polestar_current_odometer_meters": { + "name": "Mätarställning" + }, + "polestar_average_speed_km_per_hour": { + "name": "Medelhastighet km/h" + }, + "polestar_current_trip_meter_automatic": { + "name": "Trippmätare automatiskt" + }, + "polestar_current_trip_meter_manual": { + "name": "Trippmätare manual" + }, + "polestar_battery_charge_level": { + "name": "Batterinivå" + }, + "polestar_estimated_charging_time_to_full_minutes": { + "name": "Laddningstid till full" + }, + "polestar_charging_status": { + "name": "Laddningsstatus" + }, + "polestar_charging_power_watts": { + "name": "Laddningseffekt" + }, + "polestar_charging_current_amps": { + "name": "Laddningsström" + }, + "polestar_charger_connection_status": { + "name": "Laddare ansluten" + }, + "polestar_average_energy_consumption_kwh_per_100_km": { + "name": "Medelförbrukning kWh/100km" + }, + "polestar_estimated_charging_time_minutes_to_target_distance": { + "name": "Laddningstid till mål" + }, + "polestar_vin": { + "name": "VIN" + }, + "polestar_registration_number": { + "name": "Registreringsnummer" + }, + "polestar_estimated_fully_charged_time": { + "name": "Beräknad fulladdningstid" + }, + "polestar_model_name": { + "name": "Modell" + }, + "polestar_last_updated_odometer_data": { + "name": "Senast uppdaterad mätarställning" + }, + "polestar_last_updated_battery_data": { + "name": "Senast uppdaterad batteridata" + }, + "polestar_estimate_full_charge_range_miles": { + "name": "Estimerad räckvidd vid fulladdning miles" + }, + "polestar_estimate_full_charge_range": { + "name": "Estimerad räckvidd vid fulladdning" + }, + "polestar_api_status_code": { + "name": "API-statuskod" + }, + "polestar_api_token_expires_at": { + "name": "API-token löper ut kl" + } + } + } +} diff --git a/custom_components/polestar_api/translations/uk.json b/custom_components/polestar_api/translations/uk.json index cabbcd1..2297bf7 100644 --- a/custom_components/polestar_api/translations/uk.json +++ b/custom_components/polestar_api/translations/uk.json @@ -1,29 +1,98 @@ { - "config": { - "step": { - "user": { - "title": "Налаштування Polestar EV", - "description": "Введіть дані аутентифікації для Polestar EV", - "data": { - "name": "Назва", - "username": "Ім’я користувача", - "password": "Пароль", - "vin": "VIN" - } - } - }, - "abort": { - "api_timeout": "Таймаут підключення до API.", - "api_failed": "Неочікувана помилка при створенні API.", - "already_configured": "Polestar API вже налаштовано.", - "no_token": "Токен не знайдено у відповіді. Будь ласка, перевірте Ваші дані." + "config": { + "step": { + "user": { + "title": "Налаштування Polestar EV", + "description": "Введіть дані аутентифікації для Polestar EV", + "data": { + "name": "Назва", + "username": "Ім’я користувача", + "password": "Пароль", + "vin": "VIN" } + } }, - "entity": { - "sensor": { - "polestar_api_estimate_distance_to_empty_km": { - "name": "Запас відстані, км" - } - } + "abort": { + "api_timeout": "Таймаут підключення до API.", + "api_failed": "Неочікувана помилка при створенні API.", + "already_configured": "Polestar API вже налаштовано.", + "no_token": "Токен не знайдено у відповіді. Будь ласка, перевірте Ваші дані." + } + }, + "entity": { + "sensor": { + "polestar_estimate_distance_to_empty_miles": { + "name": "Запас відстані, миль" + }, + "polestar_estimate_distance_to_empty_km": { + "name": "Запас відстані, км" + }, + "polestar_current_odometer_meters": { + "name": "Пробіг, метри" + }, + "polestar_average_speed_km_per_hour": { + "name": "Середня швидкість, км/год" + }, + "polestar_current_trip_meter_automatic": { + "name": "Лічильник поїздок, автоматичний" + }, + "polestar_current_trip_meter_manual": { + "name": "Лічильник поїздок, ручний" + }, + "polestar_battery_charge_level": { + "name": "Рівень заряду батареї" + }, + "polestar_estimated_charging_time_to_full_minutes": { + "name": "Час до повного заряду, хв" + }, + "polestar_charging_status": { + "name": "Статус зарядки" + }, + "polestar_charging_power_watts": { + "name": "Потужність зарядки, Вт" + }, + "polestar_charging_current_amps": { + "name": "Сила струму зарядки, А" + }, + "polestar_charger_connection_status": { + "name": "Статус підключення зарядного пристрою" + }, + "polestar_average_energy_consumption_kwh_per_100_km": { + "name": "Середнє споживання енергії, кВт·год/100 км" + }, + "polestar_estimated_charging_time_minutes_to_target_distance": { + "name": "Час до повного заряду, хв" + }, + "polestar_vin": { + "name": "VIN" + }, + "polestar_registration_number": { + "name": "Реєстраційний номер" + }, + "polestar_estimated_fully_charged_time": { + "name": "Час до повного заряду" + }, + "polestar_model_name": { + "name": "Модель" + }, + "polestar_last_updated_odometer_data": { + "name": "Останні дані пробігу" + }, + "polestar_last_updated_battery_data": { + "name": "Останні дані батареї" + }, + "polestar_estimate_full_charge_range_miles": { + "name": "Запас відстані при повному заряді, миль" + }, + "polestar_estimate_full_charge_range": { + "name": "Запас відстані при повному заряді" + }, + "polestar_api_status_code": { + "name": "Код статусу API" + }, + "polestar_api_token_expires_at": { + "name": "Токен закінчується" + } } + } } From 3d35541cf9f728443986504269b34bb8bafb0a65 Mon Sep 17 00:00:00 2001 From: Tuen Lee Date: Tue, 26 Dec 2023 22:05:19 +0100 Subject: [PATCH 2/9] sensor should also get exception on async update --- custom_components/polestar_api/sensor.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/custom_components/polestar_api/sensor.py b/custom_components/polestar_api/sensor.py index 461fa63..74afb7d 100644 --- a/custom_components/polestar_api/sensor.py +++ b/custom_components/polestar_api/sensor.py @@ -539,6 +539,9 @@ def unit_of_measurement(self) -> str: async def async_update(self) -> None: """Get the latest data and updates the states.""" - await self._device.async_update() - self._attr_native_value = self._device.get_value( - self.description.query, self.description.field_name, self.get_skip_cache()) + try: + await self._device.async_update() + self._attr_native_value = self._device.get_value( + self.description.query, self.description.field_name, self.get_skip_cache()) + except Exception: + _LOGGER.warning("Failed to update sensor async update") From 3bec2e51fdce61d824955c448721e92156d8aa4c Mon Sep 17 00:00:00 2001 From: Tuen Lee Date: Tue, 26 Dec 2023 22:16:52 +0100 Subject: [PATCH 3/9] fix local dev in dev --- custom_components/polestar_api/sensor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/polestar_api/sensor.py b/custom_components/polestar_api/sensor.py index 74afb7d..0726ffc 100644 --- a/custom_components/polestar_api/sensor.py +++ b/custom_components/polestar_api/sensor.py @@ -413,8 +413,8 @@ def __init__(self, #self._attr_name = f"{description.name}" self._attr_unique_id = f"polestar_{unique_id}-{description.key}" self.description = description - self.translation_key = f"polestar_{description.key}" - self.has_entity_name = True + self.attr_translation_key = f"polestar_{description.key}" + self.attr_has_entity_name = True self.entity_description = description if description.state_class is not None: From 9a6799ac6987a1c07d7513b06885e2c2726cb30e Mon Sep 17 00:00:00 2001 From: Tuen Lee Date: Wed, 27 Dec 2023 00:58:48 +0100 Subject: [PATCH 4/9] fix skip cache after code cleanup --- custom_components/polestar_api/pypolestar/polestar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/polestar_api/pypolestar/polestar.py b/custom_components/polestar_api/pypolestar/polestar.py index 81257a9..6175ffd 100644 --- a/custom_components/polestar_api/pypolestar/polestar.py +++ b/custom_components/polestar_api/pypolestar/polestar.py @@ -142,7 +142,7 @@ def get_cache_data(self, query: str, field_name: str, skip_cache: bool = False): cache_entry = self.cache_data[query] data = cache_entry['data'] if data is not None: - if skip_cache is False or cache_entry['timestamp'] + timedelta(seconds=CACHE_TIME) > datetime.now(): + if skip_cache is True or cache_entry['timestamp'] + timedelta(seconds=CACHE_TIME) > datetime.now(): return self._get_field_name_value(field_name, data) return None From 2916a9e65cf628cdfcfd047471d14a9428fbb0a5 Mon Sep 17 00:00:00 2001 From: Sebastian Loeb Date: Wed, 27 Dec 2023 10:08:20 +0100 Subject: [PATCH 5/9] Correct German translations --- .../polestar_api/translations/de.json | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/custom_components/polestar_api/translations/de.json b/custom_components/polestar_api/translations/de.json index 2119d31..dbd7458 100644 --- a/custom_components/polestar_api/translations/de.json +++ b/custom_components/polestar_api/translations/de.json @@ -34,49 +34,49 @@ "name": "Durchschnittsgeschwindigkeit (km/h)" }, "polestar_current_trip_meter_automatic": { - "name": "Trip Meter Automatisch" + "name": "Kilometerzähler automatisch" }, "polestar_current_trip_meter_manual": { - "name": "Trip Meter Manuell" + "name": "Kilometerzähler manuell" }, "polestar_battery_charge_level": { "name": "Batterieladestand" }, "polestar_estimated_charging_time_to_full_minutes": { - "name": "Geschätzte Ladezeit bis zur vollen Batterie" + "name": "Geschätzte Ladezeit bis zur vollen Batterie (Minuten)" }, "polestar_charging_status": { - "name": "Ladezustand" + "name": "Ladestatus" }, "polestar_charging_power_watts": { - "name": "Ladeleistung" + "name": "Ladeleistung (W)" }, "polestar_charging_current_amps": { - "name": "Ladestrom" + "name": "Ladestrom (A)" }, "polestar_charger_connection_status": { - "name": "Ladestatus" + "name": "Verbindungsstatus Ladepunkt" }, "polestar_average_energy_consumption_kwh_per_100_km": { "name": "Durchschnittlicher Energieverbrauch (kWh/100km)" }, "polestar_estimated_charging_time_minutes_to_target_distance": { - "name": "Geschätzte Ladezeit bis zur Zielentfernung" + "name": "Geschätzte Ladezeit bis zur Zielreichweite" }, "polestar_vin": { "name": "VIN" }, "polestar_registration_number": { - "name": "Registrierungsnummer" + "name": "Kennzeichen" }, "polestar_estimated_fully_charged_time": { - "name": "Geschätzte vollständig geladene Zeit" + "name": "Geschätzte Zeit zur vollen Ladung" }, "polestar_model_name": { "name": "Modellname" }, "polestar_last_updated_odometer_data": { - "name": "Letzte Aktualisierung der Kilometerstanddaten" + "name": "Letzte Aktualisierung des Kilometerstands" }, "polestar_last_updated_battery_data": { "name": "Letzte Aktualisierung der Batteriedaten" @@ -91,8 +91,8 @@ "name": "API Status Code" }, "polestar_api_token_expires_at": { - "name": "API Token läuft ab" + "name": "API Token gültig bis" } } } -} +} \ No newline at end of file From 6d47ac24674db5ec82977f95d79962b83381f2fc Mon Sep 17 00:00:00 2001 From: Sebastian Loeb Date: Wed, 27 Dec 2023 10:43:45 +0100 Subject: [PATCH 6/9] Changed some sensor icons for better fit --- custom_components/polestar_api/sensor.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/custom_components/polestar_api/sensor.py b/custom_components/polestar_api/sensor.py index 0726ffc..8b04a11 100644 --- a/custom_components/polestar_api/sensor.py +++ b/custom_components/polestar_api/sensor.py @@ -113,7 +113,7 @@ class PolestarSensorDescription( PolestarSensorDescription( key="average_speed_km_per_hour", name="Avg Speed Per Hour", - icon="mdi:map-marker-distance", + icon="mdi:speedometer", query="getOdometerData", field_name="averageSpeedKmPerHour", unit='km', @@ -175,7 +175,7 @@ class PolestarSensorDescription( PolestarSensorDescription( key="charging_status", name="Charging status", - icon="mdi:battery-clock", + icon="mdi:ev-station", query="getBatteryData", field_name="chargingStatus", unit=None, @@ -212,7 +212,7 @@ class PolestarSensorDescription( PolestarSensorDescription( key="charger_connection_status", name="Charging Connection Status", - icon="mdi:battery-clock", + icon="mdi:connection", query="getBatteryData", field_name="chargerConnectionStatus", unit=None, @@ -286,6 +286,7 @@ class PolestarSensorDescription( PolestarSensorDescription( key="model_name", name="Model name", + icon="mdi:car-electric", query="getConsumerCarsV2", field_name="content/model/name", unit=None, @@ -296,6 +297,7 @@ class PolestarSensorDescription( PolestarSensorDescription( key="last_updated_odometer_data", name="Last updated odometer data", + icon="mdi:counter", query="getOdometerData", field_name="eventUpdatedTimestamp/iso", unit=None, From c725941a2c32550ad632c878553d08d9e077ad87 Mon Sep 17 00:00:00 2001 From: Sebastian Loeb Date: Wed, 27 Dec 2023 11:01:00 +0100 Subject: [PATCH 7/9] Revert "Changed some sensor icons for better fit" This reverts commit 6d47ac24674db5ec82977f95d79962b83381f2fc. --- custom_components/polestar_api/sensor.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/custom_components/polestar_api/sensor.py b/custom_components/polestar_api/sensor.py index 8b04a11..0726ffc 100644 --- a/custom_components/polestar_api/sensor.py +++ b/custom_components/polestar_api/sensor.py @@ -113,7 +113,7 @@ class PolestarSensorDescription( PolestarSensorDescription( key="average_speed_km_per_hour", name="Avg Speed Per Hour", - icon="mdi:speedometer", + icon="mdi:map-marker-distance", query="getOdometerData", field_name="averageSpeedKmPerHour", unit='km', @@ -175,7 +175,7 @@ class PolestarSensorDescription( PolestarSensorDescription( key="charging_status", name="Charging status", - icon="mdi:ev-station", + icon="mdi:battery-clock", query="getBatteryData", field_name="chargingStatus", unit=None, @@ -212,7 +212,7 @@ class PolestarSensorDescription( PolestarSensorDescription( key="charger_connection_status", name="Charging Connection Status", - icon="mdi:connection", + icon="mdi:battery-clock", query="getBatteryData", field_name="chargerConnectionStatus", unit=None, @@ -286,7 +286,6 @@ class PolestarSensorDescription( PolestarSensorDescription( key="model_name", name="Model name", - icon="mdi:car-electric", query="getConsumerCarsV2", field_name="content/model/name", unit=None, @@ -297,7 +296,6 @@ class PolestarSensorDescription( PolestarSensorDescription( key="last_updated_odometer_data", name="Last updated odometer data", - icon="mdi:counter", query="getOdometerData", field_name="eventUpdatedTimestamp/iso", unit=None, From 100c459dd35ca070bda958bd0370a0da2e5ad7fc Mon Sep 17 00:00:00 2001 From: Sebastian Loeb Date: Wed, 27 Dec 2023 11:30:09 +0100 Subject: [PATCH 8/9] Changed some sensor icons for better fit --- custom_components/polestar_api/sensor.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/custom_components/polestar_api/sensor.py b/custom_components/polestar_api/sensor.py index 700f8dd..549d13a 100644 --- a/custom_components/polestar_api/sensor.py +++ b/custom_components/polestar_api/sensor.py @@ -113,7 +113,7 @@ class PolestarSensorDescription( PolestarSensorDescription( key="average_speed_km_per_hour", name="Avg Speed Per Hour", - icon="mdi:map-marker-distance", + icon="mdi:speedometer", query="getOdometerData", field_name="averageSpeedKmPerHour", unit='km', @@ -175,7 +175,7 @@ class PolestarSensorDescription( PolestarSensorDescription( key="charging_status", name="Charging status", - icon="mdi:battery-clock", + icon="mdi:ev-station", query="getBatteryData", field_name="chargingStatus", unit=None, @@ -212,7 +212,7 @@ class PolestarSensorDescription( PolestarSensorDescription( key="charger_connection_status", name="Charging Connection Status", - icon="mdi:battery-clock", + icon="mdi:connection", query="getBatteryData", field_name="chargerConnectionStatus", unit=None, @@ -286,6 +286,7 @@ class PolestarSensorDescription( PolestarSensorDescription( key="model_name", name="Model name", + icon="mdi:car-electric", query="getConsumerCarsV2", field_name="content/model/name", unit=None, @@ -296,6 +297,7 @@ class PolestarSensorDescription( PolestarSensorDescription( key="last_updated_odometer_data", name="Last updated odometer data", + icon="mdi:counter", query="getOdometerData", field_name="eventUpdatedTimestamp/iso", unit=None, From 6d1b7e7e9b630a68392766b41a7a98f26619a6f1 Mon Sep 17 00:00:00 2001 From: Tomas Rudh Date: Wed, 27 Dec 2023 11:55:07 +0100 Subject: [PATCH 9/9] Update sv.json Corrected some typos --- .../polestar_api/translations/sv.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/custom_components/polestar_api/translations/sv.json b/custom_components/polestar_api/translations/sv.json index 3dde2f6..cee0889 100644 --- a/custom_components/polestar_api/translations/sv.json +++ b/custom_components/polestar_api/translations/sv.json @@ -6,7 +6,7 @@ "description": "Ange autentisering av din Polestar", "data": { "name": "Namn på displayen", - "username": "Användernam", + "username": "Användarnamn", "password": "Lösenord", "vin": "VIN" } @@ -22,10 +22,10 @@ "entity": { "sensor": { "polestar_estimate_distance_to_empty_miles": { - "name": "Avstånd Miles kvar" + "name": "Avstånd kvar (miles)" }, "polestar_estimate_distance_to_empty_km": { - "name": "Avstånd km kvar" + "name": "Avstånd kvar (km)" }, "polestar_current_odometer_meters": { "name": "Mätarställning" @@ -34,10 +34,10 @@ "name": "Medelhastighet km/h" }, "polestar_current_trip_meter_automatic": { - "name": "Trippmätare automatiskt" + "name": "Trippmätare automatisk" }, "polestar_current_trip_meter_manual": { - "name": "Trippmätare manual" + "name": "Trippmätare manuell" }, "polestar_battery_charge_level": { "name": "Batterinivå" @@ -82,10 +82,10 @@ "name": "Senast uppdaterad batteridata" }, "polestar_estimate_full_charge_range_miles": { - "name": "Estimerad räckvidd vid fulladdning miles" + "name": "Estimerad räckvidd vid full laddning miles" }, "polestar_estimate_full_charge_range": { - "name": "Estimerad räckvidd vid fulladdning" + "name": "Estimerad räckvidd vid full laddning" }, "polestar_api_status_code": { "name": "API-statuskod"