mirror of
https://github.com/esphome/esphome.git
synced 2026-10-19 12:42:50 +00:00
[seeed_mr24hpc1] Use Apply entities for the forwarding buttons, switch, numbers and selects
This commit is contained in:
@@ -9,23 +9,20 @@ from esphome.const import (
|
||||
)
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from .. import CONF_MR24HPC1_ID, MR24HPC1Component, mr24hpc1_ns
|
||||
|
||||
RestartButton = mr24hpc1_ns.class_("RestartButton", button.Button)
|
||||
CustomSetEndButton = mr24hpc1_ns.class_("CustomSetEndButton", button.Button)
|
||||
from .. import CONF_MR24HPC1_ID, MR24HPC1Component
|
||||
|
||||
CONF_CUSTOM_SET_END = "custom_set_end"
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_MR24HPC1_ID): cv.use_id(MR24HPC1Component),
|
||||
cv.Optional(CONF_RESTART): button.button_schema(
|
||||
RestartButton,
|
||||
button.ApplyButton,
|
||||
device_class=DEVICE_CLASS_RESTART,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_RESTART_ALERT,
|
||||
),
|
||||
cv.Optional(CONF_CUSTOM_SET_END): button.button_schema(
|
||||
CustomSetEndButton,
|
||||
button.ApplyButton,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon="mdi:cog",
|
||||
),
|
||||
@@ -35,5 +32,9 @@ CONFIG_SCHEMA = {
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
hub = await cg.get_variable(config[CONF_MR24HPC1_ID])
|
||||
buttons = button.sub_buttons(config, parent=hub)
|
||||
await buttons(CONF_RESTART, hub.set_restart_button)
|
||||
await buttons(CONF_CUSTOM_SET_END, hub.set_custom_set_end_button)
|
||||
await buttons(CONF_RESTART, hub.set_restart_button, apply="set_restart()")
|
||||
await buttons(
|
||||
CONF_CUSTOM_SET_END,
|
||||
hub.set_custom_set_end_button,
|
||||
apply="set_custom_end_mode()",
|
||||
)
|
||||
|
||||
@@ -4,15 +4,7 @@ import esphome.config_validation as cv
|
||||
from esphome.const import CONF_SENSITIVITY, ENTITY_CATEGORY_CONFIG
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from .. import CONF_MR24HPC1_ID, MR24HPC1Component, mr24hpc1_ns
|
||||
|
||||
SensitivityNumber = mr24hpc1_ns.class_("SensitivityNumber", number.Number)
|
||||
CustomModeNumber = mr24hpc1_ns.class_("CustomModeNumber", number.Number)
|
||||
ExistenceThresholdNumber = mr24hpc1_ns.class_("ExistenceThresholdNumber", number.Number)
|
||||
MotionThresholdNumber = mr24hpc1_ns.class_("MotionThresholdNumber", number.Number)
|
||||
MotionTriggerTimeNumber = mr24hpc1_ns.class_("MotionTriggerTimeNumber", number.Number)
|
||||
MotionToRestTimeNumber = mr24hpc1_ns.class_("MotionToRestTimeNumber", number.Number)
|
||||
CustomUnmanTimeNumber = mr24hpc1_ns.class_("CustomUnmanTimeNumber", number.Number)
|
||||
from .. import CONF_MR24HPC1_ID, MR24HPC1Component
|
||||
|
||||
CONF_CUSTOM_MODE = "custom_mode"
|
||||
CONF_EXISTENCE_THRESHOLD = "existence_threshold"
|
||||
@@ -25,37 +17,37 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(CONF_MR24HPC1_ID): cv.use_id(MR24HPC1Component),
|
||||
cv.Optional(CONF_SENSITIVITY): number.number_schema(
|
||||
SensitivityNumber,
|
||||
number.ApplyNumber,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon="mdi:archive-check-outline",
|
||||
),
|
||||
cv.Optional(CONF_CUSTOM_MODE): number.number_schema(
|
||||
CustomModeNumber,
|
||||
number.ApplyNumber,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon="mdi:cog",
|
||||
),
|
||||
cv.Optional(CONF_EXISTENCE_THRESHOLD): number.number_schema(
|
||||
ExistenceThresholdNumber,
|
||||
number.ApplyNumber,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
),
|
||||
cv.Optional(CONF_MOTION_THRESHOLD): number.number_schema(
|
||||
MotionThresholdNumber,
|
||||
number.ApplyNumber,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
),
|
||||
cv.Optional(CONF_MOTION_TRIGGER): number.number_schema(
|
||||
MotionTriggerTimeNumber,
|
||||
number.ApplyNumber,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon="mdi:camera-timer",
|
||||
unit_of_measurement="ms",
|
||||
),
|
||||
cv.Optional(CONF_MOTION_TO_REST): number.number_schema(
|
||||
MotionToRestTimeNumber,
|
||||
number.ApplyNumber,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon="mdi:camera-timer",
|
||||
unit_of_measurement="ms",
|
||||
),
|
||||
cv.Optional(CONF_CUSTOM_UNMAN_TIME): number.number_schema(
|
||||
CustomUnmanTimeNumber,
|
||||
number.ApplyNumber,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon="mdi:camera-timer",
|
||||
unit_of_measurement="s",
|
||||
@@ -68,10 +60,21 @@ async def to_code(config: ConfigType) -> None:
|
||||
hub = await cg.get_variable(config[CONF_MR24HPC1_ID])
|
||||
numbers = number.sub_numbers(config, parent=hub)
|
||||
await numbers(
|
||||
CONF_SENSITIVITY, hub.set_sensitivity_number, min_value=0, max_value=3, step=1
|
||||
CONF_SENSITIVITY,
|
||||
hub.set_sensitivity_number,
|
||||
min_value=0,
|
||||
max_value=3,
|
||||
step=1,
|
||||
apply="set_sensitivity(value)",
|
||||
)
|
||||
await numbers(
|
||||
CONF_CUSTOM_MODE, hub.set_custom_mode_number, min_value=0, max_value=4, step=1
|
||||
CONF_CUSTOM_MODE,
|
||||
hub.set_custom_mode_number,
|
||||
min_value=0,
|
||||
max_value=4,
|
||||
step=1,
|
||||
apply="set_custom_mode(value)",
|
||||
publish="before",
|
||||
)
|
||||
await numbers(
|
||||
CONF_EXISTENCE_THRESHOLD,
|
||||
@@ -79,6 +82,7 @@ async def to_code(config: ConfigType) -> None:
|
||||
min_value=0,
|
||||
max_value=250,
|
||||
step=1,
|
||||
apply="set_existence_threshold(value)",
|
||||
)
|
||||
await numbers(
|
||||
CONF_MOTION_THRESHOLD,
|
||||
@@ -86,6 +90,7 @@ async def to_code(config: ConfigType) -> None:
|
||||
min_value=0,
|
||||
max_value=250,
|
||||
step=1,
|
||||
apply="set_motion_threshold(value)",
|
||||
)
|
||||
await numbers(
|
||||
CONF_MOTION_TRIGGER,
|
||||
@@ -93,6 +98,7 @@ async def to_code(config: ConfigType) -> None:
|
||||
min_value=0,
|
||||
max_value=150,
|
||||
step=1,
|
||||
apply="set_motion_trigger_time(value)",
|
||||
)
|
||||
await numbers(
|
||||
CONF_MOTION_TO_REST,
|
||||
@@ -100,6 +106,7 @@ async def to_code(config: ConfigType) -> None:
|
||||
min_value=0,
|
||||
max_value=3000,
|
||||
step=1,
|
||||
apply="set_motion_to_rest_time(value)",
|
||||
)
|
||||
await numbers(
|
||||
CONF_CUSTOM_UNMAN_TIME,
|
||||
@@ -107,4 +114,5 @@ async def to_code(config: ConfigType) -> None:
|
||||
min_value=0,
|
||||
max_value=3600,
|
||||
step=1,
|
||||
apply="set_custom_unman_time(value)",
|
||||
)
|
||||
|
||||
@@ -4,12 +4,7 @@ import esphome.config_validation as cv
|
||||
from esphome.const import ENTITY_CATEGORY_CONFIG
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from .. import CONF_MR24HPC1_ID, MR24HPC1Component, mr24hpc1_ns
|
||||
|
||||
SceneModeSelect = mr24hpc1_ns.class_("SceneModeSelect", select.Select)
|
||||
UnmanTimeSelect = mr24hpc1_ns.class_("UnmanTimeSelect", select.Select)
|
||||
ExistenceBoundarySelect = mr24hpc1_ns.class_("ExistenceBoundarySelect", select.Select)
|
||||
MotionBoundarySelect = mr24hpc1_ns.class_("MotionBoundarySelect", select.Select)
|
||||
from .. import CONF_MR24HPC1_ID, MR24HPC1Component
|
||||
|
||||
CONF_SCENE_MODE = "scene_mode"
|
||||
CONF_UNMAN_TIME = "unman_time"
|
||||
@@ -19,21 +14,21 @@ CONF_MOTION_BOUNDARY = "motion_boundary"
|
||||
CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_MR24HPC1_ID): cv.use_id(MR24HPC1Component),
|
||||
cv.Optional(CONF_SCENE_MODE): select.select_schema(
|
||||
SceneModeSelect,
|
||||
select.ApplySelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon="mdi:hoop-house",
|
||||
),
|
||||
cv.Optional(CONF_UNMAN_TIME): select.select_schema(
|
||||
UnmanTimeSelect,
|
||||
select.ApplySelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon="mdi:timeline-clock",
|
||||
),
|
||||
cv.Optional(CONF_EXISTENCE_BOUNDARY): select.select_schema(
|
||||
ExistenceBoundarySelect,
|
||||
select.ApplySelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
),
|
||||
cv.Optional(CONF_MOTION_BOUNDARY): select.select_schema(
|
||||
MotionBoundarySelect,
|
||||
select.ApplySelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
),
|
||||
}
|
||||
@@ -46,6 +41,8 @@ async def to_code(config: ConfigType) -> None:
|
||||
CONF_SCENE_MODE,
|
||||
hub.set_scene_mode_select,
|
||||
options=["None", "Living Room", "Bedroom", "Washroom", "Area Detection"],
|
||||
apply="set_scene_mode(index)",
|
||||
publish="before",
|
||||
)
|
||||
await selects(
|
||||
CONF_UNMAN_TIME,
|
||||
@@ -61,6 +58,8 @@ async def to_code(config: ConfigType) -> None:
|
||||
"30min",
|
||||
"60min",
|
||||
],
|
||||
apply="set_unman_time(index)",
|
||||
publish="before",
|
||||
)
|
||||
await selects(
|
||||
CONF_EXISTENCE_BOUNDARY,
|
||||
@@ -77,6 +76,8 @@ async def to_code(config: ConfigType) -> None:
|
||||
"4.5m",
|
||||
"5.0m",
|
||||
],
|
||||
apply="set_existence_boundary(index)",
|
||||
publish="before",
|
||||
)
|
||||
await selects(
|
||||
CONF_MOTION_BOUNDARY,
|
||||
@@ -93,4 +94,6 @@ async def to_code(config: ConfigType) -> None:
|
||||
"4.5m",
|
||||
"5.0m",
|
||||
],
|
||||
apply="set_motion_boundary(index)",
|
||||
publish="before",
|
||||
)
|
||||
|
||||
@@ -4,18 +4,14 @@ import esphome.config_validation as cv
|
||||
from esphome.const import DEVICE_CLASS_SWITCH, ENTITY_CATEGORY_CONFIG
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from .. import CONF_MR24HPC1_ID, MR24HPC1Component, mr24hpc1_ns
|
||||
|
||||
UnderlyingOpenFuncSwitch = mr24hpc1_ns.class_(
|
||||
"UnderlyOpenFunctionSwitch", switch.Switch
|
||||
)
|
||||
from .. import CONF_MR24HPC1_ID, MR24HPC1Component
|
||||
|
||||
CONF_UNDERLYING_OPEN_FUNCTION = "underlying_open_function"
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_MR24HPC1_ID): cv.use_id(MR24HPC1Component),
|
||||
cv.Optional(CONF_UNDERLYING_OPEN_FUNCTION): switch.switch_schema(
|
||||
UnderlyingOpenFuncSwitch,
|
||||
switch.ApplySwitch,
|
||||
device_class=DEVICE_CLASS_SWITCH,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon="mdi:electric-switch",
|
||||
@@ -27,5 +23,8 @@ async def to_code(config: ConfigType) -> None:
|
||||
hub = await cg.get_variable(config[CONF_MR24HPC1_ID])
|
||||
switches = switch.sub_switches(config, parent=hub)
|
||||
await switches(
|
||||
CONF_UNDERLYING_OPEN_FUNCTION, hub.set_underlying_open_function_switch
|
||||
CONF_UNDERLYING_OPEN_FUNCTION,
|
||||
hub.set_underlying_open_function_switch,
|
||||
apply="set_underlying_open_function(state)",
|
||||
publish="before",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user