diff --git a/custom_components/tesla_custom/binary_sensor.py b/custom_components/tesla_custom/binary_sensor.py index 3b9abbad..8b9b7441 100644 --- a/custom_components/tesla_custom/binary_sensor.py +++ b/custom_components/tesla_custom/binary_sensor.py @@ -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, } @@ -301,13 +305,20 @@ 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, @@ -315,6 +326,7 @@ def extra_state_attributes(self): "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, } diff --git a/tests/test_binary_sensor.py b/tests/test_binary_sensor.py index 6dace0aa..a24856d2 100644 --- a/tests/test_binary_sensor.py +++ b/tests/test_binary_sensor.py @@ -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: @@ -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: