[seeed_mr60fda2] Use Apply entities for the forwarding buttons and selects

This commit is contained in:
J. Nick Koston
2026-10-16 10:48:31 -10:00
parent 5df5d44516
commit f0ea8edfad
40 changed files with 26 additions and 479 deletions
@@ -1,7 +0,0 @@
#include "custom_mode_end_button.h"
namespace esphome::seeed_mr24hpc1 {
void CustomSetEndButton::press_action() { this->parent_->set_custom_end_mode(); }
} // namespace esphome::seeed_mr24hpc1
@@ -1,16 +0,0 @@
#pragma once
#include "esphome/components/button/button.h"
#include "../seeed_mr24hpc1.h"
namespace esphome::seeed_mr24hpc1 {
class CustomSetEndButton final : public button::Button, public Parented<MR24HPC1Component> {
public:
CustomSetEndButton() = default;
protected:
void press_action() override;
};
} // namespace esphome::seeed_mr24hpc1
@@ -1,7 +0,0 @@
#include "restart_button.h"
namespace esphome::seeed_mr24hpc1 {
void RestartButton::press_action() { this->parent_->set_restart(); }
} // namespace esphome::seeed_mr24hpc1
@@ -1,16 +0,0 @@
#pragma once
#include "esphome/components/button/button.h"
#include "../seeed_mr24hpc1.h"
namespace esphome::seeed_mr24hpc1 {
class RestartButton final : public button::Button, public Parented<MR24HPC1Component> {
public:
RestartButton() = default;
protected:
void press_action() override;
};
} // namespace esphome::seeed_mr24hpc1
@@ -1,10 +0,0 @@
#include "custom_mode_number.h"
namespace esphome::seeed_mr24hpc1 {
void CustomModeNumber::control(float value) {
this->publish_state(value);
this->parent_->set_custom_mode(value);
}
} // namespace esphome::seeed_mr24hpc1
@@ -1,16 +0,0 @@
#pragma once
#include "esphome/components/number/number.h"
#include "../seeed_mr24hpc1.h"
namespace esphome::seeed_mr24hpc1 {
class CustomModeNumber final : public number::Number, public Parented<MR24HPC1Component> {
public:
CustomModeNumber() = default;
protected:
void control(float value) override;
};
} // namespace esphome::seeed_mr24hpc1
@@ -1,7 +0,0 @@
#include "custom_unman_time_number.h"
namespace esphome::seeed_mr24hpc1 {
void CustomUnmanTimeNumber::control(float value) { this->parent_->set_custom_unman_time(value); }
} // namespace esphome::seeed_mr24hpc1
@@ -1,16 +0,0 @@
#pragma once
#include "esphome/components/number/number.h"
#include "../seeed_mr24hpc1.h"
namespace esphome::seeed_mr24hpc1 {
class CustomUnmanTimeNumber final : public number::Number, public Parented<MR24HPC1Component> {
public:
CustomUnmanTimeNumber() = default;
protected:
void control(float value) override;
};
} // namespace esphome::seeed_mr24hpc1
@@ -1,7 +0,0 @@
#include "existence_threshold_number.h"
namespace esphome::seeed_mr24hpc1 {
void ExistenceThresholdNumber::control(float value) { this->parent_->set_existence_threshold(value); }
} // namespace esphome::seeed_mr24hpc1
@@ -1,16 +0,0 @@
#pragma once
#include "esphome/components/number/number.h"
#include "../seeed_mr24hpc1.h"
namespace esphome::seeed_mr24hpc1 {
class ExistenceThresholdNumber final : public number::Number, public Parented<MR24HPC1Component> {
public:
ExistenceThresholdNumber() = default;
protected:
void control(float value) override;
};
} // namespace esphome::seeed_mr24hpc1
@@ -1,7 +0,0 @@
#include "motion_threshold_number.h"
namespace esphome::seeed_mr24hpc1 {
void MotionThresholdNumber::control(float value) { this->parent_->set_motion_threshold(value); }
} // namespace esphome::seeed_mr24hpc1
@@ -1,16 +0,0 @@
#pragma once
#include "esphome/components/number/number.h"
#include "../seeed_mr24hpc1.h"
namespace esphome::seeed_mr24hpc1 {
class MotionThresholdNumber final : public number::Number, public Parented<MR24HPC1Component> {
public:
MotionThresholdNumber() = default;
protected:
void control(float value) override;
};
} // namespace esphome::seeed_mr24hpc1
@@ -1,7 +0,0 @@
#include "motion_trigger_time_number.h"
namespace esphome::seeed_mr24hpc1 {
void MotionTriggerTimeNumber::control(float value) { this->parent_->set_motion_trigger_time(value); }
} // namespace esphome::seeed_mr24hpc1
@@ -1,16 +0,0 @@
#pragma once
#include "esphome/components/number/number.h"
#include "../seeed_mr24hpc1.h"
namespace esphome::seeed_mr24hpc1 {
class MotionTriggerTimeNumber final : public number::Number, public Parented<MR24HPC1Component> {
public:
MotionTriggerTimeNumber() = default;
protected:
void control(float value) override;
};
} // namespace esphome::seeed_mr24hpc1
@@ -1,7 +0,0 @@
#include "motiontorest_time_number.h"
namespace esphome::seeed_mr24hpc1 {
void MotionToRestTimeNumber::control(float value) { this->parent_->set_motion_to_rest_time(value); }
} // namespace esphome::seeed_mr24hpc1
@@ -1,16 +0,0 @@
#pragma once
#include "esphome/components/number/number.h"
#include "../seeed_mr24hpc1.h"
namespace esphome::seeed_mr24hpc1 {
class MotionToRestTimeNumber final : public number::Number, public Parented<MR24HPC1Component> {
public:
MotionToRestTimeNumber() = default;
protected:
void control(float value) override;
};
} // namespace esphome::seeed_mr24hpc1
@@ -1,7 +0,0 @@
#include "sensitivity_number.h"
namespace esphome::seeed_mr24hpc1 {
void SensitivityNumber::control(float value) { this->parent_->set_sensitivity(value); }
} // namespace esphome::seeed_mr24hpc1
@@ -1,16 +0,0 @@
#pragma once
#include "esphome/components/number/number.h"
#include "../seeed_mr24hpc1.h"
namespace esphome::seeed_mr24hpc1 {
class SensitivityNumber final : public number::Number, public Parented<MR24HPC1Component> {
public:
SensitivityNumber() = default;
protected:
void control(float value) override;
};
} // namespace esphome::seeed_mr24hpc1
@@ -1,10 +0,0 @@
#include "existence_boundary_select.h"
namespace esphome::seeed_mr24hpc1 {
void ExistenceBoundarySelect::control(size_t index) {
this->publish_state(index);
this->parent_->set_existence_boundary(index);
}
} // namespace esphome::seeed_mr24hpc1
@@ -1,16 +0,0 @@
#pragma once
#include "esphome/components/select/select.h"
#include "../seeed_mr24hpc1.h"
namespace esphome::seeed_mr24hpc1 {
class ExistenceBoundarySelect final : public select::Select, public Parented<MR24HPC1Component> {
public:
ExistenceBoundarySelect() = default;
protected:
void control(size_t index) override;
};
} // namespace esphome::seeed_mr24hpc1
@@ -1,10 +0,0 @@
#include "motion_boundary_select.h"
namespace esphome::seeed_mr24hpc1 {
void MotionBoundarySelect::control(size_t index) {
this->publish_state(index);
this->parent_->set_motion_boundary(index);
}
} // namespace esphome::seeed_mr24hpc1
@@ -1,16 +0,0 @@
#pragma once
#include "esphome/components/select/select.h"
#include "../seeed_mr24hpc1.h"
namespace esphome::seeed_mr24hpc1 {
class MotionBoundarySelect final : public select::Select, public Parented<MR24HPC1Component> {
public:
MotionBoundarySelect() = default;
protected:
void control(size_t index) override;
};
} // namespace esphome::seeed_mr24hpc1
@@ -1,10 +0,0 @@
#include "scene_mode_select.h"
namespace esphome::seeed_mr24hpc1 {
void SceneModeSelect::control(size_t index) {
this->publish_state(index);
this->parent_->set_scene_mode(index);
}
} // namespace esphome::seeed_mr24hpc1
@@ -1,16 +0,0 @@
#pragma once
#include "esphome/components/select/select.h"
#include "../seeed_mr24hpc1.h"
namespace esphome::seeed_mr24hpc1 {
class SceneModeSelect final : public select::Select, public Parented<MR24HPC1Component> {
public:
SceneModeSelect() = default;
protected:
void control(size_t index) override;
};
} // namespace esphome::seeed_mr24hpc1
@@ -1,10 +0,0 @@
#include "unman_time_select.h"
namespace esphome::seeed_mr24hpc1 {
void UnmanTimeSelect::control(size_t index) {
this->publish_state(index);
this->parent_->set_unman_time(index);
}
} // namespace esphome::seeed_mr24hpc1
@@ -1,16 +0,0 @@
#pragma once
#include "esphome/components/select/select.h"
#include "../seeed_mr24hpc1.h"
namespace esphome::seeed_mr24hpc1 {
class UnmanTimeSelect final : public select::Select, public Parented<MR24HPC1Component> {
public:
UnmanTimeSelect() = default;
protected:
void control(size_t index) override;
};
} // namespace esphome::seeed_mr24hpc1
@@ -1,10 +0,0 @@
#include "underlyFuc_switch.h"
namespace esphome::seeed_mr24hpc1 {
void UnderlyOpenFunctionSwitch::write_state(bool state) {
this->publish_state(state);
this->parent_->set_underlying_open_function(state);
}
} // namespace esphome::seeed_mr24hpc1
@@ -1,16 +0,0 @@
#pragma once
#include "esphome/components/switch/switch.h"
#include "../seeed_mr24hpc1.h"
namespace esphome::seeed_mr24hpc1 {
class UnderlyOpenFunctionSwitch final : public switch_::Switch, public Parented<MR24HPC1Component> {
public:
UnderlyOpenFunctionSwitch() = default;
protected:
void write_state(bool state) override;
};
} // namespace esphome::seeed_mr24hpc1
@@ -10,24 +10,22 @@ from esphome.const import (
)
from esphome.types import ConfigType
from .. import CONF_MR60FDA2_ID, MR60FDA2Component, mr60fda2_ns
from .. import CONF_MR60FDA2_ID, MR60FDA2Component
DEPENDENCIES = ["seeed_mr60fda2"]
GetRadarParametersButton = mr60fda2_ns.class_("GetRadarParametersButton", button.Button)
ResetRadarButton = mr60fda2_ns.class_("ResetRadarButton", button.Button)
CONF_GET_RADAR_PARAMETERS = "get_radar_parameters"
CONFIG_SCHEMA = {
cv.GenerateID(CONF_MR60FDA2_ID): cv.use_id(MR60FDA2Component),
cv.Optional(CONF_GET_RADAR_PARAMETERS): button.button_schema(
GetRadarParametersButton,
button.ApplyButton,
device_class=DEVICE_CLASS_UPDATE,
entity_category=ENTITY_CATEGORY_NONE,
),
cv.Optional(CONF_FACTORY_RESET): button.button_schema(
ResetRadarButton,
button.ApplyButton,
device_class=DEVICE_CLASS_RESTART,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
@@ -37,5 +35,11 @@ CONFIG_SCHEMA = {
async def to_code(config: ConfigType) -> None:
hub = await cg.get_variable(config[CONF_MR60FDA2_ID])
buttons = button.sub_buttons(config, parent=hub)
await buttons(CONF_GET_RADAR_PARAMETERS, hub.set_get_radar_parameters_button)
await buttons(CONF_FACTORY_RESET, hub.set_factory_reset_button)
await buttons(
CONF_GET_RADAR_PARAMETERS,
hub.set_get_radar_parameters_button,
apply="get_radar_parameters()",
)
await buttons(
CONF_FACTORY_RESET, hub.set_factory_reset_button, apply="factory_reset()"
)
@@ -1,7 +0,0 @@
#include "get_radar_parameters_button.h"
namespace esphome::seeed_mr60fda2 {
void GetRadarParametersButton::press_action() { this->parent_->get_radar_parameters(); }
} // namespace esphome::seeed_mr60fda2
@@ -1,16 +0,0 @@
#pragma once
#include "esphome/components/button/button.h"
#include "../seeed_mr60fda2.h"
namespace esphome::seeed_mr60fda2 {
class GetRadarParametersButton final : public button::Button, public Parented<MR60FDA2Component> {
public:
GetRadarParametersButton() = default;
protected:
void press_action() override;
};
} // namespace esphome::seeed_mr60fda2
@@ -1,7 +0,0 @@
#include "reset_radar_button.h"
namespace esphome::seeed_mr60fda2 {
void ResetRadarButton::press_action() { this->parent_->factory_reset(); }
} // namespace esphome::seeed_mr60fda2
@@ -1,16 +0,0 @@
#pragma once
#include "esphome/components/button/button.h"
#include "../seeed_mr60fda2.h"
namespace esphome::seeed_mr60fda2 {
class ResetRadarButton final : public button::Button, public Parented<MR60FDA2Component> {
public:
ResetRadarButton() = default;
protected:
void press_action() override;
};
} // namespace esphome::seeed_mr60fda2
@@ -4,13 +4,10 @@ import esphome.config_validation as cv
from esphome.const import CONF_SENSITIVITY, ENTITY_CATEGORY_CONFIG, ICON_ACCELERATION_Z
from esphome.types import ConfigType
from .. import CONF_MR60FDA2_ID, MR60FDA2Component, mr60fda2_ns
from .. import CONF_MR60FDA2_ID, MR60FDA2Component
DEPENDENCIES = ["seeed_mr60fda2"]
InstallHeightSelect = mr60fda2_ns.class_("InstallHeightSelect", select.Select)
HeightThresholdSelect = mr60fda2_ns.class_("HeightThresholdSelect", select.Select)
SensitivitySelect = mr60fda2_ns.class_("SensitivitySelect", select.Select)
CONF_INSTALL_HEIGHT = "install_height"
CONF_HEIGHT_THRESHOLD = "height_threshold"
@@ -18,17 +15,17 @@ CONF_HEIGHT_THRESHOLD = "height_threshold"
CONFIG_SCHEMA = {
cv.GenerateID(CONF_MR60FDA2_ID): cv.use_id(MR60FDA2Component),
cv.Optional(CONF_INSTALL_HEIGHT): select.select_schema(
InstallHeightSelect,
select.ApplySelect,
entity_category=ENTITY_CATEGORY_CONFIG,
icon=ICON_ACCELERATION_Z,
),
cv.Optional(CONF_HEIGHT_THRESHOLD): select.select_schema(
HeightThresholdSelect,
select.ApplySelect,
entity_category=ENTITY_CATEGORY_CONFIG,
icon=ICON_ACCELERATION_Z,
),
cv.Optional(CONF_SENSITIVITY): select.select_schema(
SensitivitySelect,
select.ApplySelect,
entity_category=ENTITY_CATEGORY_CONFIG,
),
}
@@ -41,10 +38,20 @@ async def to_code(config: ConfigType) -> None:
CONF_INSTALL_HEIGHT,
hub.set_install_height_select,
options=["2.4m", "2.5m", "2.6m", "2.7m", "2.8m", "2.9m", "3.0m"],
apply="set_install_height(index)",
publish="before",
)
await selects(
CONF_HEIGHT_THRESHOLD,
hub.set_height_threshold_select,
options=["0.0m", "0.1m", "0.2m", "0.3m", "0.4m", "0.5m", "0.6m"],
apply="set_height_threshold(index)",
publish="before",
)
await selects(
CONF_SENSITIVITY,
hub.set_sensitivity_select,
options=["1", "2", "3"],
apply="set_sensitivity(index)",
publish="before",
)
await selects(CONF_SENSITIVITY, hub.set_sensitivity_select, options=["1", "2", "3"])
@@ -1,10 +0,0 @@
#include "height_threshold_select.h"
namespace esphome::seeed_mr60fda2 {
void HeightThresholdSelect::control(size_t index) {
this->publish_state(index);
this->parent_->set_height_threshold(index);
}
} // namespace esphome::seeed_mr60fda2
@@ -1,16 +0,0 @@
#pragma once
#include "esphome/components/select/select.h"
#include "../seeed_mr60fda2.h"
namespace esphome::seeed_mr60fda2 {
class HeightThresholdSelect final : public select::Select, public Parented<MR60FDA2Component> {
public:
HeightThresholdSelect() = default;
protected:
void control(size_t index) override;
};
} // namespace esphome::seeed_mr60fda2
@@ -1,10 +0,0 @@
#include "install_height_select.h"
namespace esphome::seeed_mr60fda2 {
void InstallHeightSelect::control(size_t index) {
this->publish_state(index);
this->parent_->set_install_height(index);
}
} // namespace esphome::seeed_mr60fda2
@@ -1,16 +0,0 @@
#pragma once
#include "esphome/components/select/select.h"
#include "../seeed_mr60fda2.h"
namespace esphome::seeed_mr60fda2 {
class InstallHeightSelect final : public select::Select, public Parented<MR60FDA2Component> {
public:
InstallHeightSelect() = default;
protected:
void control(size_t index) override;
};
} // namespace esphome::seeed_mr60fda2
@@ -1,10 +0,0 @@
#include "sensitivity_select.h"
namespace esphome::seeed_mr60fda2 {
void SensitivitySelect::control(size_t index) {
this->publish_state(index);
this->parent_->set_sensitivity(index);
}
} // namespace esphome::seeed_mr60fda2
@@ -1,16 +0,0 @@
#pragma once
#include "esphome/components/select/select.h"
#include "../seeed_mr60fda2.h"
namespace esphome::seeed_mr60fda2 {
class SensitivitySelect final : public select::Select, public Parented<MR60FDA2Component> {
public:
SensitivitySelect() = default;
protected:
void control(size_t index) override;
};
} // namespace esphome::seeed_mr60fda2