Skip to content

Commit

Permalink
Merge pull request #263 from bimmerconnected/dev
Browse files Browse the repository at this point in the history
0.7.14
  • Loading branch information
rikroe committed Jan 12, 2021
2 parents 86cfb94 + b200dac commit b5ac1b5
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 13 deletions.
14 changes: 12 additions & 2 deletions bimmer_connected/all_trips.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Models the all trips of a vehicle."""

import logging
from typing import List

from bimmer_connected.const import SERVICE_ALL_TRIPS

Expand Down Expand Up @@ -101,6 +102,15 @@ def __getattr__(self, item):
"""Generic get function for all backend attributes."""
return self._state.attributes[SERVICE_ALL_TRIPS][item]

@property
def available_attributes(self) -> List[str]:
"""Get the list of all-trips attributes available for this vehicle."""
result = ['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']
return result

@property
@backend_parameter
def reset_date(self) -> str:
Expand Down Expand Up @@ -139,8 +149,8 @@ def average_electric_consumption(self) -> StatisticValues:

@property
@backend_parameter
def average_recopuration(self) -> StatisticValues:
"""Returns the average recopuration."""
def average_recuperation(self) -> StatisticValues:
"""Returns the average recuperation."""
return StatisticValues(self._state.attributes[SERVICE_ALL_TRIPS]['avgRecuperation'])

@property
Expand Down
11 changes: 9 additions & 2 deletions bimmer_connected/charging_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ def __getattr__(self, item):
"""Generic get function for all backend attributes."""
return self._state.attributes[SERVICE_CHARGING_PROFILE][item]

@property
def available_attributes(self) -> List[str]:
"""Get the list of charging-profile attributes available for this vehicle."""
result = ['is_pre_entry_climatization_enabled', 'pre_entry_climatization_timer',
'preferred_charging_window', 'charging_preferences', 'charging_mode']
return result

@property
@backend_parameter
def is_pre_entry_climatization_enabled(self) -> bool:
Expand All @@ -129,8 +136,8 @@ def pre_entry_climatization_timer(self) -> dict:

@property
@backend_parameter
def prefered_charging_window(self) -> ChargingWindow:
"""Returns the prefered charging window."""
def preferred_charging_window(self) -> ChargingWindow:
"""Returns the preferred charging window."""
return ChargingWindow(self._state.attributes[SERVICE_CHARGING_PROFILE]['preferredChargingWindow'])

@property
Expand Down
6 changes: 6 additions & 0 deletions bimmer_connected/last_destinations.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ def attributes(self) -> dict:
"""
return self._state.attributes[SERVICE_DESTINATIONS]

@property
def available_attributes(self) -> List[str]:
"""Get the list of last-destination attributes available for this vehicle."""
result = ['last_destinations']
return result

def __getattr__(self, item):
"""Generic get function for all backend attributes."""
return self._state.attributes[SERVICE_DESTINATIONS][item]
Expand Down
12 changes: 11 additions & 1 deletion bimmer_connected/last_trip.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Models the last trip of a vehicle."""

import logging
from typing import List

from bimmer_connected.const import SERVICE_LAST_TRIP

Expand Down Expand Up @@ -34,7 +35,7 @@ def __init__(self, state):
@property
@backend_parameter
def attributes(self) -> dict:
"""Retrieve all attributes from the sever.
"""Retrieve all attributes from the server.
This does not parse the results in any way.
"""
Expand All @@ -44,6 +45,15 @@ def __getattr__(self, item):
"""Generic get function for all backend attributes."""
return self._state.attributes[SERVICE_LAST_TRIP][item]

@property
def available_attributes(self) -> List[str]:
"""Get the list of last-trip attributes available for this vehicle."""
result = ['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']
return result

@property
@backend_parameter
def efficiency_value(self) -> float:
Expand Down
2 changes: 1 addition & 1 deletion bimmer_connected/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def attributes(self) -> dict:

def __getattr__(self, item):
"""Generic get function for all backend attributes."""
return self.vehicle_status.attributes[item]
return self.vehicle_status.attributes.get(item)

@staticmethod
def _parse_datetime(date_str: str) -> datetime.datetime:
Expand Down
2 changes: 1 addition & 1 deletion bimmer_connected/vehicle_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def is_vehicle_tracking_enabled(self) -> bool:
The server return "OK" if tracking is enabled and "DRIVER_DISABLED" if it is disabled in the vehicle.
"""
return self._state.attributes[SERVICE_STATUS]['position']['status'] == 'OK'
return self._state.attributes[SERVICE_STATUS]['position']['status'] not in ['DRIVER_DISABLED', 'TOO_FAR_AWAY']

@property
@backend_parameter
Expand Down
19 changes: 15 additions & 4 deletions test/test_all_trips.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ def test_parse_i01(self):
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_recopuration.community_low)
self.assertEqual(3.76, state.all_trips.average_recopuration.community_average)
self.assertEqual(14.03, state.all_trips.average_recopuration.community_high)
self.assertEqual(2.3, state.all_trips.average_recopuration.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)
Expand All @@ -50,3 +50,14 @@ def test_parse_i01(self):
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 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)
13 changes: 11 additions & 2 deletions test/test_charging_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,14 @@ def test_parse_i01(self):
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.prefered_charging_window.start_time)
self.assertEqual('17:31', state.charging_profile.prefered_charging_window.end_time)
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_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)
8 changes: 8 additions & 0 deletions test/test_last_destinations.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@ def test_parse_i01(self):
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_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)
11 changes: 11 additions & 0 deletions test/test_last_trip.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,14 @@ def test_parse_i01(self):
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_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)

0 comments on commit b5ac1b5

Please sign in to comment.