Skip to content

Commit

Permalink
fix: remainingChargingTime & Debug audi_models.py (#298)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Action <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 21, 2024
1 parent 1486109 commit 061aa85
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions custom_components/audiconnect/audi_models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import logging

_LOGGER = logging.getLogger(__name__)


class VehicleData:
def __init__(self, config_entry):
self.sensors = set()
Expand Down Expand Up @@ -254,20 +259,22 @@ def __init__(self, data):
def _tryAppendStateWithTs(self, json, name, tsoff, loc):
ts = None
val = self._getFromJson(json, loc)
if val:
val = 0 if name == "remainingChargingTime" and val is None else val
if val is not None:
loc[tsoff:] = ["carCapturedTimestamp"]
ts = self._getFromJson(json, loc)

if val and ts:
if val is not None and ts:
self.states.append({"name": name, "value": val, "measure_time": ts})
_LOGGER.debug(
f"audi_models.py - _tryAppendStateWithTs: json:{json} name:{name} tsoff:{tsoff} loc:{loc}: val:{val} ts:{ts}"
)

def _tryAppendFieldWithTs(self, json, textId, loc):
ts = None
val = self._getFromJson(json, loc)
if val:
loc[-1:] = ["carCapturedTimestamp"]
ts = self._getFromJson(json, loc)

if val and ts:
self.data_fields.append(
Field(
Expand All @@ -278,6 +285,9 @@ def _tryAppendFieldWithTs(self, json, textId, loc):
}
)
)
_LOGGER.debug(
f"audi_models.py - _tryAppendFieldWithTs: json:{json} textId:{textId} loc:{loc}: val:{val} ts:{ts}"
)

def _getFromJson(self, json, loc):
child = json
Expand Down

0 comments on commit 061aa85

Please sign in to comment.