Skip to content

Commit

Permalink
Added heading tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyK69 committed Nov 3, 2020
1 parent af77f64 commit bb9c0f4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 2 additions & 4 deletions bimmer_connected/vehicle_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ def gps_position(self) -> (float, float):
Returns a tuple of (latitude, longitude).
This only provides data, if the vehicle tracking is enabled!
"""
pos = self._state.attributes[SERVICE_STATUS]['position']
if not self.is_vehicle_tracking_enabled:
_LOGGER.warning('Positioning status is %s', pos['status'])
_LOGGER.warning('Vehicle tracking is disabled')
return None
pos = self._state.attributes[SERVICE_STATUS]['position']
return float(pos['lat']), float(pos['lon'])
Expand All @@ -150,9 +149,8 @@ def gps_heading(self) -> (int):
This only provides data, if the vehicle tracking is enabled!
"""
pos = self._state.attributes[SERVICE_STATUS]['position']
if not self.is_vehicle_tracking_enabled:
_LOGGER.warning('Positioning status is %s', pos['status'])
_LOGGER.warning('Vehicle tracking is disabled')
return None
pos = self._state.attributes[SERVICE_STATUS]['position']
return int(pos['heading'])
Expand Down
3 changes: 3 additions & 0 deletions test/test_vehicle_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test_parse_g31(self):
self.assertTrue(state.vehicle_status.is_vehicle_tracking_enabled)
self.assertAlmostEqual(50.5050, state.vehicle_status.gps_position[0])
self.assertAlmostEqual(10.1010, state.vehicle_status.gps_position[1])
self.assertAlmostEqual(174, state.vehicle_status.gps_heading)

self.assertAlmostEqual(33, state.vehicle_status.remaining_fuel)

Expand Down Expand Up @@ -68,6 +69,7 @@ def test_parse_g31_no_psoition(self):

self.assertFalse(state.vehicle_status.is_vehicle_tracking_enabled)
self.assertIsNone(state.vehicle_status.gps_position)
self.assertIsNone(state.vehicle_status.gps_heading)

def test_parse_f48(self):
"""Test if the parsing of the attributes is working."""
Expand All @@ -84,6 +86,7 @@ def test_parse_f48(self):
self.assertTrue(state.vehicle_status.is_vehicle_tracking_enabled)
self.assertAlmostEqual(50.505050, state.vehicle_status.gps_position[0])
self.assertAlmostEqual(10.1010101, state.vehicle_status.gps_position[1])
self.assertAlmostEqual(141, state.vehicle_status.gps_heading)

self.assertAlmostEqual(39, state.vehicle_status.remaining_fuel)

Expand Down

0 comments on commit bb9c0f4

Please sign in to comment.