Skip to content

Commit

Permalink
Add charging target and ac charging limit (#516)
Browse files Browse the repository at this point in the history
* Add charging target and ac current limit
  • Loading branch information
gerard33 authored Feb 6, 2023
1 parent c84bae9 commit 3633a5d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
7 changes: 6 additions & 1 deletion bimmer_connected/vehicle/charging_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,12 @@ class ChargingProfile(VehicleDataBase):
charging_mode: ChargingMode
"""Returns the preferred charging mode."""

ac_current_limit: Optional[int] = None
"""Returns the ac current limit."""

@classmethod
def _parse_vehicle_data(cls, vehicle_data: Dict) -> Dict:
"""Parse doors and windows."""
"""Parse charging data."""
retval: Dict[str, Any] = {}

if ATTR_STATE in vehicle_data and "chargingProfile" in vehicle_data[ATTR_STATE]:
Expand All @@ -119,5 +122,7 @@ def _parse_vehicle_data(cls, vehicle_data: Dict) -> Dict:
retval["timer_type"] = TimerTypes(charging_profile.get("chargingControlType", "UNKNOWN"))
retval["charging_preferences"] = ChargingPreferences(charging_profile.get("chargingPreference", "UNKNOWN"))
retval["charging_mode"] = ChargingMode(charging_profile.get("chargingMode", "UNKNOWN"))
if "acCurrentLimit" in charging_profile["chargingSettings"]:
retval["ac_current_limit"] = charging_profile["chargingSettings"]["acCurrentLimit"]

return retval
5 changes: 5 additions & 0 deletions bimmer_connected/vehicle/fuel_and_battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class FuelAndBattery(VehicleDataBase):
is_charger_connected: bool = False
"""Get status of the connection"""

charging_target: Optional[int] = None
"""State of charging target in percent."""

account_timezone: datetime.timezone = datetime.timezone.utc

@property
Expand Down Expand Up @@ -170,6 +173,8 @@ def _parse_electric_data(
retval["charging_end_time"] = fetched_at + datetime.timedelta(
minutes=electric_data["remainingChargingMinutes"]
)
if "chargingTarget" in electric_data:
retval["charging_target"] = int(electric_data["chargingTarget"])

if retval["charging_status"] == ChargingState.WAITING_FOR_CHARGING and isinstance(charging_window, Dict):
retval["charging_start_time_no_tz"] = datetime.datetime.combine(
Expand Down
8 changes: 6 additions & 2 deletions test/test_vehicle_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ async def test_range_electric(caplog):
@time_machine.travel("2021-11-28 21:28:59 +0000", tick=False)
@pytest.mark.asyncio
async def test_charging_end_time(caplog):
"""Test if the parsing of mileage and range is working."""
"""Test charging end time."""
account = await get_mocked_account()
vehicle = account.get_vehicle(VIN_I01_NOREX)

Expand All @@ -218,6 +218,7 @@ async def test_plugged_in_waiting_for_charge_window(caplog):
assert vehicle.fuel_and_battery.charging_start_time == datetime.datetime(
2021, 11, 28, 18, 1, tzinfo=account.timezone
)
assert vehicle.fuel_and_battery.charging_target == 100

assert len(get_deprecation_warning_count(caplog)) == 0

Expand Down Expand Up @@ -405,7 +406,7 @@ async def test_check_control_messages(caplog):

@pytest.mark.asyncio
async def test_charging_profile(caplog):
"""Test parsing of the charing profile."""
"""Test parsing of the charging profile."""

charging_profile = (await get_mocked_account()).get_vehicle(VIN_I01_REX).charging_profile
assert charging_profile.is_pre_entry_climatization_enabled is False
Expand All @@ -422,4 +423,7 @@ async def test_charging_profile(caplog):
assert charging_window.start_time == datetime.time(18, 1)
assert charging_window.end_time == datetime.time(1, 30)

charging_settings = (await get_mocked_account()).get_vehicle(VIN_G01).charging_profile
assert charging_settings.ac_current_limit == 16

assert len(get_deprecation_warning_count(caplog)) == 0

0 comments on commit 3633a5d

Please sign in to comment.