1 """Support for sending data to Dweet.io."""
3 from datetime
import timedelta
7 import voluptuous
as vol
22 _LOGGER = logging.getLogger(__name__)
28 CONFIG_SCHEMA = vol.Schema(
32 vol.Required(CONF_NAME): cv.string,
33 vol.Required(CONF_WHITELIST, default=[]): vol.All(
34 cv.ensure_list, [cv.entity_id]
39 extra=vol.ALLOW_EXTRA,
43 def setup(hass: HomeAssistant, config: ConfigType) -> bool:
44 """Set up the Dweet.io component."""
46 name = conf.get(CONF_NAME)
47 whitelist = conf.get(CONF_WHITELIST)
50 def dweet_event_listener(event):
51 """Listen for new messages on the bus and sends them to Dweet.io."""
52 state = event.data.get(
"new_state")
55 or state.state
in (STATE_UNKNOWN,
"")
56 or state.entity_id
not in whitelist
61 _state = state_helper.state_as_number(state)
65 json_body[state.attributes.get(ATTR_FRIENDLY_NAME)] = _state
69 hass.bus.listen(EVENT_STATE_CHANGED, dweet_event_listener)
74 @Throttle(MIN_TIME_BETWEEN_UPDATES)
76 """Send the collected data to Dweet.io."""
78 dweepy.dweet_for(name, msg)
79 except dweepy.DweepyError:
80 _LOGGER.error(
"Error saving data to Dweet.io: %s", msg)
bool setup(HomeAssistant hass, ConfigType config)