Skip to content

Commit

Permalink
Fixed some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Markinus committed Sep 24, 2020
1 parent 223bdaa commit 82e7b09
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
17 changes: 15 additions & 2 deletions bimmer_connected/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions bimmer_connected/vehicle_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
8 changes: 5 additions & 3 deletions test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion test/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
11 changes: 7 additions & 4 deletions test/test_vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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."""
Expand All @@ -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)

0 comments on commit 82e7b09

Please sign in to comment.