Skip to content

Commit

Permalink
Merge pull request #188 from t0bias-r/master
Browse files Browse the repository at this point in the history
Fixed reading charge properties eq 0 and removed unnecessary error messages
  • Loading branch information
arjenvrh authored Sep 13, 2023
2 parents 0c0eba5 + 9b1d968 commit b693a26
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 34 deletions.
72 changes: 41 additions & 31 deletions custom_components/audiconnect/audi_connect_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,11 @@ async def update_vehicle_statusreport(self):
raise
except ClientResponseError as resp_exception:
if resp_exception.status == 403 or resp_exception.status == 502:
_LOGGER.error(
"support_status_report set to False: {status}".format(
status=resp_exception.status
)
)
#_LOGGER.error(
# "support_status_report set to False: {status}".format(
# status=resp_exception.status
# )
#)
self.support_status_report = False
else:
self.log_exception_once(
Expand Down Expand Up @@ -493,11 +493,11 @@ async def update_vehicle_position(self):
raise
except ClientResponseError as resp_exception:
if resp_exception.status == 403 or resp_exception.status == 502:
_LOGGER.error(
"support_position set to False: {status}".format(
status=resp_exception.status
)
)
#_LOGGER.error(
# "support_position set to False: {status}".format(
# status=resp_exception.status
# )
#)
self.support_position = False
# If error is 204 is returned, the position is currently not available
elif resp_exception.status != 204:
Expand Down Expand Up @@ -537,11 +537,11 @@ async def update_vehicle_climater(self):
raise
except ClientResponseError as resp_exception:
if resp_exception.status == 403 or resp_exception.status == 502:
_LOGGER.error(
"support_climater set to False: {status}".format(
status=resp_exception.status
)
)
#_LOGGER.error(
# "support_climater set to False: {status}".format(
# status=resp_exception.status
# )
#)
self.support_climater = False
else:
self.log_exception_once(
Expand Down Expand Up @@ -574,11 +574,11 @@ async def update_vehicle_preheater(self):
raise
except ClientResponseError as resp_exception:
if resp_exception.status == 403 or resp_exception.status == 502:
_LOGGER.error(
"support_preheater set to False: {status}".format(
status=resp_exception.status
)
)
#_LOGGER.error(
# "support_preheater set to False: {status}".format(
# status=resp_exception.status
# )
#)
self.support_preheater = False
else:
self.log_exception_once(
Expand Down Expand Up @@ -663,11 +663,11 @@ async def update_vehicle_charger(self):
raise
except ClientResponseError as resp_exception:
if resp_exception.status == 403 or resp_exception.status == 502:
_LOGGER.error(
"support_charger set to False: {status}".format(
status=resp_exception.status
)
)
#_LOGGER.error(
# "support_charger set to False: {status}".format(
# status=resp_exception.status
# )
#)
self.support_charger = False
else:
self.log_exception_once(
Expand Down Expand Up @@ -1174,24 +1174,31 @@ def energy_flow_supported(self):
def max_charge_current(self):
"""Return max charge current"""
if self.max_charge_current_supported:
return parse_float(self._vehicle.state.get("maxChargeCurrent"))
try:
return parse_float(self._vehicle.state.get("maxChargeCurrent"))
except ValueError:
return -1

@property
def max_charge_current_supported(self):
check = self._vehicle.state.get("maxChargeCurrent")
if check and parse_float(check):
if check is not None:
return True

@property
def actual_charge_rate(self):
"""Return actual charge rate"""
if self.actual_charge_rate_supported:
return parse_float(self._vehicle.state.get("actualChargeRate"))
try:
return parse_float(self._vehicle.state.get("actualChargeRate"))
except ValueError:
return -1


@property
def actual_charge_rate_supported(self):
check = self._vehicle.state.get("actualChargeRate")
if check and parse_float(check):
if check is not None:
return True

@property
Expand All @@ -1207,12 +1214,15 @@ def actual_charge_rate_unit(self):
def charging_power(self):
"""Return charging power"""
if self.charging_power_supported:
return parse_int(self._vehicle.state.get("chargingPower")) / 1000
try:
return parse_int(self._vehicle.state.get("chargingPower")) / 1000
except ValueError:
return -1

@property
def charging_power_supported(self):
check = self._vehicle.state.get("chargingPower")
if check and parse_int(check):
if check is not None:
return True

@property
Expand Down
1 change: 0 additions & 1 deletion custom_components/audiconnect/audi_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,5 @@ def device_info(self):
"identifiers": {(DOMAIN, self._instrument.vehicle_name)},
"manufacturer": "Audi",
"name": self._vehicle_name,
"device_type": self._component,
"model": self._instrument.vehicle_model_family,
}
3 changes: 2 additions & 1 deletion custom_components/audiconnect/audi_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ async def get_tripdata(self, vin: str, kind: str):
)

td_current = td_sorted[0]
td_reset_trip = None
# FIX, TR/2023-03-25: Assign just in case td_sorted contains only one item
td_reset_trip = td_sorted[0]

for trip in td_sorted:
if (td_current["startMileage"] - trip["startMileage"]) > 2:
Expand Down
1 change: 0 additions & 1 deletion custom_components/audiconnect/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ def device_info(self):
"identifiers": {(DOMAIN, self._instrument.vehicle_name)},
"manufacturer": "Audi",
"name": self._vehicle_name,
"device_type": "device_tracker",
}

@property
Expand Down

0 comments on commit b693a26

Please sign in to comment.