def test_parse_i01(self): """Test if the parsing of the attributes is working.""" account = mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) state._attributes[SERVICE_CHARGING_PROFILE] = I01_TEST_DATA[ 'weeklyPlanner'] self.assertTrue( state.charging_profile.is_pre_entry_climatization_enabled) self.assertEqual(ChargingMode.DELAYED_CHARGING, state.charging_profile.charging_mode) self.assertEqual(ChargingPreferences.CHARGING_WINDOW, state.charging_profile.charging_preferences) self.assertTrue(state.charging_profile.pre_entry_climatization_timer[ TimerTypes.TIMER_1].timer_enabled) self.assertEqual( '07:30', state.charging_profile.pre_entry_climatization_timer[ TimerTypes.TIMER_1].departure_time) self.assertEqual( 'MONDAY', state.charging_profile.pre_entry_climatization_timer[ TimerTypes.TIMER_1].weekdays[0]) self.assertEqual( '05:02', state.charging_profile.preferred_charging_window.start_time) self.assertEqual( '17:31', state.charging_profile.preferred_charging_window.end_time)
def test_parse_g30_phev_os7(self): """Test if the parsing of the attributes is working.""" account = mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) state._attributes[SERVICE_NAVIGATION] = G30_PHEV_OS7_TEST_DATA self.assertEqual(52.82273, state.navigation.latitude) self.assertEqual(8.8276, state.navigation.longitude) self.assertEqual('DEU', state.navigation.iso_country_code) self.assertEqual(1.4, state.navigation.aux_power_regular) self.assertEqual(1.2, state.navigation.aux_power_eco_pro) self.assertEqual(0.4, state.navigation.aux_power_eco_pro_plus) self.assertEqual(4.98700008381234, state.navigation.soc) self.assertEqual(9.48, state.navigation.soc_max) self.assertIsNone(state.navigation.eco) self.assertIsNone(state.navigation.norm) self.assertIsNone(state.navigation.eco_ev) self.assertIsNone(state.navigation.norm_ev) self.assertIsNone(state.navigation.vehicle_mass) self.assertIsNone(state.navigation.k_acc_reg) self.assertIsNone(state.navigation.k_dec_reg) self.assertIsNone(state.navigation.k_acc_eco) self.assertIsNone(state.navigation.k_dec_eco) self.assertIsNone(state.navigation.k_up) self.assertIsNone(state.navigation.k_down) self.assertIsNone(state.navigation.drive_train) self.assertFalse(state.navigation.pending_update) self.assertFalse(state.navigation.vehicle_tracking)
def __init__(self, account, attributes: dict) -> None: self._account = account self.attributes = attributes self.state = VehicleState(account, self) self.remote_services = RemoteServices(account, self) self.observer_latitude = 0.0 # type: float self.observer_longitude = 0.0 # type: float
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_available_attributes(self): """Check available_attributes for last_destination service.""" account = mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) expected_attributes = ['last_destinations'] existing_attributes = state.last_destinations.available_attributes self.assertListEqual(existing_attributes, expected_attributes)
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_available_attributes(self): """Check available_attributes for last_trip service.""" account = mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) expected_attributes = ['acceleration_value', 'anticipation_value', 'auxiliary_consumption_value', 'average_combined_consumption', 'average_electric_consumption', 'average_recuperation', 'date', 'driving_mode_value', 'duration', 'efficiency_value', 'electric_distance', 'electric_distance_ratio', 'saved_fuel', 'total_consumption_value', 'total_distance'] existing_attributes = state.last_trip.available_attributes self.assertListEqual(existing_attributes, expected_attributes)
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_available_attributes(self): """Check available_attributes for all_trips service.""" account = mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) expected_attributes = ['average_combined_consumption', 'average_electric_consumption', 'average_recuperation', 'battery_size_max', 'chargecycle_range', 'reset_date', 'saved_co2', 'saved_co2_green_energy', 'total_electric_distance', 'total_saved_fuel'] existing_attributes = state.all_trips.available_attributes self.assertListEqual(existing_attributes, expected_attributes)
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_available_attributes(self): """Check available_attributes for charging_profile service.""" account = mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) expected_attributes = [ 'is_pre_entry_climatization_enabled', 'pre_entry_climatization_timer', 'preferred_charging_window', 'charging_preferences', 'charging_mode' ] existing_attributes = state.charging_profile.available_attributes self.assertListEqual(existing_attributes, expected_attributes)
def test_parse_i01(self): """Test if the parsing of the attributes is working.""" account = mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) state._attributes[SERVICE_DESTINATIONS] = I01_TEST_DATA['destinations'] self.assertEqual(DestinationType.DESTINATION, state.last_destinations.last_destinations[0].destination_type) self.assertEqual(51.53053283691406, state.last_destinations.last_destinations[0].latitude) self.assertEqual(-0.08362331241369247, state.last_destinations.last_destinations[0].longitude) self.assertEqual('UNITED KINGDOM', state.last_destinations.last_destinations[0].country) self.assertEqual('LONDON', state.last_destinations.last_destinations[0].city) self.assertEqual('PITFIELD STREET', state.last_destinations.last_destinations[0].street) self.assertEqual('2015-09-25T08:06:11+0200', state.last_destinations.last_destinations[0].created_at)
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_parse_g31_no_position_vehicle_active(self): """Test parsing of G31 data with vehicle beeing active.""" account = unittest.mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) state._attributes[ SERVICE_STATUS] = G31_NO_POSTITION_VEHICLE_ACTIVE_TEST_DATA[ 'vehicleStatus'] self.assertTrue(state.vehicle_status.is_vehicle_tracking_enabled) self.assertTrue(state.vehicle_status.is_vehicle_active) self.assertIsNone(state.vehicle_status.gps_position) self.assertIsNone(state.vehicle_status.gps_heading)
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[SERVICE_STATUS] = G31_TEST_DATA['vehicleStatus'] self.assertEqual(4126, state.vehicle_status.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.vehicle_status.timestamp) 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) self.assertAlmostEqual(321, state.vehicle_status.remaining_range_fuel) self.assertAlmostEqual(state.vehicle_status.remaining_range_fuel, state.vehicle_status.remaining_range_total) self.assertEqual('VEHICLE_SHUTDOWN', state.vehicle_status.last_update_reason) cbs = state.vehicle_status.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.vehicle_status.are_all_cbs_ok) self.assertFalse(state.vehicle_status.are_parking_lights_on) self.assertEqual(ParkingLightState.OFF, state.vehicle_status.parking_lights)
def test_lids(self): """Test features around lids.""" account = unittest.mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) state._attributes[SERVICE_STATUS] = G31_TEST_DATA['vehicleStatus'] for lid in state.vehicle_status.lids: self.assertEqual(LidState.CLOSED, lid.state) self.assertEqual(6, len(list(state.vehicle_status.lids))) self.assertEqual(0, len(list(state.vehicle_status.open_lids))) self.assertTrue(state.vehicle_status.all_lids_closed) state._attributes[SERVICE_STATUS]['doorDriverFront'] = LidState.OPEN self.assertFalse(state.vehicle_status.all_lids_closed)
def test_windows_g31(self): """Test features around lids.""" account = unittest.mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) state._attributes[SERVICE_STATUS] = G31_TEST_DATA['vehicleStatus'] for window in state.vehicle_status.windows: self.assertEqual(LidState.CLOSED, window.state) self.assertEqual(5, len(list(state.vehicle_status.windows))) self.assertEqual(0, len(list(state.vehicle_status.open_windows))) self.assertTrue(state.vehicle_status.all_windows_closed) state._attributes[SERVICE_STATUS][ 'windowDriverFront'] = LidState.INTERMEDIATE self.assertFalse(state.vehicle_status.all_windows_closed)
def test_parse_i01(self): """Test if the parsing of the attributes is working.""" account = mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) state._attributes[SERVICE_RANGEMAP] = I01_TEST_DATA['rangemap'] self.assertEqual(RangeMapQuality.AVERAGE, state.range_maps.range_map_quality) self.assertEqual(51.123456, state.range_maps.range_map_center.latitude) self.assertEqual(-1.2345678, state.range_maps.range_map_center.longitude) self.assertEqual(RangeMapType.ECO_PRO_PLUS, state.range_maps.range_maps[0].range_map_type) self.assertEqual(51.6991281509399, state.range_maps.range_maps[0].polyline[0].latitude) self.assertEqual(-2.00423240661621, state.range_maps.range_maps[0].polyline[0].longitude)
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['vehicleStatus'] self.assertEqual(21529, state.mileage) zone = datetime.timezone(datetime.timedelta(0, 3600)) self.assertEqual( datetime.datetime(year=2018, month=3, day=10, hour=19, minute=35, second=30, tzinfo=zone), state.timestamp) self.assertTrue(state.is_vehicle_tracking_enabled) self.assertAlmostEqual(50.505050, state.gps_position[0]) self.assertAlmostEqual(10.1010101, state.gps_position[1]) self.assertAlmostEqual(39, state.remaining_fuel) self.assertAlmostEqual(590, state.remaining_range_fuel) self.assertEqual('DOOR_STATE_CHANGED', 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=2019, month=7, day=1), cbs[0].due_date) self.assertEqual(9000, cbs[0].due_distance) self.assertEqual(ConditionBasedServiceStatus.OK, cbs[1].state) self.assertEqual(datetime.datetime(year=2021, month=7, day=1), cbs[1].due_date) self.assertEqual(39000, 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_i01(self): """Test if the parsing of the attributes is working.""" account = mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) state._attributes[SERVICE_LAST_TRIP] = I01_TEST_DATA['lastTrip'] self.assertEqual(0.53, state.last_trip.efficiencyValue) self.assertEqual(141, state.last_trip.total_distance) self.assertEqual(100.1, state.last_trip.electric_distance) self.assertEqual(16.6, state.last_trip.averege_electric_consumption) self.assertEqual(2, state.last_trip.averege_recuperation) self.assertEqual(0, state.last_trip.driving_mode_value) self.assertEqual(0.39, state.last_trip.acceleration_value) self.assertEqual(0.81, state.last_trip.anticipation_value) self.assertEqual(0.79, state.last_trip.total_consumption_value) self.assertEqual(0.66, state.last_trip.auxiliary_consumption_value) self.assertEqual(1.9, state.last_trip.averege_combined_consumption) self.assertEqual(71, state.last_trip.electric_distance_ratio) self.assertEqual(0, state.last_trip.saved_fuel) self.assertEqual('2015-12-01T20:44:00+0100', state.last_trip.date) self.assertEqual(124, state.last_trip.duration)
def test_parse_g30_phev_os7(self): """Test if the parsing of the attributes is working.""" account = mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) state._attributes[SERVICE_EFFICIENCY] = G30_PHEV_OS7_TEST_DATA self.assertEqual('PHEV', state.efficiency.model_type) self.assertEqual(0, state.efficiency.efficiency_quotient) self.assertEqual('LASTTRIP_DELTA_KM', state.efficiency.last_trip_list[0].name) self.assertEqual('KM', state.efficiency.last_trip_list[0].unit) self.assertEqual('--', state.efficiency.last_trip_list[0].last_trip) self.assertEqual('TIMESTAMP_STATISTICS_RESET', state.efficiency.life_time_list[2].name) self.assertIsNone(state.efficiency.life_time_list[2].unit) self.assertEqual('12.01.2020', state.efficiency.life_time_list[2].life_time) self.assertEqual( 'DRIVING_MODE', state.efficiency.characteristic_list[1].characteristic) self.assertEqual(0, state.efficiency.characteristic_list[1].quantity)
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_parse_i01(self): """Test if the parsing of the attributes is working.""" account = mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) state._attributes[SERVICE_ALL_TRIPS] = I01_TEST_DATA['allTrips'] self.assertEqual('1970-01-01T01:00:00+0100', state.all_trips.reset_date) self.assertEqual(35820, state.all_trips.battery_size_max) self.assertEqual(87.58, state.all_trips.saved_co2) self.assertEqual(515.177, state.all_trips.saved_co2_green_energy) self.assertEqual(0, state.all_trips.total_saved_fuel) self.assertEqual(0, state.all_trips.average_electric_consumption.community_low) self.assertEqual(16.33, state.all_trips.average_electric_consumption.community_average) self.assertEqual(35.53, state.all_trips.average_electric_consumption.community_high) self.assertEqual(14.76, state.all_trips.average_electric_consumption.user_average) self.assertEqual(0, state.all_trips.average_recuperation.community_low) self.assertEqual(3.76, state.all_trips.average_recuperation.community_average) self.assertEqual(14.03, state.all_trips.average_recuperation.community_high) self.assertEqual(2.3, state.all_trips.average_recuperation.user_average) self.assertEqual(121.58, state.all_trips.chargecycle_range.community_average) self.assertEqual(200, state.all_trips.chargecycle_range.community_high) self.assertEqual(72.62, state.all_trips.chargecycle_range.user_average) self.assertEqual(135, state.all_trips.chargecycle_range.user_high) self.assertEqual(60, state.all_trips.chargecycle_range.user_current_charge_cycle) self.assertEqual(1, state.all_trips.total_electric_distance.community_low) self.assertEqual(12293.65, state.all_trips.total_electric_distance.community_average) self.assertEqual(77533.6, state.all_trips.total_electric_distance.community_high) self.assertEqual(3158.66, state.all_trips.total_electric_distance.user_total) self.assertEqual(0, state.all_trips.average_combined_consumption.community_low) self.assertEqual(1.21, state.all_trips.average_combined_consumption.community_average) self.assertEqual(6.2, state.all_trips.average_combined_consumption.community_high) self.assertEqual(0.36, state.all_trips.average_combined_consumption.user_average)
def __init__(self, account, attributes: dict) -> None: self._account = account self.attributes = attributes self.state = VehicleState(account, self) self.remote_services = RemoteServices(account, self) self.specs = VehicleSpecs(account, self)
def test_no_attributes(self, _): """Test if error handling is working correctly.""" account = unittest.mock.MagicMock(ConnectedDriveAccount) state = VehicleState(account, None) self.assertIsNone(state.mileage)