Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update audi_connect_account.py #5

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions custom_components/audiconnect/audi_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@


class AudiAPI:
HDR_XAPP_VERSION = "4.16.0"
HDR_USER_AGENT = "myAudi-Android/4.13.0 (Build 800238275.2210271555) Android/11"
HDR_XAPP_VERSION = "4.23.1"
HDR_USER_AGENT = "Android/4.23.1 (Build 800240120.root project 'onetouch-android'.ext.buildTime) Android/11"

def __init__(self, session, proxy=None):
self.__token = None
Expand Down Expand Up @@ -60,7 +60,7 @@ async def request(
return response, txt
elif raw_contents:
return await response.read()
elif response.status == 200 or response.status == 202:
elif response.status == 200 or response.status == 202 or response.status == 207:
return await response.json(loads=json_loads)
else:
raise ClientResponseError(
Expand Down
113 changes: 81 additions & 32 deletions custom_components/audiconnect/audi_connect_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ def log_exception_once(self, exception, message):
err = message + ": " + str(exception).rstrip("\n")
if not err in self._logged_errors:
self._logged_errors.add(err)
_LOGGER.error(err)
_LOGGER.error(err, exc_info=True)

async def update_vehicle_statusreport(self):
if not self.support_status_report:
Expand All @@ -439,6 +439,8 @@ async def update_vehicle_statusreport(self):
for i in range(0, len(status.data_fields))
}
self._vehicle.state["last_update_time"] = status.data_fields[0].send_time
for state in status.states:
self._vehicle.state[state["name"]] = state["value"]

except TimeoutError:
raise
Expand Down Expand Up @@ -471,22 +473,12 @@ async def update_vehicle_position(self):

try:
resp = await self._audi_service.get_stored_position(self._vehicle.vin)
if resp.get("findCarResponse") is not None:
position = resp["findCarResponse"]

if (
position.get("Position") is not None
and position["Position"].get("carCoordinate") is not None
):
if resp is not None:
self._vehicle.state["position"] = {
"latitude": get_attr(position, "Position.carCoordinate.latitude")
/ 1000000,
"longitude": get_attr(position, "Position.carCoordinate.longitude")
/ 1000000,
"timestamp": get_attr(position, "Position.timestampCarSentUTC"),
"parktime": position.get("parkingTimeUTC")
if position.get("parkingTimeUTC") is not None
else get_attr(position, "Position.timestampCarSentUTC"),
"latitude": resp["data"]["lat"],
"longitude": resp["data"]["lon"],
"timestamp": resp["data"]["carCapturedTimestamp"],
"parktime": resp["data"]["carCapturedTimestamp"]
}

except TimeoutError:
Expand Down Expand Up @@ -613,7 +605,7 @@ async def update_vehicle_charger(self):
result, "charger.status.chargingStatusData.actualChargeRate.content"
)
if self._vehicle.state["actualChargeRate"] is not None:
self._vehicle.state["actualChargeRate"] = float(self._vehicle.state["actualChargeRate"]) / 10
self._vehicle.state["actualChargeRate"] = float(self._vehicle.state["actualChargeRate"])
self._vehicle.state["actualChargeRateUnit"] = get_attr(
result, "charger.status.chargingStatusData.chargeRateUnit.content"
)
Expand Down Expand Up @@ -748,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 @@ -762,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 @@ -772,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 @@ -790,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 @@ -804,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 @@ -858,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 @@ -1203,19 +1219,14 @@ def actual_charge_rate_supported(self):

@property
def actual_charge_rate_unit(self):
if self.actual_charge_rate_supported:
res = self._vehicle.state.get("actualChargeRateUnit")
if res:
return res.replace("_per_", "/")

return res
return "km/h"

@property
def charging_power(self):
"""Return charging power"""
if self.charging_power_supported:
try:
return parse_int(self._vehicle.state.get("chargingPower")) / 1000
return parse_float(self._vehicle.state.get("chargingPower"))
except ValueError:
return -1

Expand Down Expand Up @@ -1261,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 @@ -1273,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
Loading