splunk: Handle datetime objects in event payload (#9628)
If an event contained a datetime.datetime object it would cause an exception in the Splunk component. Most of the media_player components do this in their `media_position_updated_at` attribute. Use the JSONEncoder from homeassistant.remote instead of just using the standard json.dumps encoder. Fixes #9590
This commit is contained in:
parent
e406c57ec9
commit
80a15977ff
2 changed files with 25 additions and 13 deletions
|
@ -14,6 +14,7 @@ from homeassistant.const import (
|
|||
CONF_NAME, CONF_HOST, CONF_PORT, CONF_SSL, CONF_TOKEN, EVENT_STATE_CHANGED)
|
||||
from homeassistant.helpers import state as state_helper
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.remote import JSONEncoder
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -81,7 +82,8 @@ def setup(hass, config):
|
|||
"host": event_collector,
|
||||
"event": json_body,
|
||||
}
|
||||
requests.post(event_collector, data=json.dumps(payload),
|
||||
requests.post(event_collector,
|
||||
data=json.dumps(payload, cls=JSONEncoder),
|
||||
headers=headers, timeout=10)
|
||||
except requests.exceptions.RequestException as error:
|
||||
_LOGGER.exception("Error saving event to Splunk: %s", error)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue