Skip to content

Commit

Permalink
Merge pull request #238 from jschlyter/dates_as_attributes
Browse files Browse the repository at this point in the history
Add static dates as attributes
  • Loading branch information
jschlyter authored Nov 14, 2024
2 parents 0763005 + 48b8e39 commit 2feded8
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions custom_components/polestar_api/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ class PolestarSensorDescription(
round_digits=None,
max_value=None,
dict_data=None,
entity_registry_enabled_default=False,
),
PolestarSensorDescription(
key="registration_number",
Expand All @@ -332,6 +333,7 @@ class PolestarSensorDescription(
round_digits=None,
max_value=None,
dict_data=None,
entity_registry_enabled_default=False,
),
PolestarSensorDescription(
key="internal_vehicle_id",
Expand Down Expand Up @@ -515,6 +517,7 @@ def __init__(
self.entity_description.query,
self.entity_description.field_name,
)
self._attr_extra_state_attributes = {}

if entity_description.round_digits is not None:
self.attr_suggested_display_precision = entity_description.round_digits
Expand Down Expand Up @@ -562,6 +565,22 @@ def state(self) -> StateType:
self._attr_native_value, self._attr_native_value
)

if self.entity_description.key == "vin":
self._attr_extra_state_attributes = {
"factory_complete_date": self.car.get_value(
query="getConsumerCarsV2",
field_name="factoryCompleteDate",
)
}

if self.entity_description.key == "registration_number":
self._attr_extra_state_attributes = {
"registration_date": self.car.get_value(
query="getConsumerCarsV2",
field_name="registrationDate",
)
}

if self.entity_description.key == "api_token_expires_at":
expire = self.car.get_token_expiry()
return (
Expand Down

0 comments on commit 2feded8

Please sign in to comment.