mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-11-17 06:50:53 +00:00
Code blocks (#11648)
* Run black on Python code blocks, syntax fixes https://github.com/scop/misc/blob/master/black_markdown.py * Code block language marker fixes * String formatting style tweaks
This commit is contained in:
committed by
Fabian Affolter
parent
0e49f98121
commit
b6a904933b
@@ -18,21 +18,21 @@ This example follows a topic on MQTT and updates the state of an entity to the l
|
||||
import homeassistant.loader as loader
|
||||
|
||||
# The domain of your component. Should be equal to the name of your component.
|
||||
DOMAIN = 'hello_mqtt'
|
||||
DOMAIN = "hello_mqtt"
|
||||
|
||||
# List of integration names (string) your integration depends upon.
|
||||
DEPENDENCIES = ['mqtt']
|
||||
DEPENDENCIES = ["mqtt"]
|
||||
|
||||
|
||||
CONF_TOPIC = 'topic'
|
||||
DEFAULT_TOPIC = 'home-assistant/hello_mqtt'
|
||||
CONF_TOPIC = "topic"
|
||||
DEFAULT_TOPIC = "home-assistant/hello_mqtt"
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
"""Set up the Hello MQTT component."""
|
||||
mqtt = hass.components.mqtt
|
||||
topic = config[DOMAIN].get(CONF_TOPIC, DEFAULT_TOPIC)
|
||||
entity_id = 'hello_mqtt.last_message'
|
||||
entity_id = "hello_mqtt.last_message"
|
||||
|
||||
# Listener to be called when we receive a message.
|
||||
# The msg parameter is a Message object with the following members:
|
||||
@@ -45,15 +45,15 @@ def setup(hass, config):
|
||||
mqtt.subscribe(topic, message_received)
|
||||
|
||||
# Set the initial state.
|
||||
hass.states.set(entity_id, 'No messages')
|
||||
hass.states.set(entity_id, "No messages")
|
||||
|
||||
# Service to publish a message on MQTT.
|
||||
def set_state_service(call):
|
||||
"""Service to send a message."""
|
||||
mqtt.publish(topic, call.data.get('new_state'))
|
||||
mqtt.publish(topic, call.data.get("new_state"))
|
||||
|
||||
# Register our service with Home Assistant.
|
||||
hass.services.register(DOMAIN, 'set_state', set_state_service)
|
||||
hass.services.register(DOMAIN, "set_state", set_state_service)
|
||||
|
||||
# Return boolean to indicate that initialization was successfully.
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user