From e75a10ec7dd36377a64f38d4eb80a819fc6e84d2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 16 Oct 2026 10:44:08 -1000 Subject: [PATCH] [seeed_mr24hpc1] Use Apply entities for the forwarding buttons, switch, numbers and selects --- .../seeed_mr24hpc1/button/__init__.py | 17 +++---- .../seeed_mr24hpc1/number/__init__.py | 44 +++++++++++-------- .../seeed_mr24hpc1/select/__init__.py | 23 +++++----- .../seeed_mr24hpc1/switch/__init__.py | 13 +++--- 4 files changed, 54 insertions(+), 43 deletions(-) diff --git a/esphome/components/seeed_mr24hpc1/button/__init__.py b/esphome/components/seeed_mr24hpc1/button/__init__.py index 58c62652b09..c25e8381693 100644 --- a/esphome/components/seeed_mr24hpc1/button/__init__.py +++ b/esphome/components/seeed_mr24hpc1/button/__init__.py @@ -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()", + ) diff --git a/esphome/components/seeed_mr24hpc1/number/__init__.py b/esphome/components/seeed_mr24hpc1/number/__init__.py index 0dc6d07a96d..9e0a961bf96 100644 --- a/esphome/components/seeed_mr24hpc1/number/__init__.py +++ b/esphome/components/seeed_mr24hpc1/number/__init__.py @@ -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)", ) diff --git a/esphome/components/seeed_mr24hpc1/select/__init__.py b/esphome/components/seeed_mr24hpc1/select/__init__.py index 208040e9e05..9f9dc270a5a 100644 --- a/esphome/components/seeed_mr24hpc1/select/__init__.py +++ b/esphome/components/seeed_mr24hpc1/select/__init__.py @@ -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", ) diff --git a/esphome/components/seeed_mr24hpc1/switch/__init__.py b/esphome/components/seeed_mr24hpc1/switch/__init__.py index 76e8a2089bc..9fdbf4a6d8a 100644 --- a/esphome/components/seeed_mr24hpc1/switch/__init__.py +++ b/esphome/components/seeed_mr24hpc1/switch/__init__.py @@ -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", )