neredera / teslafi_exporter

Prometheus Exporter for TeslaFi
MIT License
13 stars 0 forks source link

Errors when car is sleeping #3

Open joe-stelmach opened 1 year ago

joe-stelmach commented 1 year ago

Howdy!

When the car is asleep, the exporter will error because it's trying to take action on None or NoneType

Example Error:

Traceback (most recent call last):
  File "/home/jstelmach/teslafi/teslafi_exporter/exporter.py", line 1029, in <module>
    TESLAFI_COLLECTOR = TeslaFiCollector(teslafi_api_token)
  File "/home/jstelmach/teslafi/teslafi_exporter/exporter.py", line 32, in __init__
    registry.register(self)
  File "/usr/local/lib/python3.8/dist-packages/prometheus_client/registry.py", line 40, in register
    names = self._get_names(collector)
  File "/usr/local/lib/python3.8/dist-packages/prometheus_client/registry.py", line 80, in _get_names
    for metric in desc_func():
  File "/home/jstelmach/teslafi/teslafi_exporter/exporter.py", line 158, in collect
    value=float(self.getSetData(teslafi_data, teslafi_data_old, "odometer"))*1609.344)
TypeError: float() argument must be a string or a number, not 'NoneType'

Is this expected or by design? If not, should we add error checking to see if the value exists then exit gracefully?

Thanks!

joe-stelmach commented 1 year ago

I noticed the TODO for error handling, my apologies.

Is there any preferred way to handle the error? I can take a shot at it if you'd like.