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

Refueling events / parsing failing? #17

Closed
mm98 opened this issue Nov 10, 2023 · 4 comments
Closed

Refueling events / parsing failing? #17

mm98 opened this issue Nov 10, 2023 · 4 comments

Comments

@mm98
Copy link

mm98 commented Nov 10, 2023

Hi,

It looks like there still are some kind of bug(s) with the refueling event from ConnectedCars. Strangely it worked last time I refueled with the same version of the integration (v1.1.1).

Logger: homeassistant.helpers.entity
Source: helpers/entity.py:696
First occurred: 10:31:13 (5 occurrences)
Last logged: 10:35:13

Update for sensor.audi_a5_mileage_since_refuel fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 696, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 957, in async_device_update
    await self.async_update()
  File "/config/custom_components/connectedcars_io/sensor.py", line 385, in async_update
    distance_since_refuel = odometer_current - self._dict["Odometer"]
                            ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'

if "Odometer" in self._dict and self._dict["Odometer"] is not None:
odometer_current = await self._connectedcarsclient.get_value(
self._vehicle["id"], ["odometer", "odometer"]
)
distance_since_refuel = odometer_current - self._dict["Odometer"]
if distance_since_refuel >= 0:
self._state = distance_since_refuel


This error originated from a custom integration.

Logger: custom_components.connectedcars_io.device_tracker
Source: custom_components/connectedcars_io/device_tracker.py:171
Integration: Connectedcars.io (Min Volkswagen) (documentation, issues)
First occurred: 10:31:13 (5 occurrences)
Last logged: 10:35:13

Unable to parse ignition timestamp. Err: Invalid isoformat string: 'None'

try:
ignition_time = datetime.fromisoformat(
str(
await self._connectedcarsclient.get_value(
self._vehicle["id"], ["ignition", "time"]
)
).replace("Z", "+00:00")
)
except Exception as err: # pylint: disable=broad-except
_LOGGER.warning("Unable to parse ignition timestamp. Err: %s", err)
_LOGGER.debug("ignition: %s, time: %s", ignition, ignition_time)

Note: audi_a5_fuel_economy is disabled as suggested in #15.

@jnxxx
Copy link
Owner

jnxxx commented Nov 11, 2023

I do not get these two errors myself, but I can see how it can lead to such loggings if the read values are null.
I have now added some more error handling. Try the version in the main branch (not in a release yet).

  1. Mileage since refuel: It now checks for odometer_current being null / None, and if so does not do the calculation. Instead the sensor should show as unavailable, until the odometer reports a value again.

  2. Location: It only updates location when ignition is on, or last ignition timestamp has changed. This is to avoid triggering automations due to GPS inaccuracy.
    If the ignition timestamp is not reported or is invalid, it will now just update the location even when ignition is off.

  3. From Failing on fuel_economy #15 the rounding is now done by Home Assistant.
    Mine has started to report a value again, but if it ever reports null again, HA should just show it as unavailable.

@mm98
Copy link
Author

mm98 commented Nov 11, 2023

Try the version in the main branch (not in a release yet).

Thanks! I'll give it a try and report back with any findings.

@mm98
Copy link
Author

mm98 commented Nov 22, 2023

Hi. The changes in the main branch removed the errors. So I guess this can be closed?

@jnxxx
Copy link
Owner

jnxxx commented Dec 8, 2023

Yes, let's close it.

Fixes have now been released in v1.1.2.

@jnxxx jnxxx closed this as completed Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants