mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 06:47:09 +00:00
Ignore NaN values for influxdb (#14347)
* Ignore NaN values for influxdb * Catch TypeError
This commit is contained in:
parent
50cea77887
commit
d43e6a2888
@ -9,6 +9,7 @@ import re
|
|||||||
import queue
|
import queue
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
import math
|
||||||
|
|
||||||
import requests.exceptions
|
import requests.exceptions
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
@ -220,9 +221,12 @@ def setup(hass, config):
|
|||||||
json['fields'][key] = float(
|
json['fields'][key] = float(
|
||||||
RE_DECIMAL.sub('', new_value))
|
RE_DECIMAL.sub('', new_value))
|
||||||
|
|
||||||
# Infinity is not a valid float in InfluxDB
|
# Infinity and NaN are not valid floats in InfluxDB
|
||||||
if (key, float("inf")) in json['fields'].items():
|
try:
|
||||||
del json['fields'][key]
|
if not math.isfinite(json['fields'][key]):
|
||||||
|
del json['fields'][key]
|
||||||
|
except (KeyError, TypeError):
|
||||||
|
pass
|
||||||
|
|
||||||
json['tags'].update(tags)
|
json['tags'].update(tags)
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ class TestInfluxDB(unittest.TestCase):
|
|||||||
"""Test the event listener for missing units."""
|
"""Test the event listener for missing units."""
|
||||||
self._setup()
|
self._setup()
|
||||||
|
|
||||||
attrs = {'bignumstring': "9" * 999}
|
attrs = {'bignumstring': '9' * 999, 'nonumstring': 'nan'}
|
||||||
state = mock.MagicMock(
|
state = mock.MagicMock(
|
||||||
state=8, domain='fake', entity_id='fake.entity-id',
|
state=8, domain='fake', entity_id='fake.entity-id',
|
||||||
object_id='entity', attributes=attrs)
|
object_id='entity', attributes=attrs)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user