def write(timestamp, temperatures):
if invalidConfig:
if plotly_debugEnabled:
plotly_logger.debug('Invalid config, aborting write')
return []
debug_message = 'Writing to ' + plugin_name
if not plotly_writeEnabled:
debug_message += ' [SIMULATED]'
plotly_logger.debug(debug_message)
debug_text = '%s: ' % timestamp
if plotly_writeEnabled:
# Stream tokens from plotly
tls.set_credentials_file(stream_ids=stream_ids_array)
try:
if plotly_writeEnabled:
py.sign_in(plotly_username, plotly_api_key)
for temperature in temperatures:
debug_text += "%s (%s A" % (temperature.zone, temperature.actual)
if temperature.target is not None:
debug_text += ", %s T" % temperature.target
debug_text += ') '
if plotly_writeEnabled:
if temperature.zone in zones:
stream_id = zones[temperature.zone]
s = py.Stream(stream_id)
s.open()
ts = timestamp.strftime('%Y-%m-%d %H:%M:%S')
s.write(dict(x=ts, y=temperature.actual))
s.close()
else:
plotly_logger.debug("Zone %s does not have a stream id, ignoring")
except Exception, e:
plotly_logger.error("Plot.ly API error - aborting write\n%s", e)
if plotly_debugEnabled:
plotly_logger.debug(debug_text)
评论列表
文章目录