Skip to content

Commit

Permalink
fix: check if arrival time attribute is available
Browse files Browse the repository at this point in the history
closes #661
  • Loading branch information
alandtse committed Jul 8, 2023
1 parent 525cfb2 commit 5936ea3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions custom_components/tesla_custom/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,9 @@ def extra_state_attributes(self):
"Energy at arrival": self._car.active_route_energy_at_arrival,
"Minutes traffic delay": minutes,
"Destination": self._car.active_route_destination,
"Minutes to arrival": round(
float(self._car.active_route_minutes_to_arrival), 2
),
"Minutes to arrival": None
if self._car.active_route_minutes_to_arrival is None
else round(float(self._car.active_route_minutes_to_arrival), 2),
}


Expand Down
8 changes: 8 additions & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,14 @@ async def test_arrival_time(hass: HomeAssistant, monkeypatch: MonkeyPatch) -> No
)


async def test_arrival_time_none(hass: HomeAssistant, monkeypatch: MonkeyPatch) -> None:
"""Tests arrival time is getting the correct value."""
car_mock_data.VEHICLE_DATA["drive_state"]["active_route_minutes_to_arrival"] = None
await setup_platform(hass, SENSOR_DOMAIN)
state = hass.states.get("sensor.my_model_s_arrival_time")
assert state.attributes.get("Minutes to arrival") == None


async def test_distance_to_arrival(hass: HomeAssistant) -> None:
"""Tests distance to arrival is getting the correct value."""
await setup_platform(hass, SENSOR_DOMAIN)
Expand Down

0 comments on commit 5936ea3

Please sign in to comment.