[opentherm] Update to use schema methods (#8756)

This commit is contained in:
Jesse Hills 2025-05-13 08:53:46 +12:00 committed by GitHub
parent dcd786d21c
commit 38790793dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 29 deletions

View File

@ -11,10 +11,8 @@ COMPONENT_TYPE = const.BINARY_SENSOR
def get_entity_validation_schema(entity: schema.BinarySensorSchema) -> cv.Schema:
return binary_sensor.binary_sensor_schema(
device_class=(
entity.device_class or cv.UNDEFINED # pylint: disable=protected-access
),
icon=(entity.icon or cv.UNDEFINED), # pylint: disable=protected-access
device_class=(entity.device_class or cv.UNDEFINED),
icon=(entity.icon or cv.UNDEFINED),
)

View File

@ -3,13 +3,7 @@ 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_ID,
CONF_INITIAL_VALUE,
CONF_RESTORE_VALUE,
CONF_STEP,
CONF_UNIT_OF_MEASUREMENT,
)
from esphome.const import CONF_INITIAL_VALUE, CONF_RESTORE_VALUE, CONF_STEP
from .. import const, generate, input, schema, validate
@ -22,33 +16,30 @@ OpenthermNumber = generate.opentherm_ns.class_(
async def new_openthermnumber(config: dict[str, Any]) -> cg.Pvariable:
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
await number.register_number(
var,
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],
)
await cg.register_component(var, config)
input.generate_setters(var, config)
if CONF_INITIAL_VALUE in config:
cg.add(var.set_initial_value(config[CONF_INITIAL_VALUE]))
if CONF_RESTORE_VALUE in config:
cg.add(var.set_restore_value(config[CONF_RESTORE_VALUE]))
if (initial_value := config.get(CONF_INITIAL_VALUE, None)) is not None:
cg.add(var.set_initial_value(initial_value))
if (restore_value := config.get(CONF_RESTORE_VALUE, None)) is not None:
cg.add(var.set_restore_value(restore_value))
return var
def get_entity_validation_schema(entity: schema.InputSchema) -> cv.Schema:
return (
number.NUMBER_SCHEMA.extend(
number.number_schema(
OpenthermNumber, unit_of_measurement=entity.unit_of_measurement
)
.extend(
{
cv.GenerateID(): cv.declare_id(OpenthermNumber),
cv.Optional(
CONF_UNIT_OF_MEASUREMENT, entity.unit_of_measurement
): cv.string_strict,
cv.Optional(CONF_STEP, entity.step): cv.float_,
cv.Optional(CONF_INITIAL_VALUE): cv.float_,
cv.Optional(CONF_RESTORE_VALUE): cv.boolean,

View File

@ -3,7 +3,6 @@ from typing import Any
import esphome.codegen as cg
from esphome.components import switch
import esphome.config_validation as cv
from esphome.const import CONF_ID
from .. import const, generate, schema, validate
@ -16,15 +15,14 @@ OpenthermSwitch = generate.opentherm_ns.class_(
async def new_openthermswitch(config: dict[str, Any]) -> cg.Pvariable:
var = cg.new_Pvariable(config[CONF_ID])
var = await switch.new_switch(config)
await cg.register_component(var, config)
await switch.register_switch(var, config)
return var
def get_entity_validation_schema(entity: schema.SwitchSchema) -> cv.Schema:
return switch.SWITCH_SCHEMA.extend(
{cv.GenerateID(): cv.declare_id(OpenthermSwitch)}
return switch.switch_schema(
OpenthermSwitch, default_restore_mode=entity.default_mode
).extend(cv.COMPONENT_SCHEMA)