mirror of
https://github.com/esphome/esphome.git
synced 2025-09-14 09:12:19 +01:00
Some basic chain working
This commit is contained in:
@@ -2,34 +2,30 @@ from esphome import config_validation as cv
|
||||
from esphome import codegen as cg
|
||||
from esphome.const import CONF_ID, CONF_NAME
|
||||
|
||||
DeviceStruct = cg.esphome_ns.struct("Device")
|
||||
# DeviceStruct = cg.esphome_ns.struct("Device")
|
||||
# StringVar = cg.std_ns.struct("string")
|
||||
StringRef = cg.esphome_ns.struct("StringRef")
|
||||
|
||||
MULTI_CONF = True
|
||||
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.declare_id(DeviceStruct),
|
||||
# cv.Required(CONF_ID): cv.declare_id(DeviceStruct),
|
||||
# cv.Required(CONF_ID): cv.declare_id(StringVar),
|
||||
cv.Required(CONF_ID): cv.declare_id(StringRef),
|
||||
cv.Required(CONF_NAME): cv.string,
|
||||
# cv.Exclusive(CONF_RED, "red"): cv.percentage,
|
||||
# cv.Exclusive(CONF_RED_INT, "red"): cv.uint8_t,
|
||||
# cv.Exclusive(CONF_GREEN, "green"): cv.percentage,
|
||||
# cv.Exclusive(CONF_GREEN_INT, "green"): cv.uint8_t,
|
||||
# cv.Exclusive(CONF_BLUE, "blue"): cv.percentage,
|
||||
# cv.Exclusive(CONF_BLUE_INT, "blue"): cv.uint8_t,
|
||||
# cv.Exclusive(CONF_WHITE, "white"): cv.percentage,
|
||||
# cv.Exclusive(CONF_WHITE_INT, "white"): cv.uint8_t,
|
||||
}).extend(cv.COMPONENT_SCHEMA)
|
||||
}
|
||||
).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
# paren = await cg.get_variable(config[CONF_WEB_SERVER_BASE_ID])
|
||||
# var = cg.new_Pvariable(config[CONF_ID], paren)
|
||||
# await cg.register_component(var, config)
|
||||
# cg.add_define("USE_CAPTIVE_PORTAL")
|
||||
|
||||
cg.new_variable(
|
||||
# cg.new_variable(
|
||||
# config[CONF_ID],
|
||||
# config[CONF_NAME],
|
||||
# )
|
||||
cg.new_Pvariable(
|
||||
config[CONF_ID],
|
||||
cg.new_Pvariable(config[CONF_NAME]),
|
||||
config[CONF_NAME],
|
||||
)
|
||||
# cg.add_define("USE_DEVICE_ID")
|
||||
|
14
esphome/components/device/device.h
Normal file
14
esphome/components/device/device.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
namespace esphome {
|
||||
|
||||
class Device {
|
||||
public:
|
||||
void set_name(std::string name) { name_ = name; }
|
||||
std::string get_name(void) {return name_;}
|
||||
|
||||
protected:
|
||||
std::string name_ = "";
|
||||
};
|
||||
|
||||
} // namespace esphome
|
@@ -349,16 +349,10 @@ def icon(value):
|
||||
)
|
||||
|
||||
|
||||
def device_name(value):
|
||||
"""Validate that a given config value is a valid device name."""
|
||||
value = string_strict(value)
|
||||
if not value:
|
||||
return value
|
||||
# if re.match("^[\\w\\-]+:[\\w\\-]+$", value):
|
||||
# return value
|
||||
raise Invalid(
|
||||
'device name must be string that matches a defined device in "deviced:" section'
|
||||
)
|
||||
def device_id(value):
|
||||
StringRef = cg.esphome_ns.struct("StringRef")
|
||||
validator = use_id(StringRef)
|
||||
return validator(value)
|
||||
|
||||
|
||||
def boolean(value):
|
||||
@@ -1880,8 +1874,8 @@ ENTITY_BASE_SCHEMA = Schema(
|
||||
Optional(CONF_DISABLED_BY_DEFAULT, default=False): boolean,
|
||||
Optional(CONF_ICON): icon,
|
||||
Optional(CONF_ENTITY_CATEGORY): entity_category,
|
||||
Optional(CONF_DEVICE_ID): device_name,
|
||||
|
||||
# Optional(CONF_DEVICE_ID): use_id(StringRef),
|
||||
Optional(CONF_DEVICE_ID): device_id,
|
||||
}
|
||||
)
|
||||
|
||||
|
@@ -210,7 +210,6 @@ CONF_DELIMITER = "delimiter"
|
||||
CONF_DELTA = "delta"
|
||||
CONF_DEST = "dest"
|
||||
CONF_DEVICE = "device"
|
||||
CONF_DEVICES = "devices"
|
||||
CONF_DEVICE_CLASS = "device_class"
|
||||
CONF_DEVICE_FACTOR = "device_factor"
|
||||
CONF_DEVICE_ID = "device_id"
|
||||
|
@@ -36,13 +36,13 @@ std::string EntityBase::get_icon() const {
|
||||
void EntityBase::set_icon(const char *icon) { this->icon_c_str_ = icon; }
|
||||
|
||||
// Entity Device Name
|
||||
std::string EntityBase::get_device_name() const {
|
||||
if (this->device_name_c_str_ == nullptr) {
|
||||
return "";
|
||||
StringRef EntityBase::get_device_name() const {
|
||||
if (this->device_name_.empty()) {
|
||||
return StringRef("");
|
||||
}
|
||||
return this->device_name_c_str_;
|
||||
return this->device_name_;
|
||||
}
|
||||
void EntityBase::set_device_name(const char *device_name) { this->device_name_c_str_ = device_name; }
|
||||
void EntityBase::set_device_name(const StringRef *device_name) { this->device_name_ = *device_name; }
|
||||
|
||||
// Entity Category
|
||||
EntityCategory EntityBase::get_entity_category() const { return this->entity_category_; }
|
||||
|
@@ -48,8 +48,8 @@ class EntityBase {
|
||||
void set_icon(const char *icon);
|
||||
|
||||
// Get/set this entity's device name
|
||||
std::string get_device_name() const;
|
||||
void set_device_name(const char *icon);
|
||||
StringRef get_device_name() const;
|
||||
void set_device_name(const StringRef *device_name);
|
||||
|
||||
protected:
|
||||
/// The hash_base() function has been deprecated. It is kept in this
|
||||
@@ -65,7 +65,7 @@ class EntityBase {
|
||||
bool internal_{false};
|
||||
bool disabled_by_default_{false};
|
||||
EntityCategory entity_category_{ENTITY_CATEGORY_NONE};
|
||||
const char *device_name_c_str_{nullptr};
|
||||
StringRef device_name_;
|
||||
};
|
||||
|
||||
class EntityBase_DeviceClass { // NOLINT(readability-identifier-naming)
|
||||
|
@@ -112,8 +112,8 @@ async def setup_entity(var, config):
|
||||
if CONF_ENTITY_CATEGORY in config:
|
||||
add(var.set_entity_category(config[CONF_ENTITY_CATEGORY]))
|
||||
if CONF_DEVICE_ID in config:
|
||||
# TODO: lookup the device from devices: section and get the real name
|
||||
add(var.set_device_name(config[CONF_DEVICE_ID]))
|
||||
parent = await get_variable(config[CONF_DEVICE_ID])
|
||||
add(var.set_device_name(parent))
|
||||
|
||||
|
||||
def extract_registry_entry_config(
|
||||
|
Reference in New Issue
Block a user