def test_door_locks(self): """Test the door locks.""" account = unittest.mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) state._attributes = G31_TEST_DATA['vehicleStatus'] self.assertEqual(LockState.SECURED, state.door_lock_state)
def test_parse_nbt(self): """Test if the parsing of the attributes is working.""" account = unittest.mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) state._attributes = NBT_TEST_DATA['attributesMap'] self.assertEqual(1234, state.mileage) self.assertEqual('km', state.unit_of_length) self.assertIsNone(state.timestamp) self.assertAlmostEqual(11.111, state.gps_position[0]) self.assertAlmostEqual(22.222, state.gps_position[1]) self.assertAlmostEqual(66, state.remaining_fuel) self.assertEqual('l', state.unit_of_volume) self.assertIsNone(state.remaining_range_fuel) self.assertEqual('Error', state.last_update_reason) cbs = state.condition_based_services self.assertEqual(6, len(cbs)) self.assertEqual('00001', cbs[0].code) self.assertEqual(ConditionBasedServiceStatus.OVERDUE, cbs[0].status) self.assertEqual(datetime.datetime(year=2018, month=12, day=1), cbs[0].due_date) self.assertEqual(-500, cbs[0].due_distance) self.assertEqual('00002', cbs[2].code) self.assertEqual(ConditionBasedServiceStatus.PENDING, cbs[2].status) self.assertEqual(140, cbs[2].due_distance) self.assertIsNone(state.are_parking_lights_on) self.assertIsNone(state.parking_lights)
def test_parse_g31_no_psoition(self): """Test parsing of G31 data with position tracking disabled in the vehicle.""" account = unittest.mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) state._attributes = G31_NO_POSITION_TEST_DATA['vehicleStatus'] self.assertFalse(state.is_vehicle_tracking_enabled) self.assertIsNone(state.gps_position)
def test_parse_f48(self): """Test if the parsing of the attributes is working.""" account = unittest.mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) state._attributes = F48_TEST_DATA['attributesMap'] self.assertTrue(state.are_parking_lights_on) self.assertEqual(ParkingLightState.LEFT, state.parking_lights)
def test_windows_f48(self): """Test features around lids.""" account = unittest.mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) state._attributes = F48_TEST_DATA['vehicleStatus'] for window in state.windows: self.assertEqual(LidState.CLOSED, window.state) self.assertEqual(4, len(list(state.windows)))
def test_parse_f16(self): """Test if the parsing of the attributes is working.""" account = unittest.mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) state._attributes = F16_TEST_DATA['attributesMap'] pos = state.gps_position self.assertTrue(state.is_vehicle_tracking_enabled) self.assertAlmostEqual(40, pos[0]) self.assertAlmostEqual(10, pos[1])
def test_parse_i01(self): """Test if the parsing of the attributes is working.""" account = unittest.mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) state._attributes = I01_TEST_DATA['vehicleStatus'] self.assertEqual(48, state.remaining_range_electric) self.assertEqual(154, state.remaining_range_total) self.assertEqual(94, state.max_range_electric) self.assertEqual(ChargingState.CHARGING, state.charging_status) self.assertEqual(datetime.timedelta(minutes=332), state.charging_time_remaining) self.assertEqual(54, state.charging_level_hv)
def test_ccm_f48(self): """Test parsing of a check control message.""" account = unittest.mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) state._attributes = F48_TEST_DATA['vehicleStatus'] ccms = state.check_control_messages self.assertEqual(1, len(ccms)) ccm = ccms[0] self.assertEqual(955, ccm["ccmId"]) self.assertEqual(41544, ccm["ccmMileage"]) self.assertIn("Tyre pressure", ccm["ccmDescriptionShort"]) self.assertIn("continue driving", ccm["ccmDescriptionLong"])
def test_windows(self): """Test features around lids.""" account = unittest.mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) state._attributes = G31_TEST_DATA['attributesMap'] for window in state.windows: self.assertEqual(LidState.CLOSED, window.state) self.assertEqual(0, len(list(state.open_windows))) self.assertTrue(state.all_windows_closed) state._attributes['window_driver_front'] = LidState.INTERMEDIATE self.assertFalse(state.all_windows_closed)
def test_lids(self): """Test features around lids.""" account = unittest.mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) state._attributes = G31_TEST_DATA['attributesMap'] for lid in state.lids: self.assertEqual(LidState.CLOSED, lid.state) self.assertEqual(0, len(list(state.open_lids))) self.assertTrue(state.all_lids_closed) state._attributes['door_driver_front'] = LidState.OPEN self.assertFalse(state.all_lids_closed)
def test_parse_g31(self): """Test if the parsing of the attributes is working.""" account = unittest.mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) state._attributes = G31_TEST_DATA['vehicleStatus'] self.assertEqual(4126, state.mileage) zone = datetime.timezone(datetime.timedelta(0, 3600)) self.assertEqual( datetime.datetime(year=2018, month=3, day=10, hour=11, minute=39, second=41, tzinfo=zone), state.timestamp) self.assertTrue(state.is_vehicle_tracking_enabled) self.assertAlmostEqual(50.5050, state.gps_position[0]) self.assertAlmostEqual(10.1010, state.gps_position[1]) self.assertAlmostEqual(33, state.remaining_fuel) self.assertAlmostEqual(321, state.remaining_range_fuel) self.assertAlmostEqual(state.remaining_range_fuel, state.remaining_range_total) self.assertEqual('VEHICLE_SHUTDOWN', state.last_update_reason) cbs = state.condition_based_services self.assertEqual(3, len(cbs)) self.assertEqual(ConditionBasedServiceStatus.OK, cbs[0].state) self.assertEqual(datetime.datetime(year=2020, month=1, day=1), cbs[0].due_date) self.assertEqual(25000, cbs[0].due_distance) self.assertEqual(ConditionBasedServiceStatus.OK, cbs[1].state) self.assertEqual(datetime.datetime(year=2022, month=1, day=1), cbs[1].due_date) self.assertEqual(60000, cbs[1].due_distance) self.assertTrue(state.are_all_cbs_ok) self.assertFalse(state.are_parking_lights_on) self.assertEqual(ParkingLightState.OFF, state.parking_lights)
def test_parse_g31(self): """Test if the parsing of the attributes is working.""" account = unittest.mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) state._attributes = G31_TEST_DATA['attributesMap'] self.assertEqual(2201, state.mileage) self.assertEqual('km', state.unit_of_length) self.assertEqual(datetime.datetime(2018, 2, 17, 12, 15, 36), state.timestamp) self.assertAlmostEqual(-34.4, state.gps_position[0]) self.assertAlmostEqual(25.26, state.gps_position[1]) self.assertAlmostEqual(19, state.remaining_fuel) self.assertEqual('l', state.unit_of_volume) self.assertAlmostEqual(202, state.remaining_range_fuel) self.assertEqual('DOORSTATECHANGED', state.last_update_reason) cbs = state.condition_based_services self.assertEqual(3, len(cbs)) self.assertEqual('00001', cbs[0].code) self.assertEqual(ConditionBasedServiceStatus.OK, cbs[0].status) self.assertEqual(datetime.datetime(year=2020, month=1, day=1), cbs[0].due_date) self.assertEqual(28000, cbs[0].due_distance) self.assertEqual('00100', cbs[1].code) self.assertEqual(ConditionBasedServiceStatus.OK, cbs[1].status) self.assertEqual(datetime.datetime(year=2022, month=1, day=1), cbs[1].due_date) self.assertEqual(60000, cbs[1].due_distance) self.assertFalse(state.are_parking_lights_on) self.assertEqual(ParkingLightState.OFF, state.parking_lights)
def test_missing_attribute(self): """Test if error handling is working correctly.""" account = unittest.mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) state._attributes = dict() self.assertIsNone(state.mileage)