mirror of
https://github.com/esphome/esphome.git
synced 2026-11-17 18:46:08 +00:00
Compare commits
12
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5b39cae870 | ||
|
|
54a80ea10d | ||
|
|
ce292960aa | ||
|
|
d9b887e22d | ||
|
|
7ff60b88e1 | ||
|
|
b3149594bb | ||
|
|
7224a67208 | ||
|
|
5ee8d902a5 | ||
|
|
4c9f79cd8b | ||
|
|
964950fb07 | ||
|
|
7f64026638 | ||
|
|
2400e29f51 |
No files matched your search
+2
-47
@@ -5,7 +5,6 @@ import logging
|
||||
import math
|
||||
import re
|
||||
import string
|
||||
import struct
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
@@ -2124,17 +2123,6 @@ def _direct_function(
|
||||
)
|
||||
|
||||
|
||||
def _call_target(
|
||||
plan: list[MockObj | list[_InlineAction]],
|
||||
args: TemplateArgsType,
|
||||
config: ConfigType,
|
||||
) -> MockObj | str:
|
||||
"""What a generated callback calls: the direct function, else ``<automation>->trigger``."""
|
||||
if (target := _direct_function(plan, args, config)) is None:
|
||||
target = parent_ref(_automation_from_plan(plan, args, config)).trigger
|
||||
return target
|
||||
|
||||
|
||||
def _when_call(
|
||||
when: str | ApplyCall | None, parent: MockObj | None
|
||||
) -> ApplyCall | None:
|
||||
@@ -2152,40 +2140,6 @@ async def build_automation(
|
||||
return await new_automation(args, config, trigger)
|
||||
|
||||
|
||||
async def build_component_automation(
|
||||
config: ConfigType, component_class: MockObjClass, priority: float | None = None
|
||||
) -> MockObj:
|
||||
"""Create and register the Component that runs a no-argument automation.
|
||||
|
||||
That is ``component_class<function[, priority bits]>``, whose function runs the actions
|
||||
directly when they are all inline, else triggers their Automation. A ``trigger_id`` set
|
||||
by hand keeps its Trigger, built with ``priority`` if given.
|
||||
"""
|
||||
trigger_id: ID = config[CONF_TRIGGER_ID]
|
||||
if trigger_id.is_manual:
|
||||
var = cg.new_Pvariable(trigger_id, *([] if priority is None else [priority]))
|
||||
await cg.register_component(var, config)
|
||||
await build_automation(var, [], config)
|
||||
return var
|
||||
# Declared and registered before the actions are built, which can wait for other ids
|
||||
name = _apply_function_name(trigger_id)
|
||||
define = cg.declare_static_function(name, cg.void, [])
|
||||
id_ = trigger_id.copy()
|
||||
id_.type = component_class
|
||||
bits = [] if priority is None else [_float_bits(priority)]
|
||||
var = cg.new_Pvariable(id_, cg.TemplateArguments(cg.RawExpression(name), *bits))
|
||||
await cg.register_component(var, config)
|
||||
plan = await _build_automation_plan([], config)
|
||||
define([str(cg.statement(CallExpression(_call_target(plan, [], config))))])
|
||||
return var
|
||||
|
||||
|
||||
def _float_bits(value: float) -> HexInt:
|
||||
"""``value`` as a C++ float's bit pattern, for a template argument."""
|
||||
(bits,) = struct.unpack("<I", struct.pack("<f", value))
|
||||
return HexInt(bits)
|
||||
|
||||
|
||||
async def build_trigger_callback(
|
||||
args: TemplateArgsType,
|
||||
config: ConfigType,
|
||||
@@ -2219,7 +2173,8 @@ async def _trigger_callback(
|
||||
call: ApplyCall | None,
|
||||
parent: MockObj | None,
|
||||
) -> LambdaExpression:
|
||||
target = _call_target(plan, args, config)
|
||||
if (target := _direct_function(plan, args, config)) is None:
|
||||
target = f"{parent_ref(_automation_from_plan(plan, args, config))}->trigger"
|
||||
statements: list[str] = []
|
||||
if call is not None:
|
||||
members = call.members
|
||||
|
||||
@@ -31,7 +31,6 @@ from esphome.cpp_generator import ( # noqa: F401
|
||||
add_global,
|
||||
add_library,
|
||||
add_platformio_option,
|
||||
declare_static_function,
|
||||
extern_progmem_array,
|
||||
get_variable,
|
||||
get_variable_with_full_id,
|
||||
|
||||
@@ -12,6 +12,8 @@ class BedJetClient : public Parented<BedJetHub> {
|
||||
public:
|
||||
virtual void on_status(const BedjetStatusPacket *data) = 0;
|
||||
virtual void on_bedjet_state(bool is_ready) = 0;
|
||||
// Called from the hub's dump_config(); not dump_config() so Component children don't print twice
|
||||
virtual void dump_child_config() {}
|
||||
|
||||
protected:
|
||||
friend BedJetHub;
|
||||
|
||||
@@ -504,6 +504,8 @@ void BedJetHub::dump_config() {
|
||||
for (auto *child : this->children_) {
|
||||
ESP_LOGCONFIG(TAG, " - %s", child->describe().c_str());
|
||||
}
|
||||
for (auto *child : this->children_)
|
||||
child->dump_child_config();
|
||||
}
|
||||
|
||||
void BedJetHub::dispatch_state_(bool is_ready) {
|
||||
|
||||
@@ -20,7 +20,7 @@ DEPENDENCIES = ["bedjet"]
|
||||
CONF_OUTLET_TEMPERATURE = "outlet_temperature"
|
||||
CONF_AMBIENT_TEMPERATURE = "ambient_temperature"
|
||||
|
||||
BedjetSensor = bedjet_ns.class_("BedjetSensor", cg.Component)
|
||||
BedjetSensor = bedjet_ns.class_("BedjetSensor")
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
@@ -41,7 +41,6 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_component(var, config)
|
||||
await register_bedjet_child(var, config)
|
||||
|
||||
sensors = sensor.sub_sensors(config)
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace esphome::bedjet {
|
||||
|
||||
std::string BedjetSensor::describe() { return "BedJet Sensor"; }
|
||||
|
||||
void BedjetSensor::dump_config() {
|
||||
void BedjetSensor::dump_child_config() {
|
||||
ESP_LOGCONFIG(TAG, "BedJet Sensor:");
|
||||
LOG_SENSOR(" ", "Outlet Temperature", this->outlet_temperature_sensor_);
|
||||
LOG_SENSOR(" ", "Ambient Temperature", this->ambient_temperature_sensor_);
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esphome/components/bedjet/bedjet_child.h"
|
||||
#include "esphome/components/bedjet/bedjet_codec.h"
|
||||
|
||||
namespace esphome::bedjet {
|
||||
|
||||
class BedjetSensor final : public BedJetClient, public Component {
|
||||
class BedjetSensor final : public BedJetClient {
|
||||
SUB_SENSOR(outlet_temperature)
|
||||
SUB_SENSOR(ambient_temperature)
|
||||
|
||||
public:
|
||||
void dump_config() override;
|
||||
void dump_child_config() override;
|
||||
|
||||
void on_status(const BedjetStatusPacket *data) override;
|
||||
void on_bedjet_state(bool is_ready) override;
|
||||
|
||||
@@ -258,6 +258,7 @@ void EmonTx::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, " Registered sensors: %zu", this->sensors_.size());
|
||||
for (const auto &sensor_pair : this->sensors_) {
|
||||
ESP_LOGCONFIG(TAG, " Sensor: %s", sensor_pair.first);
|
||||
LOG_SENSOR(" ", "EmonTx Sensor", sensor_pair.second);
|
||||
}
|
||||
#else
|
||||
ESP_LOGCONFIG(TAG, " Sensor support: DISABLED");
|
||||
|
||||
@@ -32,7 +32,7 @@ from esphome.types import ConfigType
|
||||
|
||||
from .. import CONF_EMONTX_ID, CONF_TAG_NAME, EmonTx, emontx_ns
|
||||
|
||||
EmonTxSensor = emontx_ns.class_("EmonTxSensor", sensor.Sensor, cg.Component)
|
||||
EmonTxSensor = emontx_ns.class_("EmonTxSensor", sensor.Sensor)
|
||||
|
||||
# Known emonTx/avrdb JSON tag conventions, gathered from real firmware
|
||||
# (see https://github.com/openenergymonitor/avrdb_firmware), used to decide
|
||||
@@ -207,7 +207,6 @@ CONFIG_SCHEMA = cv.All(BASE_SCHEMA, apply_tag_defaults)
|
||||
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_component(var, config)
|
||||
await sensor.register_sensor(var, config)
|
||||
hub = await cg.get_variable(config[CONF_EMONTX_ID])
|
||||
cg.add(hub.register_sensor(config[CONF_TAG_NAME], var))
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "emontx_sensor.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome::emontx {
|
||||
|
||||
ESPHOME_LOG_TAG(TAG, "emontx_sensor");
|
||||
|
||||
void EmonTxSensor::dump_config() { LOG_SENSOR(" ", "EmonTx Sensor", this); }
|
||||
|
||||
} // namespace esphome::emontx
|
||||
@@ -1,13 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esphome/core/component.h"
|
||||
|
||||
namespace esphome::emontx {
|
||||
|
||||
class EmonTxSensor final : public sensor::Sensor, public Component {
|
||||
public:
|
||||
void dump_config() override;
|
||||
};
|
||||
class EmonTxSensor final : public sensor::Sensor {};
|
||||
|
||||
} // namespace esphome::emontx
|
||||
@@ -11,7 +11,7 @@ from .. import (
|
||||
)
|
||||
|
||||
Mk2PVRouterBinarySensor = mk2pvrouter_ns.class_(
|
||||
"Mk2PVRouterBinarySensor", binary_sensor.BinarySensor, cg.Component
|
||||
"Mk2PVRouterBinarySensor", binary_sensor.BinarySensor
|
||||
)
|
||||
|
||||
CONFIG_SCHEMA = binary_sensor.binary_sensor_schema(Mk2PVRouterBinarySensor).extend(
|
||||
@@ -21,7 +21,6 @@ CONFIG_SCHEMA = binary_sensor.binary_sensor_schema(Mk2PVRouterBinarySensor).exte
|
||||
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
var = cg.new_Pvariable(config[CONF_ID], config[CONF_TAG])
|
||||
await cg.register_component(var, config)
|
||||
await binary_sensor.register_binary_sensor(var, config)
|
||||
mk2pvrouter = await cg.get_variable(config[CONF_MK2PVROUTER_ID])
|
||||
await register_mk2pvrouter_listener(mk2pvrouter, var)
|
||||
@@ -13,7 +13,7 @@ void Mk2PVRouterBinarySensor::publish_val(const char *val) {
|
||||
this->publish_state(state);
|
||||
}
|
||||
|
||||
void Mk2PVRouterBinarySensor::dump_config() {
|
||||
void Mk2PVRouterBinarySensor::dump_child_config() {
|
||||
LOG_BINARY_SENSOR(" ", "Mk2PVRouter Binary Sensor", this);
|
||||
ESP_LOGCONFIG(TAG, " Tag: %s", this->get_tag());
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
|
||||
namespace esphome::mk2pvrouter {
|
||||
|
||||
class Mk2PVRouterBinarySensor final : public Mk2PVRouterListener, public binary_sensor::BinarySensor, public Component {
|
||||
class Mk2PVRouterBinarySensor final : public Mk2PVRouterListener, public binary_sensor::BinarySensor {
|
||||
public:
|
||||
explicit Mk2PVRouterBinarySensor(const char *tag);
|
||||
void publish_val(const char *val) override;
|
||||
void dump_config() override;
|
||||
void dump_child_config() override;
|
||||
};
|
||||
|
||||
} // namespace esphome::mk2pvrouter
|
||||
@@ -157,7 +157,13 @@ void Mk2PVRouter::publish_value_(const char *tag, const char *val) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void Mk2PVRouter::dump_config() { ESP_LOGCONFIG(TAG, "Mk2PVRouter:"); }
|
||||
void Mk2PVRouter::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "Mk2PVRouter:");
|
||||
#ifdef MK2PVROUTER_LISTENER_COUNT
|
||||
for (auto *listener : this->mk2pvrouter_listeners_)
|
||||
listener->dump_child_config();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef MK2PVROUTER_LISTENER_COUNT
|
||||
void Mk2PVRouter::register_mk2pvrouter_listener(Mk2PVRouterListener *listener) {
|
||||
|
||||
@@ -27,6 +27,8 @@ class Mk2PVRouterListener {
|
||||
virtual ~Mk2PVRouterListener() = default;
|
||||
const char *get_tag() const { return this->tag_; }
|
||||
virtual void publish_val(const char *val) = 0;
|
||||
// Called from the hub's dump_config(); not dump_config() so Component children don't print twice
|
||||
virtual void dump_child_config() {}
|
||||
|
||||
protected:
|
||||
const char *tag_;
|
||||
|
||||
@@ -35,9 +35,7 @@ from .. import (
|
||||
register_mk2pvrouter_listener,
|
||||
)
|
||||
|
||||
Mk2PVRouterSensor = mk2pvrouter_ns.class_(
|
||||
"Mk2PVRouterSensor", sensor.Sensor, cg.Component
|
||||
)
|
||||
Mk2PVRouterSensor = mk2pvrouter_ns.class_("Mk2PVRouterSensor", sensor.Sensor)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -122,7 +120,6 @@ async def to_code(config: ConfigType) -> None:
|
||||
tag = config[CONF_TAG]
|
||||
kind = tag_kind(tag)
|
||||
var = cg.new_Pvariable(config[CONF_ID], tag, kind is not None and kind.scale_centi)
|
||||
await cg.register_component(var, config)
|
||||
await sensor.register_sensor(var, config)
|
||||
mk2pvrouter = await cg.get_variable(config[CONF_MK2PVROUTER_ID])
|
||||
await register_mk2pvrouter_listener(mk2pvrouter, var)
|
||||
@@ -21,7 +21,7 @@ void Mk2PVRouterSensor::publish_val(const char *val) {
|
||||
this->publish_state(value);
|
||||
}
|
||||
|
||||
void Mk2PVRouterSensor::dump_config() {
|
||||
void Mk2PVRouterSensor::dump_child_config() {
|
||||
LOG_SENSOR(" ", "Mk2PVRouter Sensor", this);
|
||||
ESP_LOGCONFIG(TAG, " Tag: %s", this->get_tag());
|
||||
}
|
||||
|
||||
@@ -5,12 +5,11 @@
|
||||
|
||||
namespace esphome::mk2pvrouter {
|
||||
|
||||
// Component before Sensor so the flag lands in Sensor's tail padding
|
||||
class Mk2PVRouterSensor final : public Mk2PVRouterListener, public Component, public sensor::Sensor {
|
||||
class Mk2PVRouterSensor final : public Mk2PVRouterListener, public sensor::Sensor {
|
||||
public:
|
||||
Mk2PVRouterSensor(const char *tag, bool scale_centi);
|
||||
void publish_val(const char *val) override;
|
||||
void dump_config() override;
|
||||
void dump_child_config() override;
|
||||
|
||||
protected:
|
||||
bool scale_centi_;
|
||||
|
||||
@@ -11,7 +11,7 @@ from .. import (
|
||||
)
|
||||
|
||||
Mk2PVRouterTextSensor = mk2pvrouter_ns.class_(
|
||||
"Mk2PVRouterTextSensor", text_sensor.TextSensor, cg.Component
|
||||
"Mk2PVRouterTextSensor", text_sensor.TextSensor
|
||||
)
|
||||
|
||||
CONFIG_SCHEMA = text_sensor.text_sensor_schema(Mk2PVRouterTextSensor).extend(
|
||||
@@ -21,7 +21,6 @@ CONFIG_SCHEMA = text_sensor.text_sensor_schema(Mk2PVRouterTextSensor).extend(
|
||||
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
var = cg.new_Pvariable(config[CONF_ID], config[CONF_TAG])
|
||||
await cg.register_component(var, config)
|
||||
await text_sensor.register_text_sensor(var, config)
|
||||
mk2pvrouter = await cg.get_variable(config[CONF_MK2PVROUTER_ID])
|
||||
await register_mk2pvrouter_listener(mk2pvrouter, var)
|
||||
@@ -9,7 +9,7 @@ Mk2PVRouterTextSensor::Mk2PVRouterTextSensor(const char *tag) : Mk2PVRouterListe
|
||||
|
||||
void Mk2PVRouterTextSensor::publish_val(const char *val) { this->publish_state(val); }
|
||||
|
||||
void Mk2PVRouterTextSensor::dump_config() {
|
||||
void Mk2PVRouterTextSensor::dump_child_config() {
|
||||
LOG_TEXT_SENSOR(" ", "Mk2PVRouter Text Sensor", this);
|
||||
ESP_LOGCONFIG(TAG, " Tag: %s", this->get_tag());
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
|
||||
namespace esphome::mk2pvrouter {
|
||||
|
||||
class Mk2PVRouterTextSensor final : public Mk2PVRouterListener, public text_sensor::TextSensor, public Component {
|
||||
class Mk2PVRouterTextSensor final : public Mk2PVRouterListener, public text_sensor::TextSensor {
|
||||
public:
|
||||
explicit Mk2PVRouterTextSensor(const char *tag);
|
||||
void publish_val(const char *val) override;
|
||||
void dump_config() override;
|
||||
void dump_child_config() override;
|
||||
};
|
||||
|
||||
} // namespace esphome::mk2pvrouter
|
||||
@@ -538,6 +538,8 @@ void ModbusController::dump_config() {
|
||||
" Max Command Retries: %d\n"
|
||||
" Offline Skip Updates: %d\n",
|
||||
this->address_, this->max_cmd_retries_, this->offline_skip_updates_);
|
||||
for (auto *item : this->sensorset_)
|
||||
item->dump_child_config();
|
||||
|
||||
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
|
||||
ESP_LOGCONFIG(TAG, "sensormap");
|
||||
|
||||
@@ -72,6 +72,8 @@ class SensorItem {
|
||||
/// response buffer and is only valid for the duration of the call. Read the sensor's data from
|
||||
/// `offset` within it.
|
||||
virtual void parse_and_publish(std::span<const uint8_t> data) = 0;
|
||||
/// Called from the hub's dump_config(); not dump_config() so Component items don't print twice.
|
||||
virtual void dump_child_config() {}
|
||||
|
||||
/// Coils and discrete inputs address individual bits; every other type addresses 16-bit registers.
|
||||
bool addresses_bits() const { return modbus::helpers::is_entity_type_binary(this->register_type); }
|
||||
|
||||
@@ -42,9 +42,7 @@ DEPENDENCIES = ["modbus_controller"]
|
||||
CODEOWNERS = ["@martgras"]
|
||||
|
||||
|
||||
ModbusNumber = modbus_controller_ns.class_(
|
||||
"ModbusNumber", cg.Component, number.Number, SensorItem
|
||||
)
|
||||
ModbusNumber = modbus_controller_ns.class_("ModbusNumber", number.Number, SensorItem)
|
||||
|
||||
|
||||
def validate_min_max(config: ConfigType) -> ConfigType:
|
||||
@@ -107,7 +105,6 @@ async def to_code(config: ConfigType) -> None:
|
||||
RANGE_REUSE[config[CONF_REUSE_PREVIOUS_RANGE]],
|
||||
)
|
||||
|
||||
await cg.register_component(var, config)
|
||||
await number.register_number(
|
||||
var,
|
||||
config,
|
||||
|
||||
@@ -98,6 +98,6 @@ void ModbusNumber::control(float value) {
|
||||
}
|
||||
this->publish_state(value);
|
||||
}
|
||||
void ModbusNumber::dump_config() { LOG_NUMBER(TAG, "Modbus Number", this); }
|
||||
void ModbusNumber::dump_child_config() { LOG_NUMBER(TAG, "Modbus Number", this); }
|
||||
|
||||
} // namespace esphome::modbus_controller
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include "esphome/components/number/number.h"
|
||||
#include "esphome/components/modbus_controller/modbus_controller.h"
|
||||
#include "esphome/core/component.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -10,7 +9,7 @@ namespace esphome::modbus_controller {
|
||||
|
||||
using value_to_data_t = std::function<float>(float);
|
||||
|
||||
class ModbusNumber final : public number::Number, public Component, public SensorItem, public WriterEntity {
|
||||
class ModbusNumber final : public number::Number, public SensorItem, public WriterEntity {
|
||||
public:
|
||||
ModbusNumber(modbus::EntityType register_type, uint16_t start_address, uint8_t offset, uint32_t bitmask,
|
||||
SensorValueType value_type, RangeReuse reuse_previous_range) {
|
||||
@@ -22,9 +21,8 @@ class ModbusNumber final : public number::Number, public Component, public Senso
|
||||
this->reuse_previous_range = reuse_previous_range;
|
||||
};
|
||||
|
||||
void dump_config() override;
|
||||
void dump_child_config() override;
|
||||
void parse_and_publish(std::span<const uint8_t> data) override;
|
||||
float get_setup_priority() const override { return setup_priority::HARDWARE; }
|
||||
void set_parent(ModbusController *parent) { this->set_controller_(parent); }
|
||||
void set_write_multiply(float factor) { this->multiply_by_ = factor; }
|
||||
|
||||
|
||||
@@ -27,11 +27,10 @@ DEPENDENCIES = ["uponor_smatrix"]
|
||||
UponorSmatrixSensor = uponor_smatrix_ns.class_(
|
||||
"UponorSmatrixSensor",
|
||||
sensor.Sensor,
|
||||
cg.Component,
|
||||
UponorSmatrixDevice,
|
||||
)
|
||||
|
||||
CONFIG_SCHEMA = cv.COMPONENT_SCHEMA.extend(
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(UponorSmatrixSensor),
|
||||
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
|
||||
@@ -64,7 +63,6 @@ CONFIG_SCHEMA = cv.COMPONENT_SCHEMA.extend(
|
||||
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_component(var, config)
|
||||
await register_uponor_smatrix_device(var, config)
|
||||
|
||||
sensors = sensor.sub_sensors(config)
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace esphome::uponor_smatrix {
|
||||
|
||||
ESPHOME_LOG_TAG(TAG, "uponor_smatrix.sensor");
|
||||
|
||||
void UponorSmatrixSensor::dump_config() {
|
||||
void UponorSmatrixSensor::dump_child_config() {
|
||||
ESP_LOGCONFIG(TAG,
|
||||
"Uponor Smatrix Sensor\n"
|
||||
" Device address: 0x%08" PRIX32,
|
||||
|
||||
@@ -2,18 +2,17 @@
|
||||
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esphome/components/uponor_smatrix/uponor_smatrix.h"
|
||||
#include "esphome/core/component.h"
|
||||
|
||||
namespace esphome::uponor_smatrix {
|
||||
|
||||
class UponorSmatrixSensor final : public sensor::Sensor, public Component, public UponorSmatrixDevice {
|
||||
class UponorSmatrixSensor final : public sensor::Sensor, public UponorSmatrixDevice {
|
||||
SUB_SENSOR(temperature)
|
||||
SUB_SENSOR(external_temperature)
|
||||
SUB_SENSOR(humidity)
|
||||
SUB_SENSOR(target_temperature)
|
||||
|
||||
public:
|
||||
void dump_config() override;
|
||||
void dump_child_config() override;
|
||||
|
||||
protected:
|
||||
void on_device_data(const UponorSmatrixData *data, size_t data_len) override;
|
||||
|
||||
@@ -29,6 +29,9 @@ void UponorSmatrixComponent::dump_config() {
|
||||
}
|
||||
#endif
|
||||
|
||||
for (auto *device : this->devices_)
|
||||
device->dump_child_config();
|
||||
|
||||
if (!this->unknown_devices_.empty()) {
|
||||
ESP_LOGCONFIG(TAG, " Detected unknown device addresses:");
|
||||
for (auto device_address : this->unknown_devices_) {
|
||||
|
||||
@@ -104,6 +104,8 @@ class UponorSmatrixDevice : public Parented<UponorSmatrixComponent> {
|
||||
void set_address(uint32_t address) { this->address_ = address; }
|
||||
|
||||
virtual void on_device_data(const UponorSmatrixData *data, size_t data_len) = 0;
|
||||
// Called from the hub's dump_config(); not dump_config() so Component devices don't print twice
|
||||
virtual void dump_child_config() {}
|
||||
bool send(const UponorSmatrixData *data, size_t data_len) {
|
||||
return this->parent_->send(this->address_, data, data_len);
|
||||
}
|
||||
|
||||
@@ -171,41 +171,6 @@ class LoopTrigger : public Trigger<>, public Component {
|
||||
float get_setup_priority() const override { return setup_priority::DATA; }
|
||||
};
|
||||
|
||||
/// Component whose setup priority is the float with bit pattern PRIORITY_BITS, since GCC 10 (ESP8266)
|
||||
/// has no float template parameters. Templated on the priority only, so each priority has one copy.
|
||||
template<uint32_t PRIORITY_BITS> class PriorityComponent : public Component {
|
||||
public:
|
||||
float get_setup_priority() const override { return bit_cast<float>(PRIORITY_BITS); }
|
||||
};
|
||||
|
||||
/// Bit pattern of setup_priority::DATA (600.0f), the Component default.
|
||||
static constexpr uint32_t SETUP_PRIORITY_DATA_BITS = 0x44160000;
|
||||
// bit_cast is constexpr only where std::bit_cast exists, which GCC 10 (ESP8266) lacks
|
||||
#if __cpp_lib_bit_cast >= 201806
|
||||
static_assert(bit_cast<uint32_t>(setup_priority::DATA) == SETUP_PRIORITY_DATA_BITS);
|
||||
#endif
|
||||
|
||||
/// The default priority needs no override.
|
||||
template<> class PriorityComponent<SETUP_PRIORITY_DATA_BITS> : public Component {};
|
||||
|
||||
/// Calls Fn from setup(), for on_boot.
|
||||
template<auto Fn, uint32_t PRIORITY_BITS> class StartupCallback final : public PriorityComponent<PRIORITY_BITS> {
|
||||
public:
|
||||
void setup() override { Fn(); }
|
||||
};
|
||||
|
||||
/// Calls Fn from on_shutdown(), for on_shutdown.
|
||||
template<auto Fn, uint32_t PRIORITY_BITS> class ShutdownCallback final : public PriorityComponent<PRIORITY_BITS> {
|
||||
public:
|
||||
void on_shutdown() override { Fn(); }
|
||||
};
|
||||
|
||||
/// Calls Fn from loop(), for on_loop.
|
||||
template<auto Fn> class LoopCallback final : public Component {
|
||||
public:
|
||||
void loop() override { Fn(); }
|
||||
};
|
||||
|
||||
#ifdef ESPHOME_PROJECT_NAME
|
||||
class ProjectUpdateTrigger : public Trigger<std::string>, public Component {
|
||||
public:
|
||||
|
||||
+14
-12
@@ -124,9 +124,6 @@ ShutdownTrigger = cg.esphome_ns.class_(
|
||||
LoopTrigger = cg.esphome_ns.class_(
|
||||
"LoopTrigger", cg.Component, automation.Trigger.template()
|
||||
)
|
||||
StartupCallback = cg.esphome_ns.class_("StartupCallback", cg.Component)
|
||||
ShutdownCallback = cg.esphome_ns.class_("ShutdownCallback", cg.Component)
|
||||
LoopCallback = cg.esphome_ns.class_("LoopCallback", cg.Component)
|
||||
ProjectUpdateTrigger = cg.esphome_ns.class_(
|
||||
"ProjectUpdateTrigger", cg.Component, automation.Trigger.template(cg.std_string)
|
||||
)
|
||||
@@ -788,15 +785,20 @@ async def _add_environment_variables(env_vars: dict[str, str]) -> None:
|
||||
|
||||
@coroutine_with_priority(CoroPriority.AUTOMATION)
|
||||
async def _add_automations(config):
|
||||
for key, component_class in (
|
||||
(CONF_ON_BOOT, StartupCallback),
|
||||
(CONF_ON_SHUTDOWN, ShutdownCallback),
|
||||
(CONF_ON_LOOP, LoopCallback),
|
||||
):
|
||||
for conf in config.get(key, []):
|
||||
await automation.build_component_automation(
|
||||
conf, component_class, conf.get(CONF_PRIORITY)
|
||||
)
|
||||
for conf in config.get(CONF_ON_BOOT, []):
|
||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], conf.get(CONF_PRIORITY))
|
||||
await cg.register_component(trigger, conf)
|
||||
await automation.build_automation(trigger, [], conf)
|
||||
|
||||
for conf in config.get(CONF_ON_SHUTDOWN, []):
|
||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], conf.get(CONF_PRIORITY))
|
||||
await cg.register_component(trigger, conf)
|
||||
await automation.build_automation(trigger, [], conf)
|
||||
|
||||
for conf in config.get(CONF_ON_LOOP, []):
|
||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID])
|
||||
await cg.register_component(trigger, conf)
|
||||
await automation.build_automation(trigger, [], conf)
|
||||
|
||||
|
||||
# Datetime component has special subtypes that need additional defines
|
||||
|
||||
@@ -883,13 +883,14 @@ def new_Pvariable(id_: ID, *args: SafeExpType) -> "MockObj":
|
||||
return Pvariable(id_, rhs)
|
||||
|
||||
|
||||
def declare_static_function(
|
||||
def static_function(
|
||||
name: str,
|
||||
return_type: SafeExpType,
|
||||
parameters: TemplateArgsType,
|
||||
) -> Callable[[list[str | Statement]], RawExpression]:
|
||||
"""Declare ``static <return_type> <name>(parameters)`` now and return the function that
|
||||
emits its body, for a caller that names the function before the body is known.
|
||||
body: list[str | Statement],
|
||||
) -> RawExpression:
|
||||
"""Emit ``static <return_type> <name>(parameters) { body }`` at global scope and return an
|
||||
expression naming it, for use as a template argument or a function pointer.
|
||||
|
||||
The declaration goes with the other globals, so a template argument can name the function
|
||||
at once; the body goes after the user includes, where every id and everything those
|
||||
@@ -899,24 +900,10 @@ def declare_static_function(
|
||||
f"static {safe_exp(return_type)} {name}({ParameterListExpression(*parameters)})"
|
||||
)
|
||||
add_global(RawStatement(f"{signature};"))
|
||||
|
||||
def define(body: list[str | Statement]) -> RawExpression:
|
||||
add_global_after_includes(
|
||||
RawStatement(f"{signature} {{\n{indent(chr(10).join(map(str, body)))}\n}}")
|
||||
)
|
||||
return RawExpression(name)
|
||||
|
||||
return define
|
||||
|
||||
|
||||
def static_function(
|
||||
name: str,
|
||||
return_type: SafeExpType,
|
||||
parameters: TemplateArgsType,
|
||||
body: list[str | Statement],
|
||||
) -> RawExpression:
|
||||
"""``declare_static_function`` with the body known at once."""
|
||||
return declare_static_function(name, return_type, parameters)(body)
|
||||
add_global_after_includes(
|
||||
RawStatement(f"{signature} {{\n{indent(chr(10).join(map(str, body)))}\n}}")
|
||||
)
|
||||
return RawExpression(name)
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
@@ -30,6 +30,14 @@ def _automation_of(main_cpp: str, trigger: str) -> str:
|
||||
return match.group(1)
|
||||
|
||||
|
||||
def _has_delay(main_cpp: str, trigger: str) -> bool:
|
||||
automation = _automation_of(main_cpp, trigger)
|
||||
return (
|
||||
re.search(rf"{automation}->add_action\(delayaction_id\w*\);", main_cpp)
|
||||
is not None
|
||||
)
|
||||
|
||||
|
||||
def _registered(main_cpp: str) -> list[str]:
|
||||
return re.findall(r"App\.register_component_\((\w+), \d+\);", main_cpp)
|
||||
|
||||
@@ -48,59 +56,18 @@ def test_core_automations_registration_order(main_cpp: str) -> None:
|
||||
]
|
||||
|
||||
|
||||
def _function_body(main_cpp: str, name: str) -> str:
|
||||
match = re.search(rf"static void {name}\(\) \{{(.*?)\n\}}\n", main_cpp, re.DOTALL)
|
||||
assert match is not None, name
|
||||
return match.group(1)
|
||||
|
||||
|
||||
def _actions_body(main_cpp: str, function: str) -> str:
|
||||
"""The body of the function of inline actions that ``function`` calls."""
|
||||
match = re.fullmatch(r"\n (\w+)\(\);", _function_body(main_cpp, function))
|
||||
assert match is not None, function
|
||||
return _function_body(main_cpp, match.group(1))
|
||||
|
||||
|
||||
def _delayed_automation(main_cpp: str, function: str) -> str:
|
||||
"""The Automation that ``function`` triggers, checked to hold a delay; found through the
|
||||
function rather than an id counter."""
|
||||
match = re.fullmatch(
|
||||
r"\n ::(\w+)->trigger\(\);", _function_body(main_cpp, function)
|
||||
)
|
||||
assert match is not None, function
|
||||
automation = match.group(1)
|
||||
assert f"new({automation}) Automation<>();" in main_cpp
|
||||
assert re.search(rf"{automation}->add_action\(delayaction_id\w*\);", main_cpp)
|
||||
return automation
|
||||
|
||||
|
||||
def test_on_boot_inline_priorities(main_cpp: str) -> None:
|
||||
"""All-inline on_boot blocks call one function from setup() at their priority, default 600.
|
||||
|
||||
The priority is the float's bit pattern: 0x44480000 is 800.0f, 0x44160000 is 600.0f.
|
||||
"""
|
||||
assert _constructed(main_cpp, "startuptrigger_id") == (
|
||||
"StartupCallback<esphome__startuptrigger_id__fn, 0x44480000>()"
|
||||
)
|
||||
assert _constructed(main_cpp, "startuptrigger_id_2") == (
|
||||
"StartupCallback<esphome__startuptrigger_id_2__fn, 0x44160000>()"
|
||||
)
|
||||
assert "Automation<>(startuptrigger_id" not in main_cpp
|
||||
# Both actions of the first block run in the one function, with no stop checks
|
||||
body = _actions_body(main_cpp, "esphome__startuptrigger_id__fn")
|
||||
assert "boot high" in body
|
||||
assert "boot high lambda" in body
|
||||
assert "esphome__running" not in body
|
||||
assert "Automation" not in body
|
||||
assert "boot default" in _actions_body(main_cpp, "esphome__startuptrigger_id_2__fn")
|
||||
"""All-inline on_boot blocks keep their configured priority, default 600."""
|
||||
assert _constructed(main_cpp, "startuptrigger_id") == "StartupTrigger(800.0f)"
|
||||
assert _constructed(main_cpp, "startuptrigger_id_2") == "StartupTrigger(600.0f)"
|
||||
_automation_of(main_cpp, "startuptrigger_id")
|
||||
_automation_of(main_cpp, "startuptrigger_id_2")
|
||||
|
||||
|
||||
def test_on_boot_delay_triggers_automation(main_cpp: str) -> None:
|
||||
"""A delay keeps the Automation of separate actions, which the function triggers."""
|
||||
assert _constructed(main_cpp, "startuptrigger_id_3") == (
|
||||
"StartupCallback<esphome__startuptrigger_id_3__fn, 0xC2C80000>()"
|
||||
)
|
||||
_delayed_automation(main_cpp, "esphome__startuptrigger_id_3__fn")
|
||||
def test_on_boot_delay_keeps_trigger(main_cpp: str) -> None:
|
||||
"""A delay needs the Trigger and its Automation of separate actions."""
|
||||
assert _constructed(main_cpp, "startuptrigger_id_3") == "StartupTrigger(-100.0f)"
|
||||
assert _has_delay(main_cpp, "startuptrigger_id_3")
|
||||
|
||||
|
||||
def test_on_boot_manual_trigger_id_keeps_trigger(main_cpp: str) -> None:
|
||||
@@ -110,30 +77,19 @@ def test_on_boot_manual_trigger_id_keeps_trigger(main_cpp: str) -> None:
|
||||
|
||||
|
||||
def test_on_shutdown_priorities(main_cpp: str) -> None:
|
||||
"""on_shutdown calls its function at its priority; a delay keeps the Automation."""
|
||||
assert _constructed(main_cpp, "shutdowntrigger_id") == (
|
||||
"ShutdownCallback<esphome__shutdowntrigger_id__fn, 0x442F0000>()"
|
||||
)
|
||||
assert "shutdown inline" in _actions_body(
|
||||
main_cpp, "esphome__shutdowntrigger_id__fn"
|
||||
)
|
||||
assert _constructed(main_cpp, "shutdowntrigger_id_2") == (
|
||||
"ShutdownCallback<esphome__shutdowntrigger_id_2__fn, 0x44160000>()"
|
||||
)
|
||||
_delayed_automation(main_cpp, "esphome__shutdowntrigger_id_2__fn")
|
||||
"""on_shutdown blocks keep their priority; a delay keeps the Trigger."""
|
||||
assert _constructed(main_cpp, "shutdowntrigger_id") == "ShutdownTrigger(700.0f)"
|
||||
_automation_of(main_cpp, "shutdowntrigger_id")
|
||||
assert _constructed(main_cpp, "shutdowntrigger_id_2") == "ShutdownTrigger(600.0f)"
|
||||
assert _has_delay(main_cpp, "shutdowntrigger_id_2")
|
||||
|
||||
|
||||
def test_on_loop(main_cpp: str) -> None:
|
||||
"""on_loop calls its function each loop; a delay keeps the Automation."""
|
||||
assert _constructed(main_cpp, "looptrigger_id") == (
|
||||
"LoopCallback<esphome__looptrigger_id__fn>()"
|
||||
)
|
||||
assert "loop inline" in _actions_body(main_cpp, "esphome__looptrigger_id__fn")
|
||||
assert "HasLoopOverride<LoopCallback<esphome__looptrigger_id__fn>>" in main_cpp
|
||||
assert _constructed(main_cpp, "looptrigger_id_2") == (
|
||||
"LoopCallback<esphome__looptrigger_id_2__fn>()"
|
||||
)
|
||||
_delayed_automation(main_cpp, "esphome__looptrigger_id_2__fn")
|
||||
"""on_loop blocks are looping components; a delay keeps the Trigger."""
|
||||
assert _constructed(main_cpp, "looptrigger_id") == "LoopTrigger()"
|
||||
_automation_of(main_cpp, "looptrigger_id")
|
||||
assert _constructed(main_cpp, "looptrigger_id_2") == "LoopTrigger()"
|
||||
assert _has_delay(main_cpp, "looptrigger_id_2")
|
||||
|
||||
|
||||
def test_on_boot_registered_before_its_actions_are_built(
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "esphome/core/base_automation.h"
|
||||
|
||||
namespace esphome::core::testing {
|
||||
|
||||
namespace {
|
||||
|
||||
int calls = 0; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
|
||||
void count_call() { calls++; }
|
||||
|
||||
// Bit patterns of 800.0f, 600.0f, -100.0f and 250.5f, as the code generator writes them
|
||||
constexpr uint32_t PRIORITY_800 = 0x44480000;
|
||||
constexpr uint32_t PRIORITY_MINUS_100 = 0xC2C80000;
|
||||
constexpr uint32_t PRIORITY_250_5 = 0x437A8000;
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(CoreAutomationCallbacks, StartupCallbackRunsFromSetupAtItsPriority) {
|
||||
calls = 0;
|
||||
StartupCallback<count_call, PRIORITY_800> high;
|
||||
StartupCallback<count_call, PRIORITY_MINUS_100> late;
|
||||
StartupCallback<count_call, PRIORITY_250_5> fractional;
|
||||
EXPECT_EQ(high.get_setup_priority(), 800.0f);
|
||||
EXPECT_EQ(late.get_setup_priority(), -100.0f);
|
||||
EXPECT_EQ(fractional.get_setup_priority(), 250.5f);
|
||||
StartupCallback<count_call, SETUP_PRIORITY_DATA_BITS> standard;
|
||||
EXPECT_EQ(standard.get_setup_priority(), setup_priority::DATA);
|
||||
|
||||
high.loop();
|
||||
high.on_shutdown();
|
||||
EXPECT_EQ(calls, 0);
|
||||
high.setup();
|
||||
EXPECT_EQ(calls, 1);
|
||||
}
|
||||
|
||||
TEST(CoreAutomationCallbacks, ShutdownCallbackRunsFromOnShutdownAtItsPriority) {
|
||||
calls = 0;
|
||||
ShutdownCallback<count_call, PRIORITY_MINUS_100> shutdown;
|
||||
EXPECT_EQ(shutdown.get_setup_priority(), -100.0f);
|
||||
|
||||
shutdown.setup();
|
||||
shutdown.loop();
|
||||
EXPECT_EQ(calls, 0);
|
||||
shutdown.on_shutdown();
|
||||
EXPECT_EQ(calls, 1);
|
||||
}
|
||||
|
||||
TEST(CoreAutomationCallbacks, LoopCallbackRunsEachLoopAtDataPriority) {
|
||||
calls = 0;
|
||||
LoopCallback<count_call> looping;
|
||||
EXPECT_EQ(looping.get_setup_priority(), setup_priority::DATA);
|
||||
EXPECT_TRUE(HasLoopOverride<LoopCallback<count_call>>::value);
|
||||
EXPECT_FALSE((HasLoopOverride<StartupCallback<count_call, PRIORITY_800>>::value));
|
||||
|
||||
looping.setup();
|
||||
EXPECT_EQ(calls, 0);
|
||||
looping.loop();
|
||||
looping.loop();
|
||||
EXPECT_EQ(calls, 2);
|
||||
}
|
||||
|
||||
} // namespace esphome::core::testing
|
||||
@@ -0,0 +1,39 @@
|
||||
esphome:
|
||||
name: hub-dump-children
|
||||
|
||||
host:
|
||||
api:
|
||||
logger:
|
||||
level: DEBUG
|
||||
|
||||
uart:
|
||||
- id: emontx_uart
|
||||
baud_rate: 115200
|
||||
port: /dev/null
|
||||
rx_buffer_size: 2048
|
||||
- id: modbus_uart
|
||||
baud_rate: 9600
|
||||
port: /dev/null
|
||||
|
||||
emontx:
|
||||
uart_id: emontx_uart
|
||||
|
||||
modbus:
|
||||
uart_id: modbus_uart
|
||||
|
||||
modbus_controller:
|
||||
- id: controller
|
||||
address: 0x2
|
||||
update_interval: 1h
|
||||
|
||||
sensor:
|
||||
- platform: emontx
|
||||
name: Grid Power
|
||||
tag_name: P1
|
||||
|
||||
number:
|
||||
- platform: modbus_controller
|
||||
modbus_controller_id: controller
|
||||
name: Setpoint
|
||||
address: 0x9001
|
||||
value_type: U_WORD
|
||||
@@ -0,0 +1,33 @@
|
||||
esphome:
|
||||
name: mk2pvrouter-dump-listeners
|
||||
|
||||
host:
|
||||
api:
|
||||
logger:
|
||||
level: DEBUG
|
||||
|
||||
uart:
|
||||
baud_rate: 9600
|
||||
port: /dev/null
|
||||
data_bits: 7
|
||||
parity: EVEN
|
||||
|
||||
mk2pvrouter:
|
||||
|
||||
sensor:
|
||||
- platform: mk2pvrouter
|
||||
name: Power
|
||||
tag: P
|
||||
- platform: mk2pvrouter
|
||||
name: Voltage Phase 1
|
||||
tag: V1
|
||||
|
||||
binary_sensor:
|
||||
- platform: mk2pvrouter
|
||||
name: Relay 2
|
||||
tag: R2
|
||||
|
||||
text_sensor:
|
||||
- platform: mk2pvrouter
|
||||
name: S per MC
|
||||
tag: S_MC
|
||||
@@ -0,0 +1,28 @@
|
||||
esphome:
|
||||
name: uponor-smatrix-dump-devices
|
||||
|
||||
host:
|
||||
api:
|
||||
logger:
|
||||
level: DEBUG
|
||||
|
||||
uart:
|
||||
baud_rate: 19200
|
||||
port: /dev/null
|
||||
|
||||
uponor_smatrix:
|
||||
|
||||
sensor:
|
||||
- platform: uponor_smatrix
|
||||
address: 0x110BDE13
|
||||
temperature:
|
||||
name: Temperature Living Room
|
||||
- platform: uponor_smatrix
|
||||
address: 0x110BDE14
|
||||
humidity:
|
||||
name: Humidity Kitchen
|
||||
|
||||
climate:
|
||||
- platform: uponor_smatrix
|
||||
address: 0x110BDE15
|
||||
name: Thermostat Bedroom
|
||||
@@ -0,0 +1,27 @@
|
||||
"""The emonTx and Modbus controller hubs print their non-component children's config dumps."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from .log_utils import LineWaiter
|
||||
from .types import APIClientConnectedFactory, RunCompiledFunction
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_hub_dump_children(
|
||||
yaml_config: str,
|
||||
run_compiled: RunCompiledFunction,
|
||||
api_client_connected: APIClientConnectedFactory,
|
||||
) -> None:
|
||||
"""Each child prints the lines it printed when it was a component."""
|
||||
waiter = LineWaiter()
|
||||
async with (
|
||||
run_compiled(yaml_config, line_callback=waiter.callback),
|
||||
api_client_connected() as client,
|
||||
):
|
||||
await client.device_info()
|
||||
await waiter.wait_for_each(
|
||||
"EmonTx Sensor 'Grid Power'",
|
||||
"Modbus Number 'Setpoint'",
|
||||
)
|
||||
@@ -0,0 +1,33 @@
|
||||
"""The Mk2PVRouter hub prints each listener's config dump."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from .log_utils import LineWaiter
|
||||
from .types import APIClientConnectedFactory, RunCompiledFunction
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_mk2pvrouter_dump_listeners(
|
||||
yaml_config: str,
|
||||
run_compiled: RunCompiledFunction,
|
||||
api_client_connected: APIClientConnectedFactory,
|
||||
) -> None:
|
||||
"""Each listener prints its entity and tag, as when it was a component."""
|
||||
waiter = LineWaiter()
|
||||
async with (
|
||||
run_compiled(yaml_config, line_callback=waiter.callback),
|
||||
api_client_connected() as client,
|
||||
):
|
||||
await client.device_info()
|
||||
await waiter.wait_for_each(
|
||||
"Mk2PVRouter Sensor 'Power'",
|
||||
"Tag: P",
|
||||
"Mk2PVRouter Sensor 'Voltage Phase 1'",
|
||||
"Tag: V1",
|
||||
"Mk2PVRouter Binary Sensor 'Relay 2'",
|
||||
"Tag: R2",
|
||||
"Mk2PVRouter Text Sensor 'S per MC'",
|
||||
"Tag: S_MC",
|
||||
)
|
||||
@@ -0,0 +1,32 @@
|
||||
"""The Uponor Smatrix hub prints each sensor device's config dump."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from .log_utils import LineWaiter
|
||||
from .types import APIClientConnectedFactory, RunCompiledFunction
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_uponor_smatrix_dump_devices(
|
||||
yaml_config: str,
|
||||
run_compiled: RunCompiledFunction,
|
||||
api_client_connected: APIClientConnectedFactory,
|
||||
) -> None:
|
||||
"""Sensors print through the hub; the climate still prints its own dump."""
|
||||
waiter = LineWaiter()
|
||||
async with (
|
||||
run_compiled(yaml_config, line_callback=waiter.callback),
|
||||
api_client_connected() as client,
|
||||
):
|
||||
await client.device_info()
|
||||
await waiter.wait_for_each(
|
||||
"Uponor Smatrix Sensor",
|
||||
"Device address: 0x110BDE13",
|
||||
"Temperature 'Temperature Living Room'",
|
||||
"Device address: 0x110BDE14",
|
||||
"Humidity 'Humidity Kitchen'",
|
||||
"Uponor Smatrix Climate 'Thermostat Bedroom'",
|
||||
"Device address: 0x110BDE15",
|
||||
)
|
||||
@@ -1173,21 +1173,6 @@ def test_static_function_declares_early_and_defines_after_includes() -> None:
|
||||
]
|
||||
|
||||
|
||||
def test_declare_static_function_defines_the_body_later() -> None:
|
||||
"""The declaration is emitted at once; the body only when define() is called."""
|
||||
define = cg.declare_static_function("esphome__act__fn", ct.void, [])
|
||||
assert [str(st) for st in CORE.global_statements] == [
|
||||
"static void esphome__act__fn();"
|
||||
]
|
||||
assert CORE.global_statements_after_includes == []
|
||||
|
||||
fn = define(["first();", "second();"])
|
||||
assert str(fn) == "esphome__act__fn"
|
||||
assert [str(st) for st in CORE.global_statements_after_includes] == [
|
||||
"static void esphome__act__fn() {\n first();\n second();\n}"
|
||||
]
|
||||
|
||||
|
||||
def test_static_function_accepts_statements() -> None:
|
||||
call = cg.MockObj("foo")(cg.MockObj("x") >> 2)
|
||||
cg.static_function(
|
||||
|
||||
Reference in new issue
Block a user