mirror of
https://github.com/esphome/esphome.git
synced 2025-11-18 07:45:56 +00:00
[core] Add support for setting environment variables (#11953)
This commit is contained in:
@@ -336,6 +336,7 @@ CONF_ENERGY = "energy"
|
|||||||
CONF_ENTITY_CATEGORY = "entity_category"
|
CONF_ENTITY_CATEGORY = "entity_category"
|
||||||
CONF_ENTITY_ID = "entity_id"
|
CONF_ENTITY_ID = "entity_id"
|
||||||
CONF_ENUM_DATAPOINT = "enum_datapoint"
|
CONF_ENUM_DATAPOINT = "enum_datapoint"
|
||||||
|
CONF_ENVIRONMENT_VARIABLES = "environment_variables"
|
||||||
CONF_EQUATION = "equation"
|
CONF_EQUATION = "equation"
|
||||||
CONF_ESP8266_DISABLE_SSL_SUPPORT = "esp8266_disable_ssl_support"
|
CONF_ESP8266_DISABLE_SSL_SUPPORT = "esp8266_disable_ssl_support"
|
||||||
CONF_ESPHOME = "esphome"
|
CONF_ESPHOME = "esphome"
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ from esphome.const import (
|
|||||||
CONF_COMPILE_PROCESS_LIMIT,
|
CONF_COMPILE_PROCESS_LIMIT,
|
||||||
CONF_DEBUG_SCHEDULER,
|
CONF_DEBUG_SCHEDULER,
|
||||||
CONF_DEVICES,
|
CONF_DEVICES,
|
||||||
|
CONF_ENVIRONMENT_VARIABLES,
|
||||||
CONF_ESPHOME,
|
CONF_ESPHOME,
|
||||||
CONF_FRIENDLY_NAME,
|
CONF_FRIENDLY_NAME,
|
||||||
CONF_ID,
|
CONF_ID,
|
||||||
@@ -215,6 +216,11 @@ CONFIG_SCHEMA = cv.All(
|
|||||||
cv.string_strict: cv.Any([cv.string], cv.string),
|
cv.string_strict: cv.Any([cv.string], cv.string),
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
cv.Optional(CONF_ENVIRONMENT_VARIABLES, default={}): cv.Schema(
|
||||||
|
{
|
||||||
|
cv.string_strict: cv.string,
|
||||||
|
}
|
||||||
|
),
|
||||||
cv.Optional(CONF_ON_BOOT): automation.validate_automation(
|
cv.Optional(CONF_ON_BOOT): automation.validate_automation(
|
||||||
{
|
{
|
||||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(StartupTrigger),
|
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(StartupTrigger),
|
||||||
@@ -426,6 +432,12 @@ async def _add_platformio_options(pio_options):
|
|||||||
cg.add_platformio_option(key, val)
|
cg.add_platformio_option(key, val)
|
||||||
|
|
||||||
|
|
||||||
|
@coroutine_with_priority(CoroPriority.FINAL)
|
||||||
|
async def _add_environment_variables(env_vars: dict[str, str]) -> None:
|
||||||
|
# Set environment variables for the build process
|
||||||
|
os.environ.update(env_vars)
|
||||||
|
|
||||||
|
|
||||||
@coroutine_with_priority(CoroPriority.AUTOMATION)
|
@coroutine_with_priority(CoroPriority.AUTOMATION)
|
||||||
async def _add_automations(config):
|
async def _add_automations(config):
|
||||||
for conf in config.get(CONF_ON_BOOT, []):
|
for conf in config.get(CONF_ON_BOOT, []):
|
||||||
@@ -563,6 +575,9 @@ async def to_code(config: ConfigType) -> None:
|
|||||||
if config[CONF_PLATFORMIO_OPTIONS]:
|
if config[CONF_PLATFORMIO_OPTIONS]:
|
||||||
CORE.add_job(_add_platformio_options, config[CONF_PLATFORMIO_OPTIONS])
|
CORE.add_job(_add_platformio_options, config[CONF_PLATFORMIO_OPTIONS])
|
||||||
|
|
||||||
|
if config[CONF_ENVIRONMENT_VARIABLES]:
|
||||||
|
CORE.add_job(_add_environment_variables, config[CONF_ENVIRONMENT_VARIABLES])
|
||||||
|
|
||||||
# Process areas
|
# Process areas
|
||||||
all_areas: list[dict[str, str | core.ID]] = []
|
all_areas: list[dict[str, str | core.ID]] = []
|
||||||
if CONF_AREA in config:
|
if CONF_AREA in config:
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ esphome:
|
|||||||
debug_scheduler: true
|
debug_scheduler: true
|
||||||
platformio_options:
|
platformio_options:
|
||||||
board_build.flash_mode: dio
|
board_build.flash_mode: dio
|
||||||
|
environment_variables:
|
||||||
|
TEST_ENV_VAR: "test_value"
|
||||||
|
BUILD_NUMBER: "12345"
|
||||||
area:
|
area:
|
||||||
id: testing_area
|
id: testing_area
|
||||||
name: Testing Area
|
name: Testing Area
|
||||||
|
|||||||
Reference in New Issue
Block a user