mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 11:47:30 +01:00
fix canbus send config (#5585)
Co-authored-by: Samuel Sieb <samuel@sieb.net>
This commit is contained in:
parent
f018fde369
commit
0807d60c6a
@ -17,11 +17,12 @@ CONF_ON_FRAME = "on_frame"
|
|||||||
|
|
||||||
|
|
||||||
def validate_id(config):
|
def validate_id(config):
|
||||||
can_id = config[CONF_CAN_ID]
|
if CONF_CAN_ID in config:
|
||||||
id_ext = config[CONF_USE_EXTENDED_ID]
|
can_id = config[CONF_CAN_ID]
|
||||||
if not id_ext:
|
id_ext = config[CONF_USE_EXTENDED_ID]
|
||||||
if can_id > 0x7FF:
|
if not id_ext:
|
||||||
raise cv.Invalid("Standard IDs must be 11 Bit (0x000-0x7ff / 0-2047)")
|
if can_id > 0x7FF:
|
||||||
|
raise cv.Invalid("Standard IDs must be 11 Bit (0x000-0x7ff / 0-2047)")
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
@ -151,22 +152,18 @@ async def canbus_action_to_code(config, action_id, template_arg, args):
|
|||||||
if can_id := config.get(CONF_CAN_ID):
|
if can_id := config.get(CONF_CAN_ID):
|
||||||
can_id = await cg.templatable(can_id, args, cg.uint32)
|
can_id = await cg.templatable(can_id, args, cg.uint32)
|
||||||
cg.add(var.set_can_id(can_id))
|
cg.add(var.set_can_id(can_id))
|
||||||
use_extended_id = await cg.templatable(
|
cg.add(var.set_use_extended_id(config[CONF_USE_EXTENDED_ID]))
|
||||||
config[CONF_USE_EXTENDED_ID], args, cg.uint32
|
|
||||||
)
|
|
||||||
cg.add(var.set_use_extended_id(use_extended_id))
|
|
||||||
|
|
||||||
remote_transmission_request = await cg.templatable(
|
cg.add(
|
||||||
config[CONF_REMOTE_TRANSMISSION_REQUEST], args, bool
|
var.set_remote_transmission_request(config[CONF_REMOTE_TRANSMISSION_REQUEST])
|
||||||
)
|
)
|
||||||
cg.add(var.set_remote_transmission_request(remote_transmission_request))
|
|
||||||
|
|
||||||
data = config[CONF_DATA]
|
data = config[CONF_DATA]
|
||||||
if isinstance(data, bytes):
|
|
||||||
data = [int(x) for x in data]
|
|
||||||
if cg.is_template(data):
|
if cg.is_template(data):
|
||||||
templ = await cg.templatable(data, args, cg.std_vector.template(cg.uint8))
|
templ = await cg.templatable(data, args, cg.std_vector.template(cg.uint8))
|
||||||
cg.add(var.set_data_template(templ))
|
cg.add(var.set_data_template(templ))
|
||||||
else:
|
else:
|
||||||
|
if isinstance(data, bytes):
|
||||||
|
data = [int(x) for x in data]
|
||||||
cg.add(var.set_data_static(data))
|
cg.add(var.set_data_static(data))
|
||||||
return var
|
return var
|
||||||
|
@ -3326,6 +3326,10 @@ text_sensor:
|
|||||||
canbus_id: mcp2515_can
|
canbus_id: mcp2515_can
|
||||||
can_id: 23
|
can_id: 23
|
||||||
data: [0x10, 0x20, 0x30]
|
data: [0x10, 0x20, 0x30]
|
||||||
|
- canbus.send:
|
||||||
|
canbus_id: mcp2515_can
|
||||||
|
can_id: 23
|
||||||
|
data: !lambda return {0x10, 0x20, 0x30};
|
||||||
- canbus.send:
|
- canbus.send:
|
||||||
canbus_id: esp32_internal_can
|
canbus_id: esp32_internal_can
|
||||||
can_id: 23
|
can_id: 23
|
||||||
|
Loading…
Reference in New Issue
Block a user