mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-06 04:48:27 +02:00
Add Seeed Studio mmWave Kit MR24HPC1 (#5761)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Co-authored-by: Peter Pan <twinkle-pirate@hotmail.com>
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import number
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import (
|
||||
ENTITY_CATEGORY_CONFIG,
|
||||
)
|
||||
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)
|
||||
|
||||
CONF_SENSITIVITY = "sensitivity"
|
||||
CONF_CUSTOM_MODE = "custom_mode"
|
||||
CONF_EXISTENCE_THRESHOLD = "existence_threshold"
|
||||
CONF_MOTION_THRESHOLD = "motion_threshold"
|
||||
CONF_MOTION_TRIGGER = "motion_trigger"
|
||||
CONF_MOTION_TO_REST = "motion_to_rest"
|
||||
CONF_CUSTOM_UNMAN_TIME = "custom_unman_time"
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(CONF_MR24HPC1_ID): cv.use_id(MR24HPC1Component),
|
||||
cv.Optional(CONF_SENSITIVITY): number.number_schema(
|
||||
SensitivityNumber,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon="mdi:archive-check-outline",
|
||||
),
|
||||
cv.Optional(CONF_CUSTOM_MODE): number.number_schema(
|
||||
CustomModeNumber,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon="mdi:cog",
|
||||
),
|
||||
cv.Optional(CONF_EXISTENCE_THRESHOLD): number.number_schema(
|
||||
ExistenceThresholdNumber,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
),
|
||||
cv.Optional(CONF_MOTION_THRESHOLD): number.number_schema(
|
||||
MotionThresholdNumber,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
),
|
||||
cv.Optional(CONF_MOTION_TRIGGER): number.number_schema(
|
||||
MotionTriggerTimeNumber,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon="mdi:camera-timer",
|
||||
unit_of_measurement="ms",
|
||||
),
|
||||
cv.Optional(CONF_MOTION_TO_REST): number.number_schema(
|
||||
MotionToRestTimeNumber,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon="mdi:camera-timer",
|
||||
unit_of_measurement="ms",
|
||||
),
|
||||
cv.Optional(CONF_CUSTOM_UNMAN_TIME): number.number_schema(
|
||||
CustomUnmanTimeNumber,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon="mdi:camera-timer",
|
||||
unit_of_measurement="s",
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
mr24hpc1_component = await cg.get_variable(config[CONF_MR24HPC1_ID])
|
||||
if sensitivity_config := config.get(CONF_SENSITIVITY):
|
||||
n = await number.new_number(
|
||||
sensitivity_config,
|
||||
min_value=0,
|
||||
max_value=3,
|
||||
step=1,
|
||||
)
|
||||
await cg.register_parented(n, mr24hpc1_component)
|
||||
cg.add(mr24hpc1_component.set_sensitivity_number(n))
|
||||
if custom_mode_config := config.get(CONF_CUSTOM_MODE):
|
||||
n = await number.new_number(
|
||||
custom_mode_config,
|
||||
min_value=0,
|
||||
max_value=4,
|
||||
step=1,
|
||||
)
|
||||
await cg.register_parented(n, mr24hpc1_component)
|
||||
cg.add(mr24hpc1_component.set_custom_mode_number(n))
|
||||
if existence_threshold_config := config.get(CONF_EXISTENCE_THRESHOLD):
|
||||
n = await number.new_number(
|
||||
existence_threshold_config,
|
||||
min_value=0,
|
||||
max_value=250,
|
||||
step=1,
|
||||
)
|
||||
await cg.register_parented(n, mr24hpc1_component)
|
||||
cg.add(mr24hpc1_component.set_existence_threshold_number(n))
|
||||
if motion_threshold_config := config.get(CONF_MOTION_THRESHOLD):
|
||||
n = await number.new_number(
|
||||
motion_threshold_config,
|
||||
min_value=0,
|
||||
max_value=250,
|
||||
step=1,
|
||||
)
|
||||
await cg.register_parented(n, mr24hpc1_component)
|
||||
cg.add(mr24hpc1_component.set_motion_threshold_number(n))
|
||||
if motion_trigger_config := config.get(CONF_MOTION_TRIGGER):
|
||||
n = await number.new_number(
|
||||
motion_trigger_config,
|
||||
min_value=0,
|
||||
max_value=150,
|
||||
step=1,
|
||||
)
|
||||
await cg.register_parented(n, mr24hpc1_component)
|
||||
cg.add(mr24hpc1_component.set_motion_trigger_number(n))
|
||||
if motion_to_rest_config := config.get(CONF_MOTION_TO_REST):
|
||||
n = await number.new_number(
|
||||
motion_to_rest_config,
|
||||
min_value=0,
|
||||
max_value=3000,
|
||||
step=1,
|
||||
)
|
||||
await cg.register_parented(n, mr24hpc1_component)
|
||||
cg.add(mr24hpc1_component.set_motion_to_rest_number(n))
|
||||
if custom_unman_time_config := config.get(CONF_CUSTOM_UNMAN_TIME):
|
||||
n = await number.new_number(
|
||||
custom_unman_time_config,
|
||||
min_value=0,
|
||||
max_value=3600,
|
||||
step=1,
|
||||
)
|
||||
await cg.register_parented(n, mr24hpc1_component)
|
||||
cg.add(mr24hpc1_component.set_custom_unman_time_number(n))
|
||||
@@ -0,0 +1,12 @@
|
||||
#include "custom_mode_number.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr24hpc1 {
|
||||
|
||||
void CustomModeNumber::control(float value) {
|
||||
this->publish_state(value);
|
||||
this->parent_->set_custom_mode(value);
|
||||
}
|
||||
|
||||
} // namespace seeed_mr24hpc1
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/number/number.h"
|
||||
#include "../seeed_mr24hpc1.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr24hpc1 {
|
||||
|
||||
class CustomModeNumber : public number::Number, public Parented<MR24HPC1Component> {
|
||||
public:
|
||||
CustomModeNumber() = default;
|
||||
|
||||
protected:
|
||||
void control(float value) override;
|
||||
};
|
||||
|
||||
} // namespace seeed_mr24hpc1
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "custom_unman_time_number.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr24hpc1 {
|
||||
|
||||
void CustomUnmanTimeNumber::control(float value) { this->parent_->set_custom_unman_time(value); }
|
||||
|
||||
} // namespace seeed_mr24hpc1
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/number/number.h"
|
||||
#include "../seeed_mr24hpc1.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr24hpc1 {
|
||||
|
||||
class CustomUnmanTimeNumber : public number::Number, public Parented<MR24HPC1Component> {
|
||||
public:
|
||||
CustomUnmanTimeNumber() = default;
|
||||
|
||||
protected:
|
||||
void control(float value) override;
|
||||
};
|
||||
|
||||
} // namespace seeed_mr24hpc1
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "existence_threshold_number.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr24hpc1 {
|
||||
|
||||
void ExistenceThresholdNumber::control(float value) { this->parent_->set_existence_threshold(value); }
|
||||
|
||||
} // namespace seeed_mr24hpc1
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/number/number.h"
|
||||
#include "../seeed_mr24hpc1.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr24hpc1 {
|
||||
|
||||
class ExistenceThresholdNumber : public number::Number, public Parented<MR24HPC1Component> {
|
||||
public:
|
||||
ExistenceThresholdNumber() = default;
|
||||
|
||||
protected:
|
||||
void control(float value) override;
|
||||
};
|
||||
|
||||
} // namespace seeed_mr24hpc1
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "motion_threshold_number.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr24hpc1 {
|
||||
|
||||
void MotionThresholdNumber::control(float value) { this->parent_->set_motion_threshold(value); }
|
||||
|
||||
} // namespace seeed_mr24hpc1
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/number/number.h"
|
||||
#include "../seeed_mr24hpc1.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr24hpc1 {
|
||||
|
||||
class MotionThresholdNumber : public number::Number, public Parented<MR24HPC1Component> {
|
||||
public:
|
||||
MotionThresholdNumber() = default;
|
||||
|
||||
protected:
|
||||
void control(float value) override;
|
||||
};
|
||||
|
||||
} // namespace seeed_mr24hpc1
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "motion_trigger_time_number.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr24hpc1 {
|
||||
|
||||
void MotionTriggerTimeNumber::control(float value) { this->parent_->set_motion_trigger_time(value); }
|
||||
|
||||
} // namespace seeed_mr24hpc1
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/number/number.h"
|
||||
#include "../seeed_mr24hpc1.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr24hpc1 {
|
||||
|
||||
class MotionTriggerTimeNumber : public number::Number, public Parented<MR24HPC1Component> {
|
||||
public:
|
||||
MotionTriggerTimeNumber() = default;
|
||||
|
||||
protected:
|
||||
void control(float value) override;
|
||||
};
|
||||
|
||||
} // namespace seeed_mr24hpc1
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "motiontorest_time_number.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr24hpc1 {
|
||||
|
||||
void MotionToRestTimeNumber::control(float value) { this->parent_->set_motion_to_rest_time(value); }
|
||||
|
||||
} // namespace seeed_mr24hpc1
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/number/number.h"
|
||||
#include "../seeed_mr24hpc1.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr24hpc1 {
|
||||
|
||||
class MotionToRestTimeNumber : public number::Number, public Parented<MR24HPC1Component> {
|
||||
public:
|
||||
MotionToRestTimeNumber() = default;
|
||||
|
||||
protected:
|
||||
void control(float value) override;
|
||||
};
|
||||
|
||||
} // namespace seeed_mr24hpc1
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "sensitivity_number.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr24hpc1 {
|
||||
|
||||
void SensitivityNumber::control(float value) { this->parent_->set_sensitivity(value); }
|
||||
|
||||
} // namespace seeed_mr24hpc1
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/number/number.h"
|
||||
#include "../seeed_mr24hpc1.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr24hpc1 {
|
||||
|
||||
class SensitivityNumber : public number::Number, public Parented<MR24HPC1Component> {
|
||||
public:
|
||||
SensitivityNumber() = default;
|
||||
|
||||
protected:
|
||||
void control(float value) override;
|
||||
};
|
||||
|
||||
} // namespace seeed_mr24hpc1
|
||||
} // namespace esphome
|
||||
Reference in New Issue
Block a user