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:
Citric Lee
2024-03-12 11:33:40 +08:00
committed by GitHub
parent 5b28bd3d97
commit 4bbde8357a
43 changed files with 2330 additions and 0 deletions
@@ -0,0 +1,103 @@
import esphome.codegen as cg
from esphome.components import select
import esphome.config_validation as cv
from esphome.const import (
ENTITY_CATEGORY_CONFIG,
)
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)
CONF_SCENE_MODE = "scene_mode"
CONF_UNMAN_TIME = "unman_time"
CONF_EXISTENCE_BOUNDARY = "existence_boundary"
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,
entity_category=ENTITY_CATEGORY_CONFIG,
icon="mdi:hoop-house",
),
cv.Optional(CONF_UNMAN_TIME): select.select_schema(
UnmanTimeSelect,
entity_category=ENTITY_CATEGORY_CONFIG,
icon="mdi:timeline-clock",
),
cv.Optional(CONF_EXISTENCE_BOUNDARY): select.select_schema(
ExistenceBoundarySelect,
entity_category=ENTITY_CATEGORY_CONFIG,
),
cv.Optional(CONF_MOTION_BOUNDARY): select.select_schema(
MotionBoundarySelect,
entity_category=ENTITY_CATEGORY_CONFIG,
),
}
async def to_code(config):
mr24hpc1_component = await cg.get_variable(config[CONF_MR24HPC1_ID])
if scenemode_config := config.get(CONF_SCENE_MODE):
s = await select.new_select(
scenemode_config,
options=["None", "Living Room", "Bedroom", "Washroom", "Area Detection"],
)
await cg.register_parented(s, config[CONF_MR24HPC1_ID])
cg.add(mr24hpc1_component.set_scene_mode_select(s))
if unmantime_config := config.get(CONF_UNMAN_TIME):
s = await select.new_select(
unmantime_config,
options=[
"None",
"10s",
"30s",
"1min",
"2min",
"5min",
"10min",
"30min",
"60min",
],
)
await cg.register_parented(s, config[CONF_MR24HPC1_ID])
cg.add(mr24hpc1_component.set_unman_time_select(s))
if existence_boundary_config := config.get(CONF_EXISTENCE_BOUNDARY):
s = await select.new_select(
existence_boundary_config,
options=[
"0.5m",
"1.0m",
"1.5m",
"2.0m",
"2.5m",
"3.0m",
"3.5m",
"4.0m",
"4.5m",
"5.0m",
],
)
await cg.register_parented(s, config[CONF_MR24HPC1_ID])
cg.add(mr24hpc1_component.set_existence_boundary_select(s))
if motion_boundary_config := config.get(CONF_MOTION_BOUNDARY):
s = await select.new_select(
motion_boundary_config,
options=[
"0.5m",
"1.0m",
"1.5m",
"2.0m",
"2.5m",
"3.0m",
"3.5m",
"4.0m",
"4.5m",
"5.0m",
],
)
await cg.register_parented(s, config[CONF_MR24HPC1_ID])
cg.add(mr24hpc1_component.set_motion_boundary_select(s))
@@ -0,0 +1,15 @@
#include "existence_boundary_select.h"
namespace esphome {
namespace seeed_mr24hpc1 {
void ExistenceBoundarySelect::control(const std::string &value) {
this->publish_state(value);
auto index = this->index_of(value);
if (index.has_value()) {
this->parent_->set_existence_boundary(index.value());
}
}
} // namespace seeed_mr24hpc1
} // namespace esphome
@@ -0,0 +1,18 @@
#pragma once
#include "esphome/components/select/select.h"
#include "../seeed_mr24hpc1.h"
namespace esphome {
namespace seeed_mr24hpc1 {
class ExistenceBoundarySelect : public select::Select, public Parented<MR24HPC1Component> {
public:
ExistenceBoundarySelect() = default;
protected:
void control(const std::string &value) override;
};
} // namespace seeed_mr24hpc1
} // namespace esphome
@@ -0,0 +1,15 @@
#include "motion_boundary_select.h"
namespace esphome {
namespace seeed_mr24hpc1 {
void MotionBoundarySelect::control(const std::string &value) {
this->publish_state(value);
auto index = this->index_of(value);
if (index.has_value()) {
this->parent_->set_motion_boundary(index.value());
}
}
} // namespace seeed_mr24hpc1
} // namespace esphome
@@ -0,0 +1,18 @@
#pragma once
#include "esphome/components/select/select.h"
#include "../seeed_mr24hpc1.h"
namespace esphome {
namespace seeed_mr24hpc1 {
class MotionBoundarySelect : public select::Select, public Parented<MR24HPC1Component> {
public:
MotionBoundarySelect() = default;
protected:
void control(const std::string &value) override;
};
} // namespace seeed_mr24hpc1
} // namespace esphome
@@ -0,0 +1,15 @@
#include "scene_mode_select.h"
namespace esphome {
namespace seeed_mr24hpc1 {
void SceneModeSelect::control(const std::string &value) {
this->publish_state(value);
auto index = this->index_of(value);
if (index.has_value()) {
this->parent_->set_scene_mode(index.value());
}
}
} // namespace seeed_mr24hpc1
} // namespace esphome
@@ -0,0 +1,18 @@
#pragma once
#include "esphome/components/select/select.h"
#include "../seeed_mr24hpc1.h"
namespace esphome {
namespace seeed_mr24hpc1 {
class SceneModeSelect : public select::Select, public Parented<MR24HPC1Component> {
public:
SceneModeSelect() = default;
protected:
void control(const std::string &value) override;
};
} // namespace seeed_mr24hpc1
} // namespace esphome
@@ -0,0 +1,15 @@
#include "unman_time_select.h"
namespace esphome {
namespace seeed_mr24hpc1 {
void UnmanTimeSelect::control(const std::string &value) {
this->publish_state(value);
auto index = this->index_of(value);
if (index.has_value()) {
this->parent_->set_unman_time(index.value());
}
}
} // namespace seeed_mr24hpc1
} // namespace esphome
@@ -0,0 +1,18 @@
#pragma once
#include "esphome/components/select/select.h"
#include "../seeed_mr24hpc1.h"
namespace esphome {
namespace seeed_mr24hpc1 {
class UnmanTimeSelect : public select::Select, public Parented<MR24HPC1Component> {
public:
UnmanTimeSelect() = default;
protected:
void control(const std::string &value) override;
};
} // namespace seeed_mr24hpc1
} // namespace esphome