mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Add dweet export component (#1818)
This commit is contained in:
parent
ddfda89fc9
commit
e5d1ed9439
@ -14,6 +14,9 @@ omit =
|
|||||||
homeassistant/components/bloomsky.py
|
homeassistant/components/bloomsky.py
|
||||||
homeassistant/components/*/bloomsky.py
|
homeassistant/components/*/bloomsky.py
|
||||||
|
|
||||||
|
homeassistant/components/dweet.py
|
||||||
|
homeassistant/components/*/dweet.py
|
||||||
|
|
||||||
homeassistant/components/ecobee.py
|
homeassistant/components/ecobee.py
|
||||||
homeassistant/components/*/ecobee.py
|
homeassistant/components/*/ecobee.py
|
||||||
|
|
||||||
@ -143,7 +146,6 @@ omit =
|
|||||||
homeassistant/components/sensor/cpuspeed.py
|
homeassistant/components/sensor/cpuspeed.py
|
||||||
homeassistant/components/sensor/deutsche_bahn.py
|
homeassistant/components/sensor/deutsche_bahn.py
|
||||||
homeassistant/components/sensor/dht.py
|
homeassistant/components/sensor/dht.py
|
||||||
homeassistant/components/sensor/dweet.py
|
|
||||||
homeassistant/components/sensor/efergy.py
|
homeassistant/components/sensor/efergy.py
|
||||||
homeassistant/components/sensor/eliqonline.py
|
homeassistant/components/sensor/eliqonline.py
|
||||||
homeassistant/components/sensor/forecast.py
|
homeassistant/components/sensor/forecast.py
|
||||||
|
73
homeassistant/components/dweet.py
Normal file
73
homeassistant/components/dweet.py
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
"""
|
||||||
|
A component which allows you to send data to Dweet.io.
|
||||||
|
|
||||||
|
For more details about this component, please refer to the documentation at
|
||||||
|
https://home-assistant.io/components/dweet/
|
||||||
|
"""
|
||||||
|
import logging
|
||||||
|
from datetime import timedelta
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from homeassistant.const import EVENT_STATE_CHANGED, STATE_UNKNOWN
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.helpers import state as state_helper
|
||||||
|
from homeassistant.util import Throttle
|
||||||
|
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
DOMAIN = "dweet"
|
||||||
|
DEPENDENCIES = []
|
||||||
|
|
||||||
|
REQUIREMENTS = ['dweepy==0.2.0']
|
||||||
|
|
||||||
|
CONF_NAME = 'name'
|
||||||
|
CONF_WHITELIST = 'whitelist'
|
||||||
|
|
||||||
|
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=1)
|
||||||
|
|
||||||
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
|
DOMAIN: vol.Schema({
|
||||||
|
vol.Required(CONF_NAME): cv.string,
|
||||||
|
vol.Required(CONF_WHITELIST): cv.string,
|
||||||
|
}),
|
||||||
|
}, extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=too-many-locals
|
||||||
|
def setup(hass, config):
|
||||||
|
"""Setup the Dweet.io component."""
|
||||||
|
conf = config[DOMAIN]
|
||||||
|
name = conf[CONF_NAME]
|
||||||
|
whitelist = conf.get(CONF_WHITELIST, [])
|
||||||
|
json_body = {}
|
||||||
|
|
||||||
|
def dweet_event_listener(event):
|
||||||
|
"""Listen for new messages on the bus and sends them to Dweet.io."""
|
||||||
|
state = event.data.get('new_state')
|
||||||
|
if state is None or state.state in (STATE_UNKNOWN, '') \
|
||||||
|
or state.entity_id not in whitelist:
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
_state = state_helper.state_as_number(state)
|
||||||
|
except ValueError:
|
||||||
|
_state = state.state
|
||||||
|
|
||||||
|
json_body[state.attributes.get('friendly_name')] = _state
|
||||||
|
|
||||||
|
send_data(name, json_body)
|
||||||
|
|
||||||
|
hass.bus.listen(EVENT_STATE_CHANGED, dweet_event_listener)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||||
|
def send_data(name, msg):
|
||||||
|
"""Send the collected data to Dweet.io."""
|
||||||
|
import dweepy
|
||||||
|
try:
|
||||||
|
dweepy.dweet_for(name, msg)
|
||||||
|
except dweepy.DweepyError:
|
||||||
|
_LOGGER.error("Error saving data '%s' to Dweet.io", msg)
|
@ -40,6 +40,7 @@ blockchain==1.3.1
|
|||||||
# homeassistant.components.notify.xmpp
|
# homeassistant.components.notify.xmpp
|
||||||
dnspython3==1.12.0
|
dnspython3==1.12.0
|
||||||
|
|
||||||
|
# homeassistant.components.dweet
|
||||||
# homeassistant.components.sensor.dweet
|
# homeassistant.components.sensor.dweet
|
||||||
dweepy==0.2.0
|
dweepy==0.2.0
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user