Skip to content

Commit

Permalink
feat: add min_to_full_charge attribute (#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
InTheDaylight14 committed Feb 9, 2023
1 parent cc9686d commit 316ad90
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions custom_components/tesla_custom/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,18 @@ def native_value(self) -> Optional[datetime]:
return self._value
return None

@property
def extra_state_attributes(self):
"""Return device state attributes."""
# pylint: disable=protected-access
minutes_to_full_charge = self._car._vehicle_data.get("charge_state", {}).get(
"minutes_to_full_charge"
)

return {
"minutes_to_full_charge": minutes_to_full_charge,
}


class TeslaCarTpmsPressureSensor(TeslaCarEntity, SensorEntity):
"""Representation of the Tesla car TPMS Pressure sensor."""
Expand Down
8 changes: 8 additions & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@
PressureConverter,
SpeedConverter,
)
import pytest
from pytest import MonkeyPatch

pytestmark = pytest.mark.asyncio

from .common import setup_platform
from .mock_data import car as car_mock_data, energysite as energysite_mock_data

Expand Down Expand Up @@ -267,6 +270,11 @@ async def test_time_charge_complete_charging(
)
charge_complete_str = datetime.strftime(charge_complete, "%Y-%m-%dT%H:%M:%S+00:00")

minutes_to_full_charge = car_mock_data.VEHICLE_DATA["charge_state"][
"minutes_to_full_charge"
]
assert state.attributes.get("minutes_to_full_charge") == minutes_to_full_charge


async def test_time_charge_completed(hass: HomeAssistant) -> None:
"""Tests time charge complete is the correct value."""
Expand Down

0 comments on commit 316ad90

Please sign in to comment.