Skip to content

Commit

Permalink
feat: add scheduled departure and charge timestamp attributes (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
InTheDaylight14 authored Dec 24, 2022
1 parent d310ae5 commit b979846
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
14 changes: 13 additions & 1 deletion custom_components/tesla_custom/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,12 @@ def is_on(self):
@property
def extra_state_attributes(self):
"""Return device state attributes."""
timestamp = self._car._vehicle_data.get("charge_state", {}).get(
"scheduled_charging_start_time"
)
return {
"Scheduled charging time": self._car.scheduled_charging_start_time_app,
"Scheduled charging timestamp": timestamp,
}


Expand All @@ -301,20 +305,28 @@ def __init__(
@property
def is_on(self):
"""Return True if scheduled departure enebaled."""
if self._car.scheduled_charging_mode == "DepartBy":
if (
self._car.scheduled_charging_mode == "DepartBy"
or self._car.is_preconditioning_enabled
or self._car.is_off_peak_charging_enabled
):
return True
return False

@property
def extra_state_attributes(self):
"""Return device state attributes."""
timestamp = self._car._vehicle_data.get("charge_state", {}).get(
"scheduled_departure_time"
)
return {
"Departure time": self._car.scheduled_departure_time_minutes,
"Preconditioning enabled": self._car.is_preconditioning_enabled,
"Preconditioning weekdays only": self._car.is_preconditioning_weekday_only,
"Off peak charging enabled": self._car.is_off_peak_charging_enabled,
"Off peak charging weekdays only": self._car.is_off_peak_charging_weekday_only,
"End off peak time": self._car.off_peak_hours_end_time,
"Departure timestamp": timestamp,
}


Expand Down
8 changes: 8 additions & 0 deletions tests/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ async def test_car_scheduled_charging(hass: HomeAssistant) -> None:
"scheduled_charging_start_time_app"
]
)
assert (
state.attributes.get("Scheduled charging timestamp")
== car_mock_data.VEHICLE_DATA["charge_state"]["scheduled_charging_start_time"]
)


async def test_car_scheduled_departure(hass: HomeAssistant) -> None:
Expand Down Expand Up @@ -230,6 +234,10 @@ async def test_car_scheduled_departure(hass: HomeAssistant) -> None:
state.attributes.get("End off peak time")
== car_mock_data.VEHICLE_DATA["charge_state"]["off_peak_hours_end_time"]
)
assert (
state.attributes.get("Departure timestamp")
== car_mock_data.VEHICLE_DATA["charge_state"]["scheduled_departure_time"]
)


async def test_car_user_present(hass: HomeAssistant) -> None:
Expand Down

0 comments on commit b979846

Please sign in to comment.