mirror of
https://github.com/esphome/esphome.git
synced 2026-09-21 03:58:41 +00:00
[opentherm] Fix step=0 default overriding entity step (#15484)
This commit is contained in:
@@ -2,51 +2,48 @@ from typing import Any
|
||||
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import CONF_MAX_VALUE, CONF_MIN_VALUE
|
||||
|
||||
from . import generate, schema
|
||||
|
||||
CONF_min_value = "min_value"
|
||||
CONF_max_value = "max_value"
|
||||
CONF_auto_min_value = "auto_min_value"
|
||||
CONF_auto_max_value = "auto_max_value"
|
||||
CONF_step = "step"
|
||||
CONF_AUTO_MIN_VALUE = "auto_min_value"
|
||||
CONF_AUTO_MAX_VALUE = "auto_max_value"
|
||||
|
||||
OpenthermInput = generate.opentherm_ns.class_("OpenthermInput")
|
||||
|
||||
|
||||
def validate_min_value_less_than_max_value(conf):
|
||||
if (
|
||||
CONF_min_value in conf
|
||||
and CONF_max_value in conf
|
||||
and conf[CONF_min_value] > conf[CONF_max_value]
|
||||
CONF_MIN_VALUE in conf
|
||||
and CONF_MAX_VALUE in conf
|
||||
and conf[CONF_MIN_VALUE] > conf[CONF_MAX_VALUE]
|
||||
):
|
||||
raise cv.Invalid(f"{CONF_min_value} must be less than {CONF_max_value}")
|
||||
raise cv.Invalid(f"{CONF_MIN_VALUE} must be less than {CONF_MAX_VALUE}")
|
||||
return conf
|
||||
|
||||
|
||||
def input_schema(entity: schema.InputSchema) -> cv.Schema:
|
||||
result = cv.Schema(
|
||||
{
|
||||
cv.Optional(CONF_min_value, entity.range[0]): cv.float_range(
|
||||
cv.Optional(CONF_MIN_VALUE, entity.range[0]): cv.float_range(
|
||||
entity.range[0], entity.range[1]
|
||||
),
|
||||
cv.Optional(CONF_max_value, entity.range[1]): cv.float_range(
|
||||
cv.Optional(CONF_MAX_VALUE, entity.range[1]): cv.float_range(
|
||||
entity.range[0], entity.range[1]
|
||||
),
|
||||
}
|
||||
)
|
||||
result = result.add_extra(validate_min_value_less_than_max_value)
|
||||
result = result.extend({cv.Optional(CONF_step, False): cv.float_})
|
||||
if entity.auto_min_value is not None:
|
||||
result = result.extend({cv.Optional(CONF_auto_min_value, False): cv.boolean})
|
||||
result = result.extend({cv.Optional(CONF_AUTO_MIN_VALUE, False): cv.boolean})
|
||||
if entity.auto_max_value is not None:
|
||||
result = result.extend({cv.Optional(CONF_auto_max_value, False): cv.boolean})
|
||||
result = result.extend({cv.Optional(CONF_AUTO_MAX_VALUE, False): cv.boolean})
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def generate_setters(entity: cg.MockObj, conf: dict[str, Any]) -> None:
|
||||
generate.add_property_set(entity, CONF_min_value, conf)
|
||||
generate.add_property_set(entity, CONF_max_value, conf)
|
||||
generate.add_property_set(entity, CONF_auto_min_value, conf)
|
||||
generate.add_property_set(entity, CONF_auto_max_value, conf)
|
||||
generate.add_property_set(entity, CONF_MIN_VALUE, conf)
|
||||
generate.add_property_set(entity, CONF_MAX_VALUE, conf)
|
||||
generate.add_property_set(entity, CONF_AUTO_MIN_VALUE, conf)
|
||||
generate.add_property_set(entity, CONF_AUTO_MAX_VALUE, conf)
|
||||
|
||||
@@ -3,7 +3,13 @@ from typing import Any
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import number
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import CONF_INITIAL_VALUE, CONF_RESTORE_VALUE, CONF_STEP
|
||||
from esphome.const import (
|
||||
CONF_INITIAL_VALUE,
|
||||
CONF_MAX_VALUE,
|
||||
CONF_MIN_VALUE,
|
||||
CONF_RESTORE_VALUE,
|
||||
CONF_STEP,
|
||||
)
|
||||
|
||||
from .. import const, generate, input, schema, validate
|
||||
|
||||
@@ -18,9 +24,9 @@ OpenthermNumber = generate.opentherm_ns.class_(
|
||||
async def new_openthermnumber(config: dict[str, Any]) -> cg.Pvariable:
|
||||
var = await number.new_number(
|
||||
config,
|
||||
min_value=config[input.CONF_min_value],
|
||||
max_value=config[input.CONF_max_value],
|
||||
step=config[input.CONF_step],
|
||||
min_value=config[CONF_MIN_VALUE],
|
||||
max_value=config[CONF_MAX_VALUE],
|
||||
step=config[CONF_STEP],
|
||||
)
|
||||
await cg.register_component(var, config)
|
||||
input.generate_setters(var, config)
|
||||
|
||||
Reference in New Issue
Block a user