From 82e7b09c9048294a04fbb7d315167e893931b213 Mon Sep 17 00:00:00 2001 From: Markus Eckhardt Date: Thu, 24 Sep 2020 22:09:29 +0200 Subject: [PATCH] Fixed some tests --- bimmer_connected/vehicle.py | 17 +++++++++++++++-- bimmer_connected/vehicle_status.py | 6 ++++++ test/__init__.py | 8 +++++--- test/test_account.py | 2 +- test/test_vehicle.py | 11 +++++++---- 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/bimmer_connected/vehicle.py b/bimmer_connected/vehicle.py index f5acfe7f..bbc99d7b 100644 --- a/bimmer_connected/vehicle.py +++ b/bimmer_connected/vehicle.py @@ -20,7 +20,10 @@ class DriveTrainType(Enum): #: Set of drive trains that have a combustion engine -COMBUSTION_ENGINE_DRIVE_TRAINS = {DriveTrainType.CONVENTIONAL, DriveTrainType.PHEV, DriveTrainType.BEV_REX} +COMBUSTION_ENGINE_DRIVE_TRAINS = {DriveTrainType.CONVENTIONAL, DriveTrainType.PHEV} + +#: Set of drive trains that have a range extender +RANGE_EXTENDER_DRIVE_TRAINS = {DriveTrainType.BEV_REX} #: set of drive trains that have a high voltage battery HV_BATTERY_DRIVE_TRAINS = {DriveTrainType.PHEV, DriveTrainType.BEV, DriveTrainType.BEV_REX} @@ -90,6 +93,13 @@ def has_hv_battery(self) -> bool: """ return self.drive_train in HV_BATTERY_DRIVE_TRAINS + @property + def has_range_extender(self) -> bool: + """Return True if vehicle is equipped with a range extender. + + In this case we can get the state of the gas tank.""" + return self.drive_train in RANGE_EXTENDER_DRIVE_TRAINS + @property def has_internal_combustion_engine(self) -> bool: """Return True if vehicle is equipped with an internal combustion engine. @@ -113,8 +123,11 @@ def drive_train_attributes(self) -> List[str]: 'lastChargingEndReason', 'remaining_range_electric', 'lastChargingEndResult'] if self.has_internal_combustion_engine: result += ['remaining_range_fuel'] + if self.has_hv_battery and self.has_range_extender: + result += ['maxFuel', 'remaining_range_fuel'] if self.has_hv_battery and self.has_internal_combustion_engine: - result += ['maxFuel'] + result += ['fuelPercent'] + result.remove('max_range_electric') return result @property diff --git a/bimmer_connected/vehicle_status.py b/bimmer_connected/vehicle_status.py index 9079a14d..19552ffb 100644 --- a/bimmer_connected/vehicle_status.py +++ b/bimmer_connected/vehicle_status.py @@ -335,6 +335,12 @@ def charging_level_hv(self) -> int: """State of charge of the high voltage battery in percent.""" return int(self._state.attributes[SERVICE_STATUS]['chargingLevelHv']) + @property + @backend_parameter + def fuel_percent(self) -> int: + """State of fuel in percent.""" + return int(self._state.attributes[SERVICE_STATUS]['fuelPercent']) + @property @backend_parameter def check_control_messages(self) -> List[CheckControlMessage]: diff --git a/test/__init__.py b/test/__init__.py index 482b8ebb..3bbe7c23 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -29,7 +29,7 @@ F15_VIN: 'F15', F45_VIN: 'F45', F31_VIN: 'F31', - G30_PHEV_OS7_VIN: 'G30_PHEV_OS7_VIN' + G30_PHEV_OS7_VIN: 'G30_PHEV_OS7' } _AUTH_RESPONSE_HEADERS = { @@ -62,7 +62,7 @@ 'parkingLight': 'parking_lights', 'remainingRangeFuel': 'remaining_range_fuel', 'updateTime': 'timestamp', - 'chargingTimeRemaining': 'charging_time_remaining', + 'chargingTimeRemaining': 'charging_time_remaining' } # these are additional attributes in the API, not available in the status.json @@ -73,6 +73,7 @@ 'lids', # required for existing Home Assistant binary sensors 'windows', # required for existing Home Assistant binary sensors 'lights_parking', # required for existing Home Assistant binary sensors + 'steering', # para not available in all vehicles ] # there attributes are not (yet) implemented @@ -83,7 +84,8 @@ 'chargingTimeRemaining', # only present while charging 'sunroof', # not available in all vehicles 'lights_parking', # required for existing Home Assistant binary sensors - + 'steering', # para not available in all vehicles + 'vehicleCountry', # para not available in all vehicles ] POI_DATA = { diff --git a/test/test_account.py b/test/test_account.py index 1b158209..715b9ce9 100644 --- a/test/test_account.py +++ b/test/test_account.py @@ -18,7 +18,7 @@ def test_token_vehicles(self): with mock.patch('bimmer_connected.account.requests', new=backend_mock): account = ConnectedDriveAccount(TEST_USERNAME, TEST_PASSWORD, Regions.REST_OF_WORLD) self.assertIsNotNone(account._oauth_token) - self.assertEqual(8, len(account.vehicles)) + self.assertEqual(9, len(account.vehicles)) vehicle = account.get_vehicle(G31_VIN) self.assertEqual(G31_VIN, vehicle.vin) diff --git a/test/test_vehicle.py b/test/test_vehicle.py index 6ff6a8e0..7c3aa696 100644 --- a/test/test_vehicle.py +++ b/test/test_vehicle.py @@ -3,10 +3,11 @@ from unittest import mock from test import load_response_json, BackendMock, TEST_USERNAME, TEST_PASSWORD, TEST_REGION, \ G31_VIN, F48_VIN, I01_VIN, I01_NOREX_VIN, F15_VIN, F45_VIN, F31_VIN, TEST_VEHICLE_DATA, \ - ATTRIBUTE_MAPPING, MISSING_ATTRIBUTES, ADDITIONAL_ATTRIBUTES + ATTRIBUTE_MAPPING, MISSING_ATTRIBUTES, ADDITIONAL_ATTRIBUTES, G30_PHEV_OS7_VIN from bimmer_connected.vehicle import ConnectedDriveVehicle, DriveTrainType from bimmer_connected.account import ConnectedDriveAccount +from bimmer_connected.const import SERVICE_STATUS _VEHICLES = load_response_json('vehicles.json')['vehicles'] @@ -42,10 +43,12 @@ def test_drive_train_attributes(self): account = ConnectedDriveAccount(TEST_USERNAME, TEST_PASSWORD, TEST_REGION) for vehicle in account.vehicles: - self.assertEqual(vehicle.vin in [G31_VIN, F48_VIN, F15_VIN, I01_VIN, F45_VIN, F31_VIN], + self.assertEqual(vehicle.vin in [G31_VIN, F48_VIN, F15_VIN, F45_VIN, F31_VIN, G30_PHEV_OS7_VIN], vehicle.has_internal_combustion_engine) - self.assertEqual(vehicle.vin in [I01_VIN, I01_NOREX_VIN], + self.assertEqual(vehicle.vin in [I01_VIN, I01_NOREX_VIN, G30_PHEV_OS7_VIN], vehicle.has_hv_battery) + self.assertEqual(vehicle.vin in [I01_VIN], + vehicle.has_range_extender) def test_parsing_of_lsc_type(self): """Test parsing the lsc type field.""" @@ -70,4 +73,4 @@ def test_available_attributes(self): existing_attributes = sorted([ATTRIBUTE_MAPPING.get(a, a) for a in existing_attributes if a not in MISSING_ATTRIBUTES]) expected_attributes = sorted([a for a in vehicle.available_attributes if a not in ADDITIONAL_ATTRIBUTES]) - self.assertListEqual(existing_attributes, expected_attributes) + self.assertListEqual(existing_attributes, expected_attributes) \ No newline at end of file