[components] Use cg.byte_span for std::span<const uint8_t> automation args (#22464)

This commit is contained in:
J. Nick Koston authored and GitHub committed 2026-11-09 09:30:56 -05:00
1 parent 2610a6a03a
commit ba423ff170
7 files changed
+9 -11

No files matched your search

+1 -1
View File
@@ -35,7 +35,7 @@ CONF_VELOCITY = "velocity"
ble_midi_ns = cg.esphome_ns.namespace("ble_midi")
BLEMidi = ble_midi_ns.class_("BLEMidi", cg.Component, ble_client.BLEClientNode)
# The message bytes as a view: data.size() and data[i] work, and nothing is copied
ByteSpan = cg.std_span.template(cg.uint8.operator("const"))
ByteSpan = cg.byte_span
# MIDI data bytes are 7-bit and channels are 4-bit, matching what goes on the wire and what the triggers report.
# Channel 0 is the channel that MIDI hardware usually labels "1".
+1 -2
View File
@@ -31,12 +31,11 @@ CONF_OPCODE = "opcode"
hdmi_cec_ns = cg.esphome_ns.namespace("hdmi_cec")
HDMICEC = hdmi_cec_ns.class_("HDMICEC", cg.Component)
_PAYLOAD_SPAN = cg.std_span.template(cg.uint8.operator("const"))
_PAYLOAD_VECTOR = cg.std_vector.template(cg.uint8)
_MESSAGE_ARGS = [
(cg.uint8, "source"),
(cg.uint8, "destination"),
(_PAYLOAD_SPAN, "data"),
(cg.byte_span, "data"),
]
_request_message_callback_slot = cg.slot_counter("HDMI_CEC_MESSAGE_CALLBACK_COUNT")
+1 -1
View File
@@ -171,7 +171,7 @@ def reject_broadcast_options_for_unicast(
# Raw PDU; valid only during the automation.
PDU_SPAN = cg.std_span.template(cg.uint8.operator("const"))
PDU_SPAN = cg.byte_span
_request_on_request_slot = cg.slot_counter("MODBUS_ON_REQUEST_COUNT")
@@ -454,7 +454,7 @@ async def add_modbus_base_properties(
[
(sensor_type.operator("ptr"), "item"),
(lambda_param_type, "x"),
(cg.std_span.template(cg.uint8.operator("const")), "data"),
(cg.byte_span, "data"),
],
return_type=cg.optional.template(lambda_return_type),
)
@@ -118,7 +118,7 @@ async def to_code(config: ConfigType) -> None:
[
(ModbusSelect.operator("const_ptr"), "item"),
(cg.int64, "x"),
(cg.std_span.template(cg.uint8.operator("const")), "data"),
(cg.byte_span, "data"),
],
return_type=cg.optional.template(cg.std_string),
)
+3 -4
View File
@@ -83,7 +83,6 @@ QUEUE_POLICIES = QueuePolicy.options("replace_latest", "fifo", prefix="QUEUE_")
TX_GATE_MODES = TxGateMode.options(
"frame_trigger", "idle_gap", "fixed_delay", prefix="TX_GATE_"
)
_BYTE_SPAN = cg.std_span.template(cg.uint8.operator("const"))
MAX_COMMAND_VALUES = 8
# Must agree with MAX_FRAME_TYPE_LEN in rs485_frame.h, which sizes a stack buffer.
@@ -350,9 +349,9 @@ async def to_code(config: ConfigType) -> None:
await automation.build_callback_automation(
var,
"add_on_frame_callback",
[(_BYTE_SPAN, "payload")],
[(cg.byte_span, "payload")],
conf,
params=[(_BYTE_SPAN, "payload")],
params=[(cg.byte_span, "payload")],
when=" || ".join(checks) or None,
)
@@ -361,7 +360,7 @@ def _progmem_span(config: ConfigType, value: list[int]) -> str:
if not value:
return "{}"
table = automation.progmem_bytes(f"{config[CONF_ID]}_send", value)
return str(_BYTE_SPAN(table, len(value)))
return str(cg.byte_span(table, len(value)))
def _validate_send_frame(config: ConfigType) -> ConfigType:
+1 -1
View File
@@ -31,7 +31,7 @@ udp_ns = cg.esphome_ns.namespace("udp")
UDPComponent = udp_ns.class_("UDPComponent", cg.Component)
trigger_argname = "data"
# Listener callback type (non-owning span from UDP component)
listener_args = cg.std_span.template(cg.uint8.operator("const"))
listener_args = cg.byte_span
listener_argtype = [(listener_args, trigger_argname)]
# Automation/trigger type (owned vector, safe for deferred actions like delay)
trigger_args = cg.std_vector.template(cg.uint8)