Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Seeed Studio mmWave Kit MR24HPC1 #5761

Merged
merged 81 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
a13e46b
Add Seeed Studio mmWave Kit MR24HPC1
limengdu Nov 14, 2023
a7c2add
Delete Chinese comments
limengdu Nov 14, 2023
1910541
Merge branch 'esphome:dev' into dev
limengdu Nov 15, 2023
15915c8
Fix suggested changes
limengdu Nov 15, 2023
b9f5a08
Fix suggested changes
limengdu Nov 15, 2023
1beb851
Fix suggested changes
limengdu Nov 15, 2023
b113d0c
Fix run flake8 problem
limengdu Nov 15, 2023
864f2d9
Fix run flake8 problem
limengdu Nov 15, 2023
ee5dcf6
Merge branch 'esphome:dev' into dev
limengdu Dec 5, 2023
15c98f0
Complete all development of the Seeed MR24HPC1 radar.
limengdu Dec 5, 2023
fe47cca
fix check
limengdu Dec 5, 2023
3e86f69
fix check
limengdu Dec 5, 2023
ab592bf
fix check
limengdu Dec 5, 2023
de19b17
fix
limengdu Dec 6, 2023
9f94d7d
try to tix
limengdu Dec 6, 2023
719326f
try to tix
limengdu Dec 6, 2023
e1953db
try to tix
limengdu Dec 6, 2023
d05a7cd
try to tix
limengdu Dec 6, 2023
0b4fba8
Merge branch 'dev' into dev
limengdu Dec 6, 2023
f168c07
try to tix
limengdu Dec 6, 2023
c1a3231
fix
limengdu Dec 6, 2023
0605700
build codeowner
peterpanstechland Dec 6, 2023
2217436
Merge pull request #1 from peterpanstechland/dev
limengdu Dec 7, 2023
911e568
Merge branch 'esphome:dev' into dev
limengdu Dec 7, 2023
0fc370c
adapt esphome content
limengdu Dec 7, 2023
7acf171
adapt esphome content
limengdu Dec 7, 2023
18be79e
fix
limengdu Dec 7, 2023
db45386
fix
limengdu Dec 7, 2023
be2068b
fix
limengdu Dec 7, 2023
92d0d78
Optimising loop logic
limengdu Dec 7, 2023
dc76727
fix
limengdu Dec 7, 2023
3867997
fix clang-tidy bug
limengdu Dec 7, 2023
3e38fcf
fix clang-tidy bug
limengdu Dec 7, 2023
84a1413
fix clang-format
limengdu Dec 7, 2023
dc27262
fix clang-tidy
limengdu Dec 7, 2023
1441e07
Add test
limengdu Dec 11, 2023
d4a7cd0
Add test
limengdu Dec 11, 2023
9b51e1e
fix
limengdu Dec 11, 2023
e2a5d89
fix
limengdu Dec 11, 2023
30d9eb2
Possible problems caused by empty components
limengdu Dec 11, 2023
1ebc720
fix
limengdu Dec 11, 2023
0be4392
Merge branch 'dev' into dev
limengdu Dec 12, 2023
49fb988
Update esphome/components/seeed_mr24hpc1/__init__.py
limengdu Dec 14, 2023
60dff91
Update esphome/components/seeed_mr24hpc1/__init__.py
limengdu Dec 14, 2023
e5f841b
Update esphome/components/seeed_mr24hpc1/binary_sensor.py
limengdu Dec 14, 2023
d346fc5
Update esphome/components/seeed_mr24hpc1/binary_sensor.py
limengdu Dec 14, 2023
545fa42
Update esphome/components/seeed_mr24hpc1/seeed_mr24hpc1.h
limengdu Dec 14, 2023
e4fe8ed
Update esphome/components/seeed_mr24hpc1/number/__init__.py
limengdu Dec 14, 2023
4a97e0a
Update esphome/components/seeed_mr24hpc1/number/__init__.py
limengdu Dec 14, 2023
76e2a68
Update esphome/components/seeed_mr24hpc1/seeed_mr24hpc1.cpp
limengdu Dec 14, 2023
b74f266
Update esphome/components/seeed_mr24hpc1/seeed_mr24hpc1.cpp
limengdu Dec 14, 2023
d69508b
Update esphome/components/seeed_mr24hpc1/seeed_mr24hpc1.cpp
limengdu Dec 14, 2023
25fa4e5
Update esphome/components/seeed_mr24hpc1/seeed_mr24hpc1.cpp
limengdu Dec 14, 2023
8816ac4
Update esphome/components/seeed_mr24hpc1/seeed_mr24hpc1.cpp
limengdu Dec 14, 2023
cb15421
Update esphome/components/seeed_mr24hpc1/seeed_mr24hpc1.h
limengdu Dec 14, 2023
def1cc7
Update esphome/components/seeed_mr24hpc1/seeed_mr24hpc1.h
limengdu Dec 14, 2023
83fe3c5
Fix: seeed mmwave kit advise
limengdu Dec 20, 2023
f455a89
Update: test1.yaml file
limengdu Dec 20, 2023
0124cc2
Merge branch 'dev' into dev
limengdu Dec 20, 2023
5e594e2
fix
limengdu Dec 20, 2023
2c3f060
del files
limengdu Dec 20, 2023
6725e0a
Update
limengdu Dec 20, 2023
6c000d1
Merge branch 'dev' into dev
limengdu Dec 21, 2023
4219ec5
Merge branch 'dev' into dev
limengdu Dec 22, 2023
d93928e
Merge branch 'dev' into dev
limengdu Dec 22, 2023
5cd7034
Merge branch 'dev' into dev
limengdu Dec 22, 2023
a794d80
Merge branch 'dev' into dev
limengdu Dec 22, 2023
1af562a
Merge branch 'dev' into dev
limengdu Dec 22, 2023
e06f3d7
Merge branch 'dev' into dev
limengdu Dec 25, 2023
c240f9a
Merge branch 'dev' into dev
limengdu Jan 1, 2024
2d251ba
Merge branch 'dev' into dev
limengdu Jan 2, 2024
38e2098
Merge branch 'dev' into dev
limengdu Jan 5, 2024
a4503c5
Merge branch 'dev' into dev
limengdu Jan 17, 2024
a99ab81
Remove extra code
jesserockz Mar 11, 2024
992e408
Dont auto load main component
jesserockz Mar 11, 2024
7d5e6ca
Rename underly_open_function to underlying_open_function
jesserockz Mar 11, 2024
6c1043d
Move/create constants and tidy up some parts
jesserockz Mar 12, 2024
ef7fb02
Merge branch 'dev' into pr/limengdu/5761-1
jesserockz Mar 12, 2024
c527497
Move tests to new structure
jesserockz Mar 12, 2024
332d9a4
Fix
jesserockz Mar 12, 2024
c6f749f
More fixes
jesserockz Mar 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ esphome/components/scd4x/* @martgras @sjtrny
esphome/components/script/* @esphome/core
esphome/components/sdm_meter/* @jesserockz @polyfaces
esphome/components/sdp3x/* @Azimath
esphome/components/seeed_mr24hpc1/* @limengdu
esphome/components/selec_meter/* @sourabhjaiswal
esphome/components/select/* @esphome/core
esphome/components/sen0321/* @notjj
Expand Down
51 changes: 51 additions & 0 deletions esphome/components/seeed_mr24hpc1/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import uart
from esphome.const import CONF_ID

DEPENDENCIES = ["uart"]
# is the code owner of the relevant code base
CODEOWNERS = ["@limengdu"]
# The current component or platform can be configured or defined multiple times in the same configuration file.
MULTI_CONF = True

# This line of code creates a new namespace called mr24hpc1_ns.
# This namespace will be used as a prefix for all classes, functions and variables associated with the mr24hpc1_ns component, ensuring that they do not conflict with the names of other components.
mr24hpc1_ns = cg.esphome_ns.namespace("seeed_mr24hpc1")
# This MR24HPC1Component class will be a periodically polled UART device
MR24HPC1Component = mr24hpc1_ns.class_(
"MR24HPC1Component", cg.Component, uart.UARTDevice
)

CONF_MR24HPC1_ID = "mr24hpc1_id"

CONFIG_SCHEMA = (
cv.Schema(
{
cv.GenerateID(): cv.declare_id(MR24HPC1Component),
}
)
.extend(uart.UART_DEVICE_SCHEMA)
.extend(cv.COMPONENT_SCHEMA)
)

# A verification mode was created to verify the configuration parameters of a UART device named "seeed_mr24hpc1".
# This authentication mode requires that the device must have transmit and receive functionality, a parity mode of "NONE", and a stop bit of one.
FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema(
"seeed_mr24hpc1",
require_tx=True,
require_rx=True,
parity="NONE",
stop_bits=1,
)


# The async def keyword is used to define a concurrent function.
# Concurrent functions are special functions designed to work with Python's asyncio library to support asynchronous I/O operations.
async def to_code(config):
# This line of code creates a new Pvariable (a Python object representing a C++ variable) with the variable's ID taken from the configuration.
var = cg.new_Pvariable(config[CONF_ID])
# This line of code registers the newly created Pvariable as a component so that ESPHome can manage it at runtime.
await cg.register_component(var, config)
# This line of code registers the newly created Pvariable as a device.
await uart.register_uart_device(var, config)
23 changes: 23 additions & 0 deletions esphome/components/seeed_mr24hpc1/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import esphome.codegen as cg
from esphome.components import binary_sensor
import esphome.config_validation as cv
from esphome.const import (
DEVICE_CLASS_OCCUPANCY,
)
from . import CONF_MR24HPC1_ID, MR24HPC1Component

CONF_HAS_TARGET = "has_target"

CONFIG_SCHEMA = {
cv.GenerateID(CONF_MR24HPC1_ID): cv.use_id(MR24HPC1Component),
cv.Optional(CONF_HAS_TARGET): binary_sensor.binary_sensor_schema(
device_class=DEVICE_CLASS_OCCUPANCY, icon="mdi:motion-sensor"
),
}


async def to_code(config):
mr24hpc1_component = await cg.get_variable(config[CONF_MR24HPC1_ID])
if has_target_config := config.get(CONF_HAS_TARGET):
sens = await binary_sensor.new_binary_sensor(has_target_config)
cg.add(mr24hpc1_component.set_has_target_binary_sensor(sens))
42 changes: 42 additions & 0 deletions esphome/components/seeed_mr24hpc1/button/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import esphome.codegen as cg
from esphome.components import button
import esphome.config_validation as cv
from esphome.const import (
DEVICE_CLASS_RESTART,
ENTITY_CATEGORY_CONFIG,
ICON_RESTART_ALERT,
)
from .. import CONF_MR24HPC1_ID, MR24HPC1Component, mr24hpc1_ns

RestartButton = mr24hpc1_ns.class_("RestartButton", button.Button)
CustomSetEndButton = mr24hpc1_ns.class_("CustomSetEndButton", button.Button)

CONF_RESTART = "restart"
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,
device_class=DEVICE_CLASS_RESTART,
entity_category=ENTITY_CATEGORY_CONFIG,
icon=ICON_RESTART_ALERT,
),
cv.Optional(CONF_CUSTOM_SET_END): button.button_schema(
CustomSetEndButton,
entity_category=ENTITY_CATEGORY_CONFIG,
icon="mdi:cog",
),
}


async def to_code(config):
mr24hpc1_component = await cg.get_variable(config[CONF_MR24HPC1_ID])
if restart_config := config.get(CONF_RESTART):
b = await button.new_button(restart_config)
await cg.register_parented(b, config[CONF_MR24HPC1_ID])
cg.add(mr24hpc1_component.set_restart_button(b))
if custom_set_end_config := config.get(CONF_CUSTOM_SET_END):
b = await button.new_button(custom_set_end_config)
await cg.register_parented(b, config[CONF_MR24HPC1_ID])
cg.add(mr24hpc1_component.set_custom_set_end_button(b))
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "custom_mode_end_button.h"

namespace esphome {
namespace seeed_mr24hpc1 {

void CustomSetEndButton::press_action() { this->parent_->set_custom_end_mode(); }

} // namespace seeed_mr24hpc1
} // namespace esphome
18 changes: 18 additions & 0 deletions esphome/components/seeed_mr24hpc1/button/custom_mode_end_button.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include "esphome/components/button/button.h"
#include "../seeed_mr24hpc1.h"

namespace esphome {
namespace seeed_mr24hpc1 {

class CustomSetEndButton : public button::Button, public Parented<MR24HPC1Component> {
public:
CustomSetEndButton() = default;

protected:
void press_action() override;
};

} // namespace seeed_mr24hpc1
} // namespace esphome
9 changes: 9 additions & 0 deletions esphome/components/seeed_mr24hpc1/button/restart_button.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "restart_button.h"

namespace esphome {
namespace seeed_mr24hpc1 {

void RestartButton::press_action() { this->parent_->set_restart(); }

} // namespace seeed_mr24hpc1
} // namespace esphome
18 changes: 18 additions & 0 deletions esphome/components/seeed_mr24hpc1/button/restart_button.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include "esphome/components/button/button.h"
#include "../seeed_mr24hpc1.h"

namespace esphome {
namespace seeed_mr24hpc1 {

class RestartButton : public button::Button, public Parented<MR24HPC1Component> {
public:
RestartButton() = default;

protected:
void press_action() override;
};

} // namespace seeed_mr24hpc1
} // namespace esphome
132 changes: 132 additions & 0 deletions esphome/components/seeed_mr24hpc1/number/__init__.py
Original file line number Diff line number Diff line change
@@ -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))
12 changes: 12 additions & 0 deletions esphome/components/seeed_mr24hpc1/number/custom_mode_number.cpp
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions esphome/components/seeed_mr24hpc1/number/custom_mode_number.h
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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