Skip to content

Commit

Permalink
New senor values:
Browse files Browse the repository at this point in the history
- Tank Level in percentage
- Oil change maintenace
- AdBlue Range
- Parking Light
- CarType
- Primary + secondary engine range in percentage
+ Fixed negative maintenance values
  • Loading branch information
t0bias-r committed Mar 4, 2024
1 parent c258a99 commit a5004c5
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 29 deletions.
78 changes: 70 additions & 8 deletions custom_components/audiconnect/audi_connect_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ def last_update_time_supported(self):
def service_inspection_time(self):
"""Return time left for service inspection"""
if self.service_inspection_time_supported:
return -int(
return int(
self._vehicle.fields.get("MAINTENANCE_INTERVAL_TIME_TO_INSPECTION")
)

Expand All @@ -754,7 +754,7 @@ def service_inspection_time_supported(self):
def service_inspection_distance(self):
"""Return distance left for service inspection"""
if self.service_inspection_distance_supported:
return -int(
return int(
self._vehicle.fields.get("MAINTENANCE_INTERVAL_DISTANCE_TO_INSPECTION")
)

Expand All @@ -764,11 +764,25 @@ def service_inspection_distance_supported(self):
if check and parse_int(check):
return True

@property
def service_adblue_distance(self):
"""Return distance left for service inspection"""
if self.service_adblue_distance_supported:
return int(
self._vehicle.fields.get("ADBLUE_RANGE")
)

@property
def service_adblue_distance_supported(self):
check = self._vehicle.fields.get("ADBLUE_RANGE")
if check and parse_int(check):
return True

@property
def oil_change_time(self):
"""Return time left for oil change"""
if self.oil_change_time_supported:
return -int(
return int(
self._vehicle.fields.get("MAINTENANCE_INTERVAL_TIME_TO_OIL_CHANGE")
)

Expand All @@ -782,7 +796,7 @@ def oil_change_time_supported(self):
def oil_change_distance(self):
"""Return distance left for oil change"""
if self.oil_change_distance_supported:
return -int(
return int(
self._vehicle.fields.get("MAINTENANCE_INTERVAL_DISTANCE_TO_OIL_CHANGE")
)

Expand All @@ -796,12 +810,19 @@ def oil_change_distance_supported(self):
def oil_level(self):
"""Return oil level percentage"""
if self.oil_level_supported:
return float(self._vehicle.fields.get("OIL_LEVEL_DIPSTICKS_PERCENTAGE"))
val = self._vehicle.fields.get("OIL_LEVEL_DIPSTICKS_PERCENTAGE")
if type(val) is bool:
if val:
return 100
else:
return 1
if parse_float(val):
return True

@property
def oil_level_supported(self):
check = self._vehicle.fields.get("OIL_LEVEL_DIPSTICKS_PERCENTAGE")
if check and parse_float(check):
if check is not None:
return True

@property
Expand Down Expand Up @@ -850,8 +871,11 @@ def preheater_remaining(self):
def parking_light(self):
"""Return true if parking light is on"""
if self.parking_light_supported:
check = self._vehicle.fields.get("LIGHT_STATUS")
return check != "2"
try:
check = self._vehicle.fields.get("LIGHT_STATUS")
return check[0]["status"] != "off" or check[1]["status"] != "off"
except:
return False

@property
def parking_light_supported(self):
Expand Down Expand Up @@ -1248,6 +1272,18 @@ def primary_engine_range_supported(self):
if check and check != "unsupported":
return True

@property
def primary_engine_range_percent(self):
"""Return primary engine range"""
if self.primary_engine_range_percent_supported:
return self._vehicle.state.get("primaryEngineRangePercent")

@property
def primary_engine_range_percent_supported(self):
check = self._vehicle.state.get("primaryEngineRangePercent")
if check and check != "unsupported":
return True

@property
def secondary_engine_range(self):
"""Return secondary engine range"""
Expand All @@ -1260,6 +1296,32 @@ def secondary_engine_range_supported(self):
if check and check != "unsupported":
return True

@property
def car_type(self):
"""Return secondary engine range"""
if self.car_type_supported:
return self._vehicle.state.get("carType")

@property
def car_type_supported(self):
check = self._vehicle.state.get("carType")
if check and check != "unsupported":
return True

@property
def secondary_engine_range_percent(self):
"""Return secondary engine range"""
if self.secondary_engine_range_percent_supported:
return self._vehicle.state.get("secondaryEngineRangePercent")

@property
def secondary_engine_range_percent_supported(self):
check = self._vehicle.state.get("secondaryEngineRangePercent")
if check and check != "unsupported":
return True



@property
def hybrid_range(self):
"""Return hybrid range"""
Expand Down
50 changes: 32 additions & 18 deletions custom_components/audiconnect/audi_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,44 @@ def __init__(self, data):
self.data_fields = []
self.states = []

self._tryAppendFieldWithTs(data, "TOTAL_RANGE", ["fuelStatus", "rangeStatus", "value", "totalRange_km"])
self._tryAppendFieldWithTs(data, "UTC_TIME_AND_KILOMETER_STATUS", ["measurements", "odometerStatus", "value", "odometer"])
self._tryAppendFieldWithTs(data, "MAINTENANCE_INTERVAL_TIME_TO_INSPECTION", ["vehicleHealthInspection", "maintenanceStatus", "value", "inspectionDue_days"])
self._tryAppendFieldWithTs(data, "MAINTENANCE_INTERVAL_DISTANCE_TO_INSPECTION", ["vehicleHealthInspection", "maintenanceStatus", "value", "inspectionDue_km"])
self._tryAppendFieldWithTs(data, "TOTAL_RANGE", ["fuelStatus", "rangeStatus", "value", "totalRange_km"])
self._tryAppendFieldWithTs(data, "TANK_LEVEL_IN_PERCENTAGE", ["measurements", "fuelLevelStatus", "value", "currentFuelLevel_pct"])
self._tryAppendFieldWithTs(data, "UTC_TIME_AND_KILOMETER_STATUS", ["measurements", "odometerStatus", "value", "odometer"])
self._tryAppendFieldWithTs(data, "MAINTENANCE_INTERVAL_TIME_TO_INSPECTION", ["vehicleHealthInspection", "maintenanceStatus", "value", "inspectionDue_days"])
self._tryAppendFieldWithTs(data, "MAINTENANCE_INTERVAL_DISTANCE_TO_INSPECTION", ["vehicleHealthInspection", "maintenanceStatus", "value", "inspectionDue_km"])

self._tryAppendFieldWithTs(data, "MAINTENANCE_INTERVAL_TIME_TO_OIL_CHANGE", ["vehicleHealthInspection", "maintenanceStatus", "value", "oilServiceDue_days"])
self._tryAppendFieldWithTs(data, "MAINTENANCE_INTERVAL_DISTANCE_TO_OIL_CHANGE", ["vehicleHealthInspection", "maintenanceStatus", "value", "oilServiceDue_km"])

self._tryAppendFieldWithTs(data, "OIL_LEVEL_DIPSTICKS_PERCENTAGE", ["oilLevel", "oilLevelStatus", "value", "value"])
self._tryAppendFieldWithTs(data, "ADBLUE_RANGE", ["measurements", "rangeStatus", "value", "adBlueRange"])

self._tryAppendFieldWithTs(data, "LIGHT_STATUS", ["vehicleLights", "lightsStatus", "value", "lights"])


self.appendWindowState(data)
self.appendSunRoofState(data)
self.appendDoorState(data)
self.appendHoodState(data)

self._tryAppendStateWithTs(data, "carType", -1, ["fuelStatus", "rangeStatus", "value", "carType"])

self._tryAppendStateWithTs(data, "engineTypeFirstEngine", -2, ["fuelStatus", "rangeStatus", "value", "primaryEngine", "type"])
self._tryAppendStateWithTs(data, "primaryEngineRange", -2, ["fuelStatus", "rangeStatus", "value", "primaryEngine", "remainingRange_km"])
self._tryAppendStateWithTs(data, "engineTypeSecondEngine", -2, ["fuelStatus", "rangeStatus", "value", "secondaryEngine", "type"])
self._tryAppendStateWithTs(data, "secondaryEngineRange", -2, ["fuelStatus", "rangeStatus", "value", "secondaryEngine", "remainingRange_km"])
self._tryAppendStateWithTs(data, "hybridRange", -1, ["fuelStatus", "rangeStatus", "value", "totalRange_km"])

self._tryAppendStateWithTs(data, "stateOfCharge", -1, ["charging", "batteryStatus", "value", "currentSOC_pct"])
self._tryAppendStateWithTs(data, "chargingMode", -1, ["charging", "chargingStatus", "value", "chargeType"])
self._tryAppendStateWithTs(data, "actualChargeRate", -1, ["charging", "chargingStatus", "value", "chargeRate_kmph"])
self._tryAppendStateWithTs(data, "chargingPower", -1, ["charging", "chargingStatus", "value", "chargePower_kW"])
self._tryAppendStateWithTs(data, "chargeMode", -1, ["charging", "chargingStatus", "value", "chargeMode"])
self._tryAppendStateWithTs(data, "chargingState", -1, ["charging", "chargingStatus", "value", "chargingState"])
self._tryAppendStateWithTs(data, "plugState", -1, ["charging", "plugStatus", "value", "plugConnectionState"])
self._tryAppendStateWithTs(data, "remainingChargingTime", -1, ["charging", "plugStatus", "value", "remainingChargingTimeToComplete_min"])
self._tryAppendStateWithTs(data, "engineTypeFirstEngine", -2, ["fuelStatus", "rangeStatus", "value", "primaryEngine", "type"])
self._tryAppendStateWithTs(data, "primaryEngineRange", -2, ["fuelStatus", "rangeStatus", "value", "primaryEngine", "remainingRange_km"])
self._tryAppendStateWithTs(data, "primaryEngineRangePercent", -2, ["fuelStatus", "rangeStatus", "value", "primaryEngine", "currentSOC_pct"])
self._tryAppendStateWithTs(data, "engineTypeSecondEngine", -2, ["fuelStatus", "rangeStatus", "value", "secondaryEngine", "type"])
self._tryAppendStateWithTs(data, "secondaryEngineRange", -2, ["fuelStatus", "rangeStatus", "value", "secondaryEngine", "remainingRange_km"])
self._tryAppendStateWithTs(data, "secondaryEngineRangePercent", -2, ["fuelStatus", "rangeStatus", "value", "secondaryEngine", "currentSOC_pct"])
self._tryAppendStateWithTs(data, "hybridRange", -1, ["fuelStatus", "rangeStatus", "value", "totalRange_km"])

self._tryAppendStateWithTs(data, "stateOfCharge", -1, ["charging", "batteryStatus", "value", "currentSOC_pct"])
self._tryAppendStateWithTs(data, "chargingMode", -1, ["charging", "chargingStatus", "value", "chargeType"])
self._tryAppendStateWithTs(data, "actualChargeRate", -1, ["charging", "chargingStatus", "value", "chargeRate_kmph"])
self._tryAppendStateWithTs(data, "chargingPower", -1, ["charging", "chargingStatus", "value", "chargePower_kW"])
self._tryAppendStateWithTs(data, "chargeMode", -1, ["charging", "chargingStatus", "value", "chargeMode"])
self._tryAppendStateWithTs(data, "chargingState", -1, ["charging", "chargingStatus", "value", "chargingState"])
self._tryAppendStateWithTs(data, "plugState", -1, ["charging", "plugStatus", "value", "plugConnectionState"])
self._tryAppendStateWithTs(data, "remainingChargingTime", -1, ["charging", "plugStatus", "value", "remainingChargingTimeToComplete_min"])


def _tryAppendStateWithTs(self, json, name, tsoff, loc):
Expand Down
4 changes: 2 additions & 2 deletions custom_components/audiconnect/audi_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,9 +880,9 @@ async def login_request(self, user: str, password: str):

# form_data with password
# 2022-01-29: new HTML response uses a js two build the html form data + button.
# Therefore it's not possible to extract hmac and other form data.
# Therefore it's not possible to extract hmac and other form data.
# --> extract hmac from embedded js snippet.
regex_res = re.findall('"hmac"\s*:\s*"[0-9a-fA-F]+"', email_rsptxt)
regex_res = re.findall('"hmac"\\s*:\\s*"[0-9a-fA-F]+"', email_rsptxt)
if regex_res:
submit_url = submit_url.replace("identifier", "authenticate")
submit_data["hmac"] = regex_res[0].split(":")[1].strip('"')
Expand Down
1 change: 1 addition & 0 deletions custom_components/audiconnect/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"range",
"service_inspection_time",
"service_inspection_distance",
"service_adblue_distance",
"oil_change_time",
"oil_change_distance",
"oil_level",
Expand Down
20 changes: 20 additions & 0 deletions custom_components/audiconnect/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,9 @@ def create_instruments():
Lock(),
Preheater(),
Sensor(attr="model", name="Model", icon="mdi:car-info", unit=None),
Sensor(attr="service_adblue_distance", name="AdBlue Range", icon="mdi:gas-station", unit="km"),
Sensor(attr="mileage", name="Mileage", icon="mdi:speedometer", unit="km"),
Sensor(attr="service_adblue_distance", name="AdBlue range", icon="mdi:gas-station", unit="km"),
Sensor(attr="range", name="Range", icon="mdi:gas-station", unit="km"),
Sensor(
attr="service_inspection_time",
Expand Down Expand Up @@ -452,6 +454,24 @@ def create_instruments():
icon="mdi:gas-station-outline",
unit="km",
),
Sensor(
attr="primary_engine_range_percent",
name="Primary engine Percent",
icon="mdi:gas-station-outline",
unit="%",
),
Sensor(
attr="car_type",
name="Car Type",
icon="mdi:car-info",
unit=None,
),
Sensor(
attr="secondary_engine_range_percent",
name="Secondary engine Percent",
icon="mdi:gas-station-outline",
unit="%",
),
Sensor(
attr="charging_power", name="Charging power", icon="mdi:flash", unit="kW"
),
Expand Down
2 changes: 2 additions & 0 deletions custom_components/audiconnect/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"name": "Audi Connect",
"config_flow": true,
"documentation": "https://github.com/arjenvrh/audi_connect_ha",
"integration_type": "hub",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/arjenvrh/audi_connect_ha/issues",
"requirements": ["beautifulsoup4"],
"dependencies": [],
Expand Down
1 change: 0 additions & 1 deletion hacs.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"name": "Audi connect",
"domains": ["sensor", "binary_sensor", "switch", "device_tracker", "lock"],
"homeassistant": "0.110.0"
}

0 comments on commit a5004c5

Please sign in to comment.