Merge pull request #1758 from FarmBot/mark_as
Phase 0: Ability to pass variables to MARK AS steppull/1759/head
commit
643bcb1a37
|
@ -38,7 +38,7 @@ module CeleryScriptSettingsBag
|
||||||
factory_reset find_home flash_firmware home
|
factory_reset find_home flash_firmware home
|
||||||
install_farmware install_first_party_farmware _if
|
install_farmware install_first_party_farmware _if
|
||||||
move_absolute move_relative power_off read_pin
|
move_absolute move_relative power_off read_pin
|
||||||
read_status reboot remove_farmware resource_update
|
read_status reboot remove_farmware update_resource
|
||||||
send_message set_servo_angle set_user_env sync
|
send_message set_servo_angle set_user_env sync
|
||||||
take_photo toggle_pin update_farmware wait
|
take_photo toggle_pin update_farmware wait
|
||||||
write_pin zero)
|
write_pin zero)
|
||||||
|
@ -74,7 +74,6 @@ module CeleryScriptSettingsBag
|
||||||
"as input. Please change your selection to a single" \
|
"as input. Please change your selection to a single" \
|
||||||
" location."
|
" location."
|
||||||
PLANT_STAGES = %w(planned planted harvested sprouted)
|
PLANT_STAGES = %w(planned planted harvested sprouted)
|
||||||
RESOURCE_UPDATE_ARGS = [:resource_type, :resource_id, :label, :value]
|
|
||||||
SCOPE_DECLARATIONS = [:variable_declaration, :parameter_declaration]
|
SCOPE_DECLARATIONS = [:variable_declaration, :parameter_declaration]
|
||||||
MISC_ENUM_ERR = '"%s" is not valid. Allowed values: %s'
|
MISC_ENUM_ERR = '"%s" is not valid. Allowed values: %s'
|
||||||
MAX_WAIT_MS = 1000 * 60 * 3 # Three Minutes
|
MAX_WAIT_MS = 1000 * 60 * 3 # Three Minutes
|
||||||
|
@ -82,6 +81,13 @@ module CeleryScriptSettingsBag
|
||||||
"A single wait node cannot exceed #{MAX_WAIT_MS / 1000 / 60} minutes. " +
|
"A single wait node cannot exceed #{MAX_WAIT_MS / 1000 / 60} minutes. " +
|
||||||
"Consider lowering the wait time or using multiple WAIT blocks."
|
"Consider lowering the wait time or using multiple WAIT blocks."
|
||||||
Corpus = CeleryScript::Corpus.new
|
Corpus = CeleryScript::Corpus.new
|
||||||
|
THIS_IS_DEPRECATED = {
|
||||||
|
args: [:resource_type, :resource_id, :label, :value],
|
||||||
|
tags: [:function, :api_writer, :network_user],
|
||||||
|
blk: ->(n) do
|
||||||
|
n.invalidate!("Deprecated `mark_as` detected. Delete it and re-add")
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
CORPUS_VALUES = {
|
CORPUS_VALUES = {
|
||||||
boolean: [TrueClass, FalseClass],
|
boolean: [TrueClass, FalseClass],
|
||||||
|
@ -278,6 +284,9 @@ module CeleryScriptSettingsBag
|
||||||
lua: {
|
lua: {
|
||||||
defn: [v(:string)],
|
defn: [v(:string)],
|
||||||
},
|
},
|
||||||
|
resource: {
|
||||||
|
defn: [n(:identifier), n(:resource)],
|
||||||
|
},
|
||||||
}.map do |(name, conf)|
|
}.map do |(name, conf)|
|
||||||
blk = conf[:blk]
|
blk = conf[:blk]
|
||||||
defn = conf.fetch(:defn)
|
defn = conf.fetch(:defn)
|
||||||
|
@ -513,15 +522,22 @@ module CeleryScriptSettingsBag
|
||||||
tags: [:function, :firmware_user, :rpi_user],
|
tags: [:function, :firmware_user, :rpi_user],
|
||||||
blk: ->(n) { no_rpi_analog(n) },
|
blk: ->(n) { no_rpi_analog(n) },
|
||||||
},
|
},
|
||||||
resource_update: {
|
# DEPRECATED- Get rid of this node ASAP -RC 15 APR 2020
|
||||||
args: RESOURCE_UPDATE_ARGS,
|
resource_update: THIS_IS_DEPRECATED,
|
||||||
tags: [:function, :api_writer, :network_user],
|
resource: {
|
||||||
|
args: [:resource_type, :resource_id],
|
||||||
|
tags: [:network_user],
|
||||||
blk: ->(n) do
|
blk: ->(n) do
|
||||||
resource_type = n.args.fetch(:resource_type).value
|
resource_type = n.args.fetch(:resource_type).value
|
||||||
resource_id = n.args.fetch(:resource_id).value
|
resource_id = n.args.fetch(:resource_id).value
|
||||||
check_resource_type(n, resource_type, resource_id, Device.current)
|
check_resource_type(n, resource_type, resource_id, Device.current)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
update_resource: {
|
||||||
|
args: [:resource],
|
||||||
|
body: [:pair],
|
||||||
|
tags: [:function, :api_writer, :network_user],
|
||||||
|
},
|
||||||
point_group: {
|
point_group: {
|
||||||
args: [:point_group_id],
|
args: [:point_group_id],
|
||||||
tags: [:data, :list_like],
|
tags: [:data, :list_like],
|
||||||
|
@ -529,7 +545,7 @@ module CeleryScriptSettingsBag
|
||||||
resource_id = n.args.fetch(:point_group_id).value
|
resource_id = n.args.fetch(:point_group_id).value
|
||||||
check_resource_type(n, "PointGroup", resource_id, Device.current)
|
check_resource_type(n, "PointGroup", resource_id, Device.current)
|
||||||
end,
|
end,
|
||||||
}
|
},
|
||||||
}.map { |(name, list)| Corpus.node(name, **list) }
|
}.map { |(name, list)| Corpus.node(name, **list) }
|
||||||
|
|
||||||
HASH = Corpus.as_json
|
HASH = Corpus.as_json
|
||||||
|
|
|
@ -148,19 +148,36 @@ describe CeleryScript::Corpus do
|
||||||
expect(checker.error.message).to include("Tool #0 does not exist.")
|
expect(checker.error.message).to include("Tool #0 does not exist.")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "Validates resource_update nodes" do
|
it "Validates update_resource nodes" do
|
||||||
ast = { "kind": "resource_update",
|
ast = {
|
||||||
"args": { "resource_type" => "Device",
|
kind: "update_resource",
|
||||||
|
args: {
|
||||||
|
"resource" => {
|
||||||
|
kind: "resource",
|
||||||
|
args: {
|
||||||
|
"resource_type" => "Device",
|
||||||
"resource_id" => 23, # Mutated to "0" later..
|
"resource_id" => 23, # Mutated to "0" later..
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
kind: "pair",
|
||||||
|
args: {
|
||||||
"label" => "mounted_tool_id",
|
"label" => "mounted_tool_id",
|
||||||
"value" => 1 } }
|
"value" => 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
checker = CeleryScript::Checker
|
checker = CeleryScript::Checker
|
||||||
.new(CeleryScript::AstNode.new(**ast), corpus, device)
|
.new(CeleryScript::AstNode.new(**ast), corpus, device)
|
||||||
expect(checker.valid?).to be(true)
|
expect(checker.valid?).to be(true)
|
||||||
expect(checker.tree.args[:resource_id].value).to eq(device.id)
|
device_id = checker.tree.args[:resource].args[:resource_id].value
|
||||||
|
expect(device_id).to eq(device.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "rejects bogus resource_updates" do
|
it "deprecates resource_updates" do
|
||||||
fake_id = FactoryBot.create(:plant).id + 1
|
fake_id = FactoryBot.create(:plant).id + 1
|
||||||
expect(Plant.exists?(fake_id)).to be(false)
|
expect(Plant.exists?(fake_id)).to be(false)
|
||||||
ast = { "kind": "resource_update",
|
ast = { "kind": "resource_update",
|
||||||
|
@ -172,20 +189,8 @@ describe CeleryScript::Corpus do
|
||||||
expect(hmm.args.fetch(:resource_id).value).to eq(fake_id)
|
expect(hmm.args.fetch(:resource_id).value).to eq(fake_id)
|
||||||
checker = CeleryScript::Checker.new(hmm, corpus, device)
|
checker = CeleryScript::Checker.new(hmm, corpus, device)
|
||||||
expect(checker.valid?).to be(false)
|
expect(checker.valid?).to be(false)
|
||||||
expect(checker.error.message).to eq("Can't find Plant with id of #{fake_id}")
|
msg = "Deprecated `mark_as` detected. Delete it and re-add"
|
||||||
end
|
expect(checker.error.message).to eq(msg)
|
||||||
|
|
||||||
it "rejects bogus resource_types" do
|
|
||||||
ast = { "kind": "resource_update",
|
|
||||||
"args": { "resource_type" => "CanOpener",
|
|
||||||
"resource_id" => 0,
|
|
||||||
"label" => "foo",
|
|
||||||
"value" => "Should Fail" } }
|
|
||||||
checker = CeleryScript::Checker.new(CeleryScript::AstNode.new(**ast),
|
|
||||||
corpus,
|
|
||||||
device)
|
|
||||||
expect(checker.valid?).to be(false)
|
|
||||||
expect(checker.error.message).to include('"CanOpener" is not a valid resource_type.')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "has enums" do
|
it "has enums" do
|
||||||
|
|
|
@ -167,13 +167,25 @@ describe Points::Destroy do
|
||||||
|
|
||||||
def mark_as(resource)
|
def mark_as(resource)
|
||||||
{
|
{
|
||||||
kind: "resource_update",
|
kind: "update_resource",
|
||||||
|
args: {
|
||||||
|
resource: {
|
||||||
|
kind: "resource",
|
||||||
args: {
|
args: {
|
||||||
resource_type: resource.class.to_s,
|
resource_type: resource.class.to_s,
|
||||||
resource_id: resource.id,
|
resource_id: resource.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
kind: "pair",
|
||||||
|
args: {
|
||||||
label: "foo",
|
label: "foo",
|
||||||
value: "bar",
|
value: "bar",
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue