Maintenance 2nd (#4106)
* Add link to docs * Fix link * Update line breaks * Update ordering * Align vera platofrm to only use add_devices (instead od add_devices_callback) * Remove line break * Use consts * Update ordering * Update ordering * Use const, create default name, use string formatting * Update ordering * Use const * Update import style * Update ordering and line breaks * update line breaks * Set default port * Set defaults and update ordering * Update ordering * Minor style updates * Update ordering, defaults, line breaks, and readability * Use constants * Add line breaks * use string formatting * Update line breaks * Update logger
This commit is contained in:
1 parent
e6ece4bf6d
commit
9f2aae1357
28 files changed
+272
-271
No files matched your search
@@ -11,9 +11,7 @@ import voluptuous as vol
|
||||
import requests
|
||||
|
||||
from homeassistant.const import (
|
||||
CONF_API_KEY, CONF_WHITELIST,
|
||||
CONF_URL, STATE_UNKNOWN,
|
||||
STATE_UNAVAILABLE,
|
||||
CONF_API_KEY, CONF_WHITELIST, CONF_URL, STATE_UNKNOWN, STATE_UNAVAILABLE,
|
||||
CONF_SCAN_INTERVAL)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers import state as state_helper
|
||||
@@ -22,8 +20,8 @@ from homeassistant.util import dt as dt_util
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN = "emoncms_history"
|
||||
CONF_INPUTNODE = "inputnode"
|
||||
DOMAIN = 'emoncms_history'
|
||||
CONF_INPUTNODE = 'inputnode'
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
DOMAIN: vol.Schema({
|
||||
@@ -37,20 +35,19 @@ CONFIG_SCHEMA = vol.Schema({
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
"""Setup the emoncms_history component."""
|
||||
"""Set up the Emoncms history component."""
|
||||
conf = config[DOMAIN]
|
||||
whitelist = conf.get(CONF_WHITELIST)
|
||||
|
||||
def send_data(url, apikey, node, payload):
|
||||
"""Send payload data to emoncms."""
|
||||
"""Send payload data to Emoncms."""
|
||||
try:
|
||||
fullurl = "{}/input/post.json".format(url)
|
||||
req = requests.post(fullurl,
|
||||
params={"node": node},
|
||||
data={"apikey": apikey,
|
||||
"data": payload},
|
||||
allow_redirects=True,
|
||||
timeout=5)
|
||||
fullurl = '{}/input/post.json'.format(url)
|
||||
data = {"apikey": apikey, "data": payload}
|
||||
parameters = {"node": node}
|
||||
req = requests.post(
|
||||
fullurl, params=parameters, data=data, allow_redirects=True,
|
||||
timeout=5)
|
||||
|
||||
except requests.exceptions.RequestException:
|
||||
_LOGGER.error("Error saving data '%s' to '%s'",
|
||||
@@ -63,14 +60,14 @@ def setup(hass, config):
|
||||
fullurl, req.status_code)
|
||||
|
||||
def update_emoncms(time):
|
||||
"""Send whitelisted entities states reguarly to emoncms."""
|
||||
"""Send whitelisted entities states reguarly to Emoncms."""
|
||||
payload_dict = {}
|
||||
|
||||
for entity_id in whitelist:
|
||||
state = hass.states.get(entity_id)
|
||||
|
||||
if state is None or state.state in (
|
||||
STATE_UNKNOWN, "", STATE_UNAVAILABLE):
|
||||
STATE_UNKNOWN, '', STATE_UNAVAILABLE):
|
||||
continue
|
||||
|
||||
try:
|
||||
@@ -88,8 +85,7 @@ def setup(hass, config):
|
||||
str(conf.get(CONF_INPUTNODE)), payload)
|
||||
|
||||
track_point_in_time(hass, update_emoncms, time +
|
||||
timedelta(seconds=conf.get(
|
||||
CONF_SCAN_INTERVAL)))
|
||||
timedelta(seconds=conf.get(CONF_SCAN_INTERVAL)))
|
||||
|
||||
update_emoncms(dt_util.utcnow())
|
||||
return True
|
||||
Reference in new issue
Block a user