Added host variable to Splunk.py and updated tox tests (#8052)

* Added host variable to Splunk.py and updated tox tests

* Update splunk.py

* Update splunk.py
This commit is contained in:
boojew 2017-06-15 23:41:19 -04:00 committed by Paulus Schoutsen
parent a3a702b269
commit c478f2c7d0
2 changed files with 7 additions and 1 deletions

View file

@ -11,7 +11,7 @@ import requests
import voluptuous as vol
from homeassistant.const import (
CONF_HOST, CONF_PORT, CONF_SSL, CONF_TOKEN, EVENT_STATE_CHANGED)
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
@ -22,6 +22,7 @@ DOMAIN = 'splunk'
DEFAULT_HOST = 'localhost'
DEFAULT_PORT = 8088
DEFAULT_SSL = False
DEFAULT_NAME = 'HASS'
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
@ -29,6 +30,7 @@ CONFIG_SCHEMA = vol.Schema({
vol.Optional(CONF_HOST, default=DEFAULT_HOST): cv.string,
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
vol.Optional(CONF_SSL, default=False): cv.boolean,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
}),
}, extra=vol.ALLOW_EXTRA)
@ -40,6 +42,7 @@ def setup(hass, config):
port = conf.get(CONF_PORT)
token = conf.get(CONF_TOKEN)
use_ssl = conf.get(CONF_SSL)
name = conf.get(CONF_NAME)
if use_ssl:
uri_scheme = 'https://'
@ -69,6 +72,7 @@ def setup(hass, config):
'attributes': dict(state.attributes),
'time': str(event.time_fired),
'value': _state,
'host': name,
}
]

View file

@ -28,6 +28,7 @@ class TestSplunk(unittest.TestCase):
'port': 123,
'token': 'secret',
'ssl': 'False',
'name': 'hostname',
}
}
@ -96,6 +97,7 @@ class TestSplunk(unittest.TestCase):
'attributes': {},
'time': '12345',
'value': out,
'host': 'HASS',
}]
payload = {'host': 'http://host:8088/services/collector/event',