Black
This commit is contained in:
1 parent
da05dfe708
commit
4de97abc3a
2676 files changed
+163166
-140084
No files matched your search
@@ -5,32 +5,41 @@ import voluptuous as vol
|
||||
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.const import (
|
||||
CONF_PASSWORD, CONF_USERNAME, EVENT_STATE_CHANGED,
|
||||
EVENT_HOMEASSISTANT_STOP)
|
||||
CONF_PASSWORD,
|
||||
CONF_USERNAME,
|
||||
EVENT_STATE_CHANGED,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
)
|
||||
from homeassistant.helpers import state as state_helper
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN = 'shiftr'
|
||||
DOMAIN = "shiftr"
|
||||
|
||||
SHIFTR_BROKER = 'broker.shiftr.io'
|
||||
SHIFTR_BROKER = "broker.shiftr.io"
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
DOMAIN: vol.Schema({
|
||||
vol.Required(CONF_USERNAME): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
}),
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{
|
||||
DOMAIN: vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_USERNAME): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
}
|
||||
)
|
||||
},
|
||||
extra=vol.ALLOW_EXTRA,
|
||||
)
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
"""Initialize the Shiftr.io MQTT consumer."""
|
||||
import paho.mqtt.client as mqtt
|
||||
|
||||
conf = config[DOMAIN]
|
||||
username = conf.get(CONF_USERNAME)
|
||||
password = conf.get(CONF_PASSWORD)
|
||||
|
||||
client_id = 'HomeAssistant'
|
||||
client_id = "HomeAssistant"
|
||||
port = 1883
|
||||
keepalive = 600
|
||||
|
||||
@@ -46,8 +55,8 @@ def setup(hass, config):
|
||||
|
||||
def shiftr_event_listener(event):
|
||||
"""Listen for new messages on the bus and sends them to Shiftr.io."""
|
||||
state = event.data.get('new_state')
|
||||
topic = state.entity_id.replace('.', '/')
|
||||
state = event.data.get("new_state")
|
||||
topic = state.entity_id.replace(".", "/")
|
||||
|
||||
try:
|
||||
_state = state_helper.state_as_number(state)
|
||||
@@ -60,8 +69,11 @@ def setup(hass, config):
|
||||
if state.attributes:
|
||||
for attribute, data in state.attributes.items():
|
||||
mqttc.publish(
|
||||
'/{}/{}'.format(topic, attribute), str(data), qos=0,
|
||||
retain=False)
|
||||
"/{}/{}".format(topic, attribute),
|
||||
str(data),
|
||||
qos=0,
|
||||
retain=False,
|
||||
)
|
||||
except RuntimeError:
|
||||
pass
|
||||
|
||||
|
||||
Reference in new issue
Block a user