mirror of
https://github.com/esphome/esphome.git
synced 2025-11-10 11:55:52 +00:00
cleanups
This commit is contained in:
@@ -244,6 +244,9 @@ async def to_code(config):
|
|||||||
var = cg.new_Pvariable(config[CONF_ID])
|
var = cg.new_Pvariable(config[CONF_ID])
|
||||||
await cg.register_component(var, config)
|
await cg.register_component(var, config)
|
||||||
|
|
||||||
|
# Track controller registration for StaticVector sizing
|
||||||
|
CORE.register_controller()
|
||||||
|
|
||||||
cg.add(var.set_port(config[CONF_PORT]))
|
cg.add(var.set_port(config[CONF_PORT]))
|
||||||
if config[CONF_PASSWORD]:
|
if config[CONF_PASSWORD]:
|
||||||
cg.add_define("USE_API_PASSWORD")
|
cg.add_define("USE_API_PASSWORD")
|
||||||
|
|||||||
@@ -289,6 +289,9 @@ async def to_code(config):
|
|||||||
var = cg.new_Pvariable(config[CONF_ID], paren)
|
var = cg.new_Pvariable(config[CONF_ID], paren)
|
||||||
await cg.register_component(var, config)
|
await cg.register_component(var, config)
|
||||||
|
|
||||||
|
# Track controller registration for StaticVector sizing
|
||||||
|
CORE.register_controller()
|
||||||
|
|
||||||
version = config[CONF_VERSION]
|
version = config[CONF_VERSION]
|
||||||
|
|
||||||
cg.add(paren.set_port(config[CONF_PORT]))
|
cg.add(paren.set_port(config[CONF_PORT]))
|
||||||
|
|||||||
@@ -910,6 +910,11 @@ class EsphomeCore:
|
|||||||
"""
|
"""
|
||||||
self.platform_counts[platform_name] += 1
|
self.platform_counts[platform_name] += 1
|
||||||
|
|
||||||
|
def register_controller(self) -> None:
|
||||||
|
"""Track registration of a Controller for ControllerRegistry StaticVector sizing."""
|
||||||
|
controller_count = self.data.setdefault("controller_registry_count", 0)
|
||||||
|
self.data["controller_registry_count"] = controller_count + 1
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def cpp_main_section(self):
|
def cpp_main_section(self):
|
||||||
from esphome.cpp_generator import statement
|
from esphome.cpp_generator import statement
|
||||||
|
|||||||
@@ -462,6 +462,15 @@ async def _add_platform_defines() -> None:
|
|||||||
cg.add_define(f"USE_{platform_name.upper()}")
|
cg.add_define(f"USE_{platform_name.upper()}")
|
||||||
|
|
||||||
|
|
||||||
|
@coroutine_with_priority(CoroPriority.FINAL)
|
||||||
|
async def _add_controller_registry_define() -> None:
|
||||||
|
# Generate StaticVector size for ControllerRegistry
|
||||||
|
controller_count = CORE.data.get("controller_registry_count", 0)
|
||||||
|
if controller_count > 0:
|
||||||
|
cg.add_define("USE_CONTROLLER_REGISTRY")
|
||||||
|
cg.add_define("CONTROLLER_REGISTRY_MAX", controller_count)
|
||||||
|
|
||||||
|
|
||||||
@coroutine_with_priority(CoroPriority.CORE)
|
@coroutine_with_priority(CoroPriority.CORE)
|
||||||
async def to_code(config: ConfigType) -> None:
|
async def to_code(config: ConfigType) -> None:
|
||||||
cg.add_global(cg.global_ns.namespace("esphome").using)
|
cg.add_global(cg.global_ns.namespace("esphome").using)
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
#include "esphome/core/controller_registry.h"
|
#include "esphome/core/controller_registry.h"
|
||||||
|
|
||||||
|
#ifdef USE_CONTROLLER_REGISTRY
|
||||||
|
|
||||||
#include "esphome/core/controller.h"
|
#include "esphome/core/controller.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
|
|
||||||
std::vector<Controller *> ControllerRegistry::controllers;
|
StaticVector<Controller *, CONTROLLER_REGISTRY_MAX> ControllerRegistry::controllers;
|
||||||
|
|
||||||
void ControllerRegistry::register_controller(Controller *controller) { controllers.push_back(controller); }
|
void ControllerRegistry::register_controller(Controller *controller) { controllers.push_back(controller); }
|
||||||
|
|
||||||
@@ -168,3 +171,5 @@ void ControllerRegistry::notify_update(update::UpdateEntity *obj) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|
||||||
|
#endif // USE_CONTROLLER_REGISTRY
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "esphome/core/defines.h"
|
#include "esphome/core/defines.h"
|
||||||
#include <vector>
|
|
||||||
|
#ifdef USE_CONTROLLER_REGISTRY
|
||||||
|
|
||||||
|
#include "esphome/core/helpers.h"
|
||||||
|
|
||||||
// Forward declarations
|
// Forward declarations
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
@@ -234,7 +237,9 @@ class ControllerRegistry {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static std::vector<Controller *> controllers;
|
static StaticVector<Controller *, CONTROLLER_REGISTRY_MAX> controllers;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|
||||||
|
#endif // USE_CONTROLLER_REGISTRY
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#define USE_BUTTON
|
#define USE_BUTTON
|
||||||
#define USE_CAMERA
|
#define USE_CAMERA
|
||||||
#define USE_CLIMATE
|
#define USE_CLIMATE
|
||||||
|
#define USE_CONTROLLER_REGISTRY
|
||||||
#define USE_COVER
|
#define USE_COVER
|
||||||
#define USE_DATETIME
|
#define USE_DATETIME
|
||||||
#define USE_DATETIME_DATE
|
#define USE_DATETIME_DATE
|
||||||
@@ -296,6 +297,7 @@
|
|||||||
#define USE_DASHBOARD_IMPORT
|
#define USE_DASHBOARD_IMPORT
|
||||||
|
|
||||||
// Default counts for static analysis
|
// Default counts for static analysis
|
||||||
|
#define CONTROLLER_REGISTRY_MAX 2
|
||||||
#define ESPHOME_COMPONENT_COUNT 50
|
#define ESPHOME_COMPONENT_COUNT 50
|
||||||
#define ESPHOME_DEVICE_COUNT 10
|
#define ESPHOME_DEVICE_COUNT 10
|
||||||
#define ESPHOME_AREA_COUNT 10
|
#define ESPHOME_AREA_COUNT 10
|
||||||
|
|||||||
Reference in New Issue
Block a user