mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 13:34:54 +01:00
commit
f235dcc096
4 changed files with 16 additions and 6 deletions
|
@ -346,7 +346,7 @@ def upload_program(config, args, host):
|
||||||
not is_ip_address(CORE.address) # pylint: disable=too-many-boolean-expressions
|
not is_ip_address(CORE.address) # pylint: disable=too-many-boolean-expressions
|
||||||
and (get_port_type(host) == "MQTT" or config[CONF_MDNS][CONF_DISABLED])
|
and (get_port_type(host) == "MQTT" or config[CONF_MDNS][CONF_DISABLED])
|
||||||
and CONF_MQTT in config
|
and CONF_MQTT in config
|
||||||
and (not args.device or args.device == "MQTT")
|
and (not args.device or args.device in ("MQTT", "OTA"))
|
||||||
):
|
):
|
||||||
from esphome import mqtt
|
from esphome import mqtt
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,9 @@ from esphome.const import (
|
||||||
CONF_STATE,
|
CONF_STATE,
|
||||||
CONF_STOP,
|
CONF_STOP,
|
||||||
CONF_TRIGGER_ID,
|
CONF_TRIGGER_ID,
|
||||||
|
DEVICE_CLASS_EMPTY,
|
||||||
|
DEVICE_CLASS_GAS,
|
||||||
|
DEVICE_CLASS_WATER,
|
||||||
)
|
)
|
||||||
from esphome.core import CORE, coroutine_with_priority
|
from esphome.core import CORE, coroutine_with_priority
|
||||||
from esphome.cpp_helpers import setup_entity
|
from esphome.cpp_helpers import setup_entity
|
||||||
|
@ -22,6 +25,12 @@ IS_PLATFORM_COMPONENT = True
|
||||||
|
|
||||||
CODEOWNERS = ["@esphome/core"]
|
CODEOWNERS = ["@esphome/core"]
|
||||||
|
|
||||||
|
DEVICE_CLASSES = [
|
||||||
|
DEVICE_CLASS_EMPTY,
|
||||||
|
DEVICE_CLASS_GAS,
|
||||||
|
DEVICE_CLASS_WATER,
|
||||||
|
]
|
||||||
|
|
||||||
valve_ns = cg.esphome_ns.namespace("valve")
|
valve_ns = cg.esphome_ns.namespace("valve")
|
||||||
|
|
||||||
Valve = valve_ns.class_("Valve", cg.EntityBase)
|
Valve = valve_ns.class_("Valve", cg.EntityBase)
|
||||||
|
@ -65,6 +74,7 @@ VALVE_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMMAND_COMPONENT_SCHEMA).ex
|
||||||
{
|
{
|
||||||
cv.GenerateID(): cv.declare_id(Valve),
|
cv.GenerateID(): cv.declare_id(Valve),
|
||||||
cv.OnlyWith(CONF_MQTT_ID, "mqtt"): cv.declare_id(mqtt.MQTTValveComponent),
|
cv.OnlyWith(CONF_MQTT_ID, "mqtt"): cv.declare_id(mqtt.MQTTValveComponent),
|
||||||
|
cv.Optional(CONF_DEVICE_CLASS): cv.one_of(*DEVICE_CLASSES, lower=True),
|
||||||
cv.Optional(CONF_POSITION_COMMAND_TOPIC): cv.All(
|
cv.Optional(CONF_POSITION_COMMAND_TOPIC): cv.All(
|
||||||
cv.requires_component("mqtt"), cv.subscribe_topic
|
cv.requires_component("mqtt"), cv.subscribe_topic
|
||||||
),
|
),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"""Constants used by esphome."""
|
"""Constants used by esphome."""
|
||||||
|
|
||||||
__version__ = "2024.5.0"
|
__version__ = "2024.5.1"
|
||||||
|
|
||||||
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
||||||
VALID_SUBSTITUTIONS_CHARACTERS = (
|
VALID_SUBSTITUTIONS_CHARACTERS = (
|
||||||
|
|
|
@ -18,7 +18,7 @@ class MqttStatusThread(threading.Thread):
|
||||||
"""Run the status thread."""
|
"""Run the status thread."""
|
||||||
dashboard = DASHBOARD
|
dashboard = DASHBOARD
|
||||||
entries = dashboard.entries
|
entries = dashboard.entries
|
||||||
current_entries = entries.all()
|
current_entries = entries.async_all()
|
||||||
|
|
||||||
config = mqtt.config_from_env()
|
config = mqtt.config_from_env()
|
||||||
topic = "esphome/discover/#"
|
topic = "esphome/discover/#"
|
||||||
|
@ -33,7 +33,7 @@ class MqttStatusThread(threading.Thread):
|
||||||
return
|
return
|
||||||
for entry in current_entries:
|
for entry in current_entries:
|
||||||
if entry.name == data["name"]:
|
if entry.name == data["name"]:
|
||||||
entries.set_state(entry, EntryState.ONLINE)
|
entries.async_set_state(entry, EntryState.ONLINE)
|
||||||
return
|
return
|
||||||
|
|
||||||
def on_connect(client, userdata, flags, return_code):
|
def on_connect(client, userdata, flags, return_code):
|
||||||
|
@ -53,11 +53,11 @@ class MqttStatusThread(threading.Thread):
|
||||||
client.loop_start()
|
client.loop_start()
|
||||||
|
|
||||||
while not dashboard.stop_event.wait(2):
|
while not dashboard.stop_event.wait(2):
|
||||||
current_entries = entries.all()
|
current_entries = entries.async_all()
|
||||||
# will be set to true on on_message
|
# will be set to true on on_message
|
||||||
for entry in current_entries:
|
for entry in current_entries:
|
||||||
if entry.no_mdns:
|
if entry.no_mdns:
|
||||||
entries.set_state(entry, EntryState.OFFLINE)
|
entries.async_set_state(entry, EntryState.OFFLINE)
|
||||||
|
|
||||||
client.publish("esphome/discover", None, retain=False)
|
client.publish("esphome/discover", None, retain=False)
|
||||||
dashboard.mqtt_ping_request.wait()
|
dashboard.mqtt_ping_request.wait()
|
||||||
|
|
Loading…
Reference in a new issue