mirror of
https://github.com/esphome/esphome.git
synced 2026-06-01 01:19:45 +08:00
[globals] Fix handling of string booleans in yaml (#14447)
This commit is contained in:
@@ -51,7 +51,7 @@ _RESTORING_SCHEMA = cv.Schema(
|
|||||||
|
|
||||||
def _globals_schema(config: ConfigType) -> ConfigType:
|
def _globals_schema(config: ConfigType) -> ConfigType:
|
||||||
"""Select schema based on restore_value setting."""
|
"""Select schema based on restore_value setting."""
|
||||||
if config.get(CONF_RESTORE_VALUE, False):
|
if cv.boolean(config.get(CONF_RESTORE_VALUE, False)):
|
||||||
return _RESTORING_SCHEMA(config)
|
return _RESTORING_SCHEMA(config)
|
||||||
return _NON_RESTORING_SCHEMA(config)
|
return _NON_RESTORING_SCHEMA(config)
|
||||||
|
|
||||||
|
|||||||
@@ -27,3 +27,14 @@ globals:
|
|||||||
type: bool
|
type: bool
|
||||||
restore_value: false
|
restore_value: false
|
||||||
initial_value: "false"
|
initial_value: "false"
|
||||||
|
# Test restore_value with string "false" - should be converted to bool false
|
||||||
|
- id: glob_no_restore_string_false
|
||||||
|
type: int
|
||||||
|
restore_value: "false"
|
||||||
|
initial_value: "42"
|
||||||
|
# Test restore_value with string "true" - should be converted to bool true
|
||||||
|
- id: glob_restore_string_true
|
||||||
|
type: int
|
||||||
|
restore_value: "true"
|
||||||
|
initial_value: "99"
|
||||||
|
update_interval: 5s
|
||||||
|
|||||||
Reference in New Issue
Block a user