Skip to content

Commit

Permalink
new status and attributes added
Browse files Browse the repository at this point in the history
  • Loading branch information
tillsteinbach committed Oct 16, 2023
1 parent 66dffc3 commit b85300d
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2 deletions.
11 changes: 11 additions & 0 deletions weconnect/elements/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ class CarType(Enum,):
UNKNOWN = 'unknown car type'


class EngineType(Enum,):
GASOLINE = 'gasoline'
ELECTRIC = 'electric'
PETROL = 'petrol'
DIESEL = 'diesel'
CNG = 'cng'
LPG = 'lpg'
INVALID = 'invalid'
UNKNOWN = 'unknown engine type'


class SpinState(Enum,):
DEFINED = 'DEFINED'
UNKNOWN = 'unknown spin state'
63 changes: 63 additions & 0 deletions weconnect/elements/fuel_level_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import logging

from weconnect.addressable import AddressableAttribute
from weconnect.elements.generic_status import GenericStatus
from weconnect.elements.enums import EngineType, CarType

LOG = logging.getLogger("weconnect")


class FuelLevelStatus(GenericStatus):
def __init__(
self,
vehicle,
parent,
statusId,
fromDict=None,
fixAPI=True,
):
self.currentFuelLevel_pct = AddressableAttribute(localAddress='currentFuelLevel_pct', parent=self, value=None, valueType=int)
self.currentSOC_pct = AddressableAttribute(localAddress='currentSOC_pct', parent=self, value=None, valueType=int)
self.primaryEngineType = AddressableAttribute(localAddress='primaryEngineType', parent=self, value=None, valueType=EngineType)
self.secondaryEngineType = AddressableAttribute(localAddress='secondaryEngineType', parent=self, value=None, valueType=EngineType)
self.carType = AddressableAttribute(localAddress='carType', parent=self, value=None, valueType=CarType)

super().__init__(vehicle=vehicle, parent=parent, statusId=statusId, fromDict=fromDict, fixAPI=fixAPI)

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

if 'value' in fromDict:
self.currentFuelLevel_pct.fromDict(fromDict['value'], 'currentFuelLevel_pct')
self.currentSOC_pct.fromDict(fromDict['value'], 'currentSOC_pct')
self.primaryEngineType.fromDict(fromDict['value'], 'primaryEngineType')
self.secondaryEngineType.fromDict(fromDict['value'], 'secondaryEngineType')
self.carType.fromDict(fromDict['value'], 'carType')
else:
self.currentFuelLevel_pct.enabled = False
self.currentSOC_pct.enabled = False
self.primaryEngineType.enabled = False
self.secondaryEngineType.enabled = False
self.carType.enabled = False

super().update(fromDict=fromDict, ignoreAttributes=(ignoreAttributes
+ ['currentFuelLevel_pct',
'currentSOC_pct',
'primaryEngineType',
'secondaryEngineType',
'carType']))

def __str__(self):
string = super().__str__()
if self.carType.enabled:
string += f'\n\tCar Type: {self.carType.value.value}' # pylint: disable=no-member
if self.primaryEngineType.enabled:
string += f'\n\tPrimary Engine: {self.primaryEngineType.value.value}'
if self.secondaryEngineType.enabled:
string += f'\n\tSecondary Engine: {self.secondaryEngineType.value.value}'
if self.currentFuelLevel_pct.enabled:
string += f'\n\tCurrent Fuel Level: {self.currentFuelLevel_pct.value}%'
if self.currentSOC_pct.enabled:
string += f'\n\tCurrent Charge Level: {self.currentSOC_pct.value}%'
return string
8 changes: 7 additions & 1 deletion weconnect/elements/range_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def __init__(
fromDict=None,
fixAPI=True,
):
self.totalRange_km = AddressableAttribute(
localAddress='totalRange_km', value=None, parent=self, valueType=int)
self.electricRange = AddressableAttribute(
localAddress='electricRange', parent=self, value=None, valueType=int)
self.gasolineRange = AddressableAttribute(
Expand All @@ -30,21 +32,25 @@ def update(self, fromDict, ignoreAttributes=None):
LOG.debug('Update battery status from dict')

if 'value' in fromDict:
self.totalRange_km.fromDict(fromDict['value'], 'totalRange_km')
self.electricRange.fromDict(fromDict['value'], 'electricRange')
self.gasolineRange.fromDict(fromDict['value'], 'gasolineRange')
self.adBlueRange.fromDict(fromDict['value'], 'adBlueRange')
self.dieselRange.fromDict(fromDict['value'], 'dieselRange')
else:
self.totalRange_km.enabled = False
self.electricRange.enabled = False
self.gasolineRange.enabled = False
self.adBlueRange.enabled = False
self.dieselRange.enabled = False

super().update(fromDict=fromDict, ignoreAttributes=(
ignoreAttributes + ['electricRange', 'gasolineRange', 'adBlueRange', 'dieselRange']))
ignoreAttributes + ['totalRange_km', 'electricRange', 'gasolineRange', 'adBlueRange', 'dieselRange']))

def __str__(self):
string = super().__str__()
if self.totalRange_km.enabled:
string += f'\n\tTotal Range: {self.totalRange_km.value}km'
if self.electricRange.enabled:
string += f'\n\tElectric Range: {self.electricRange.value}km'
if self.gasolineRange.enabled:
Expand Down
2 changes: 1 addition & 1 deletion weconnect/elements/range_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(

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

if 'value' in fromDict:
self.carType.fromDict(fromDict['value'], 'carType')
Expand Down
3 changes: 3 additions & 0 deletions weconnect/elements/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from weconnect.elements.climatization_settings import ClimatizationSettings
from weconnect.elements.climatization_timer import ClimatizationTimer
from weconnect.elements.departure_timers_status import DepartureTimersStatus
from weconnect.elements.fuel_level_status import FuelLevelStatus
from weconnect.elements.lights_status import LightsStatus
from weconnect.elements.maintenance_status import MaintenanceStatus
from weconnect.elements.warning_lights_status import WarningLightsStatus
Expand Down Expand Up @@ -304,6 +305,8 @@ def updateStatus(self, updateCapabilities: bool = True, force: bool = False, #
'odometerStatus': OdometerMeasurement,
'oilLevelStatus': GenericStatus,
'measurements': GenericStatus,
'temperatureBatteryStatus': GenericStatus,
'fuelLevelStatus': FuelLevelStatus,
},
Domain.BATTERY_SUPPORT: {
'batterySupportStatus': BatterySupportStatus,
Expand Down

0 comments on commit b85300d

Please sign in to comment.