Skip to content

Commit

Permalink
Merge 7c76397 into ef7b25e
Browse files Browse the repository at this point in the history
  • Loading branch information
rikroe committed Feb 18, 2020
2 parents ef7b25e + 7c76397 commit 492094d
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 26 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ install: pip install -U tox coveralls
matrix:
fast_finish: true
include:
- python: '3.4'
env: TOXENV=py34
- python: '3.5'
env: TOXENV=py35
- python: '3.6'
env: TOXENV=py36
- python: '3.7'
env: TOXENV=py37
- python: '3.8'
env: TOXENV=py38
- python: '3.6'
env: TOXENV=flake8
- python: '3.6'
Expand Down
1 change: 1 addition & 0 deletions bimmer_connected/country_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def get_server_url(region: Regions) -> str:
"""Get the url of the server for the region."""
return _SERVER_URLS[region]


def get_gcdm_oauth_endpoint(region: Regions) -> str:
"""Get the url of the server for the region."""
return _GCDM_OAUTH_ENDPOINTS[region]
8 changes: 5 additions & 3 deletions bimmer_connected/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,11 @@ def available_attributes(self) -> List[str]:
result += LIDS
result += WINDOWS
result += self.drive_train_attributes
result += ['DCS_CCH_Activation', 'DCS_CCH_Ongoing', 'condition_based_services', 'check_control_messages',
'door_lock_state', 'internalDataTimeUTC', 'lights_parking', 'lids', 'windows',
'positionLight', 'last_update_reason', 'singleImmediateCharging']
result += ['DCS_CCH_Activation', 'DCS_CCH_Ongoing', 'condition_based_services',
'check_control_messages', 'door_lock_state', 'internalDataTimeUTC',
'parking_lights', 'positionLight', 'last_update_reason', 'singleImmediateCharging']
# required for existing Home Assistant binary sensors
result += ['lights_parking', 'lids', 'windows']
return result

def get_vehicle_image(self, width: int, height: int, direction: VehicleViewDirection) -> bytes:
Expand Down
16 changes: 15 additions & 1 deletion test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
F15_VIN = 'F15_VIN'
I01_NOREX_VIN = 'I01_NOREX_VIN'
F45_VIN = 'F45_VIN'
F31_VIN = 'F31_VIN'

#: Mapping of VINs to test data directories
TEST_VEHICLE_DATA = {
Expand All @@ -26,6 +27,7 @@
I01_NOREX_VIN: 'I01_NOREX',
F15_VIN: 'F15',
F45_VIN: 'F45',
F31_VIN: 'F31',
}

_AUTH_RESPONSE_HEADERS = {
Expand All @@ -37,7 +39,10 @@
'X-NodeID': '02',
'Max-Forwards': '20',
'Date': 'Sun, 11 Mar 2018 08:16:13 GMT',
'Content-Encoding': 'gzip'}
'Content-Encoding': 'gzip',
'Location': ('https://www.bmw-connecteddrive.com/app/static/external-dispatch.html'
'#access_token=TOKEN&token_type=Bearer&expires_in=7199')
}

# VehicleState has different names than the json file. So we need to map some of the
# parameters.
Expand All @@ -63,6 +68,9 @@
'remaining_range_total', # added by bimmer_connected
'charging_time_remaining', # only present while charging
'sunroof', # not available in all vehicles
'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
]

# there attributes are not (yet) implemented
Expand All @@ -72,6 +80,8 @@
'maxRangeElectricMls', # we're not using miles
'chargingTimeRemaining', # only present while charging
'sunroof', # not available in all vehicles
'lights_parking', # required for existing Home Assistant binary sensors

]

POI_DATA = {
Expand Down Expand Up @@ -118,6 +128,10 @@ def __init__(self) -> None:
headers=_AUTH_RESPONSE_HEADERS,
data_files=['G31_NBTevo/auth_response.json'],
status_code=200),
MockResponse('https://.+/gcdm/(.+/)?oauth/authenticate',
headers=_AUTH_RESPONSE_HEADERS,
data_files=['G31_NBTevo/auth_response.json'],
status_code=302),
MockResponse('https://.+/webapi/v1/user/vehicles$',
data_files=['vehicles.json']),
]
Expand Down
7 changes: 3 additions & 4 deletions test/responses/F31/status.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"DCS_CCH_Activation": "NA",
"DCS_CCH_Ongoing": false,
"vehicleStatus": {
"DCS_CCH_Activation": "NA",
"DCS_CCH_Ongoing": false,
"position": {
"lat": 12.3456,
"lon": 34.5678,
"status": "OK"
},
"steering": "RH",
"updateTime": "2018-07-25T16:02:04+0200",
"vehicleCountry": "GB",
"vin": "some_vin"
"vin": "F31_VIN"
}
}
4 changes: 2 additions & 2 deletions test/responses/vehicles.json
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@
"steering": "RH",
"vehicleFinder": "ACTIVATED",
"vehicleFinderRestriction": "NONE",
"vin": "some_vin",
"vin": "F31_VIN",
"yearOfConstruction": 2015
},
{
Expand Down Expand Up @@ -400,7 +400,7 @@
"statisticsCommunityEnabled": false,
"steering": "LH",
"vehicleFinder": "NOT_SUPPORTED",
"vin": "some_vin",
"vin": "F31_VIN",
"yearOfConstruction": 2015
}
]
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(6, len(account.vehicles))
self.assertEqual(8, len(account.vehicles))
vehicle = account.get_vehicle(G31_VIN)
self.assertEqual(G31_VIN, vehicle.vin)

Expand Down
7 changes: 7 additions & 0 deletions test/test_remote_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,20 @@ def test_trigger_remote_services(self):
backend_mock.add_response(
r'https://.+/webapi/v1/user/vehicles/{vin}/serviceExecutionStatus\?serviceType={service_type}'.format(
vin=G31_VIN, service_type=service),
r'https://.+/webapi/v1/user/vehicles/{vin}/status'.format(
vin=G31_VIN),
data_files=[
_RESPONSE_PENDING,
_RESPONSE_PENDING,
_RESPONSE_DELIVERED,
_RESPONSE_DELIVERED,
_RESPONSE_EXECUTED])

backend_mock.add_response(
r'https://.+/webapi/v1/user/vehicles/{vin}/status'.format(
vin=G31_VIN),
data_files=[_RESPONSE_EXECUTED])

with mock.patch('bimmer_connected.account.requests', new=backend_mock):
account = ConnectedDriveAccount(TEST_USERNAME, TEST_PASSWORD, TEST_REGION)
mock_listener = mock.Mock(return_value=None)
Expand Down
12 changes: 5 additions & 7 deletions test/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ def test_no_attributes(self, _):
"""Test if error handling is working correctly."""
account = unittest.mock.MagicMock(ConnectedDriveAccount)
state = VehicleState(account, None)
with self.assertRaises(ValueError):
state.mileage # pylint: disable = pointless-statement
self.assertIsNone(state.mileage)

def test_update_data(self):
"""Test update_data method."""
Expand Down Expand Up @@ -248,9 +247,8 @@ def test_ccm_f48(self):

ccms = state.check_control_messages
self.assertEqual(1, len(ccms))

ccm = ccms[0]
self.assertEqual(955, ccm.ccm_id)
self.assertEqual(41544, ccm.mileage)
self.assertIn("Tyre pressure", ccm.description_short)
self.assertIn("continue driving", ccm.description_long)
self.assertEqual(955, ccm["ccmId"])
self.assertEqual(41544, ccm["ccmMileage"])
self.assertIn("Tyre pressure", ccm["ccmDescriptionShort"])
self.assertIn("continue driving", ccm["ccmDescriptionLong"])
5 changes: 2 additions & 3 deletions test/test_vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import unittest
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, TEST_VEHICLE_DATA, \
G31_VIN, F48_VIN, I01_VIN, I01_NOREX_VIN, F15_VIN, F45_VIN, F31_VIN, TEST_VEHICLE_DATA, \
ATTRIBUTE_MAPPING, MISSING_ATTRIBUTES, ADDITIONAL_ATTRIBUTES, POI_DATA, POI_REQUEST

from bimmer_connected.vehicle import ConnectedDriveVehicle, DriveTrainType, PointOfInterest
Expand Down Expand Up @@ -42,8 +42,7 @@ def test_drive_train_attributes(self):
account = ConnectedDriveAccount(TEST_USERNAME, TEST_PASSWORD, TEST_REGION)

for vehicle in account.vehicles:
print(vehicle.name)
self.assertEqual(vehicle.vin in [G31_VIN, F48_VIN, F15_VIN, I01_VIN, F45_VIN],
self.assertEqual(vehicle.vin in [G31_VIN, F48_VIN, F15_VIN, I01_VIN, F45_VIN, F31_VIN],
vehicle.has_internal_combustion_engine)
self.assertEqual(vehicle.vin in [I01_VIN, I01_NOREX_VIN],
vehicle.has_hv_battery)
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py34, py35, py36, pylint, flake8, docs
envlist = py36, py37, py38, pylint, flake8, docs
skip_missing_interpreters = True

[testenv]
Expand Down

0 comments on commit 492094d

Please sign in to comment.