2#ifdef LD2450_POLYGON_ZONE_COUNT
18 ESP_LOGW(TAG,
"'%s': saved polygon is invalid; zone disabled", this->
get_name().c_str());
26 char polygon_s[POLYGON_STR_SIZE];
28 LOG_TEXT(
" ",
"PolygonZone",
this);
29 ESP_LOGCONFIG(TAG,
" Polygon: '%s'", polygon_s);
30 LOG_BINARY_SENSOR(
" ",
"Presence", this->
presence_);
35 if (!polygon.
parse(value.c_str(), value.size())) {
36 ESP_LOGW(TAG,
"'%s': invalid polygon '%s'; expected 'x,y;x,y;...' with %u to %u points", this->
get_name().c_str(),
37 value.c_str(), MIN_POLYGON_POINTS, MAX_POLYGON_POINTS);
40 ESP_LOGW(TAG,
"'%s': could not save the polygon; keeping the previous one", this->
get_name().c_str());
53 char polygon_s[POLYGON_STR_SIZE];
const StringRef & get_name() const
ESPPreferenceObject make_entity_preference(uint32_t version=0)
Create a preference object for storing this entity's state/settings.
void invalidate_state()
Clear the state — sets has_state() to false and fires callbacks with nullopt.
void setup()
Load the saved polygon and publish it. Called from the hub's setup().
ESPPreferenceObject pref_
void control(const std::string &value) override
binary_sensor::BinarySensor * presence_
void publish_state(const std::string &state)
ESPHOME_LOG_TAG(TAG, "ld2450")
A polygon in radar coordinates. Trivially copyable so it can be saved to preferences as-is.
void format(char *buf) const
Write the polygon as "x,y;x,y;..." into buf, which must hold at least POLYGON_STR_SIZE bytes.
bool parse(const char *str, size_t len)
Parse "x,y;x,y;..." (mm) into this polygon.
bool is_valid() const
True when the polygon is empty, or has a valid number of points that are all inside the radar area.
bool empty() const
True when the polygon has no points, which disables the zone.