Skip to content

Commit

Permalink
Add attributes reported from ID.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Lake292 authored Jun 13, 2024
1 parent 13879cf commit 3132ffd
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
8 changes: 7 additions & 1 deletion weconnect/elements/battery_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def __init__(
):
self.currentSOC_pct = AddressableAttribute(
localAddress='currentSOC_pct', parent=self, value=None, valueType=int)
self.navigationTargetSOC_pct = AddressableAttribute(
localAddress='navigationTargetSOC_pct', parent=self, value=None, valueType=int)
self.cruisingRangeElectric_km = AddressableAttribute(
localAddress='cruisingRangeElectric_km', value=None, parent=self, valueType=int)
super().__init__(vehicle=vehicle, parent=parent, statusId=statusId, fromDict=fromDict, fixAPI=fixAPI)
Expand Down Expand Up @@ -45,17 +47,21 @@ def update(self, fromDict, ignoreAttributes=None):
self.cruisingRangeElectric_km.enabled = False

self.currentSOC_pct.fromDict(fromDict['value'], 'currentSOC_pct')
self.navigationTargetSOC_pct.fromDict(fromDict['value'], 'navigationTargetSOC_pct')
else:
self.currentSOC_pct.enabled = False
self.cruisingRangeElectric_km.enabled = False
self.navigationTargetSOC_pct.enabled = False

super().update(fromDict=fromDict, ignoreAttributes=(
ignoreAttributes + ['currentSOC_pct', 'cruisingRangeElectric_km']))
ignoreAttributes + ['currentSOC_pct', 'navigationTargetSOC_pct', 'cruisingRangeElectric_km']))

def __str__(self):
string = super().__str__()
if self.currentSOC_pct.enabled:
string += f'\n\tCurrent SoC: {self.currentSOC_pct.value}%'
if self.navigationTargetSOC_pct.enabled:
string += f'\n\tNavigation Target SoC: {self.navigationTargetSOC_pct.value}%'
if self.cruisingRangeElectric_km.enabled:
if self.cruisingRangeElectric_km.value is not None:
string += f'\n\tRange: {self.cruisingRangeElectric_km.value}km'
Expand Down
2 changes: 1 addition & 1 deletion weconnect/elements/temperature_battery_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(

def update(self, fromDict, ignoreAttributes=None):
ignoreAttributes = ignoreAttributes or []
LOG.debug('Update range status from dict')
LOG.debug('Update battery temperature status from dict')

if 'value' in fromDict:
self.temperatureHvBatteryMin_K.fromDict(fromDict['value'], 'temperatureHvBatteryMin_K')
Expand Down
39 changes: 39 additions & 0 deletions weconnect/elements/temperature_outside_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import logging

from weconnect.addressable import AddressableAttribute
from weconnect.elements.generic_status import GenericStatus
from weconnect.util import kelvinToCelsius

LOG = logging.getLogger("weconnect")


class TemperatureOutsideStatus(GenericStatus):
def __init__(
self,
vehicle,
parent,
statusId,
fromDict=None,
fixAPI=True,
):
self.temperatureOutside_K = AddressableAttribute(localAddress='temperatureOutside_K', parent=self, value=None, valueType=float)
super().__init__(vehicle=vehicle, parent=parent, statusId=statusId, fromDict=fromDict, fixAPI=fixAPI)

def update(self, fromDict, ignoreAttributes=None):
ignoreAttributes = ignoreAttributes or []
LOG.debug('Update outside temperature status from dict')

if 'value' in fromDict:
self.temperatureOutside_K.fromDict(fromDict['value'], 'temperatureOutside_K')

else:
self.temperatureOutside_K.enabled = False

super().update(fromDict=fromDict, ignoreAttributes=(ignoreAttributes
+ ['temperatureOutside_K']))

def __str__(self):
string = super().__str__()
if self.temperatureOutside_K.enabled:
string += f'\n\tOutside temperature {kelvinToCelsius(self.temperatureOutside_K.value)}°C'
return string
2 changes: 2 additions & 0 deletions weconnect/elements/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from weconnect.elements.range_measurements import RangeMeasurements
from weconnect.elements.readiness_status import ReadinessStatus
from weconnect.elements.temperature_battery_status import TemperatureBatteryStatus
from weconnect.elements.temperature_outside_status import TemperatureOutsideStatus
from weconnect.elements.charging_profiles import ChargingProfiles
from weconnect.elements.trip import Trip
from weconnect.errors import APICompatibilityError, RetrievalError, APIError, TooManyRequestsError
Expand Down Expand Up @@ -309,6 +310,7 @@ def updateStatus(self, updateCapabilities: bool = True, force: bool = False, #
'oilLevelStatus': GenericStatus,
'measurements': GenericStatus,
'temperatureBatteryStatus': TemperatureBatteryStatus,
'temperatureOutsideStatus': TemperatureOutsideStatus,
'fuelLevelStatus': FuelLevelStatus,
},
Domain.BATTERY_SUPPORT: {
Expand Down

0 comments on commit 3132ffd

Please sign in to comment.