Skip to content
Permalink
Browse files

Make sure FarmwareEnv is updated in the API after an update

  • Loading branch information...
ConnorRigby committed Aug 12, 2019
1 parent b93c31a commit 8f560450deb04613cac52405716df88184c63699
Showing with 17 additions and 8 deletions.
  1. +6 −6 farmbot_core/lib/farmbot_core/asset.ex
  2. +11 −2 farmbot_os/lib/farmbot_os/sys_calls.ex
@@ -50,7 +50,6 @@ defmodule FarmbotCore.Asset do
:ok
end


## End Device

## Begin FarmEvent
@@ -375,11 +374,12 @@ defmodule FarmbotCore.Asset do

def new_farmware_env(params) do
key = params["key"] || params[:key]

fwe =
if key do
Repo.get_by(FarmwareEnv, key: key)
end || %FarmwareEnv{}
fwe = with key when is_binary(key) <- key,
[fwe | _] <- Repo.all(from fwe in FarmwareEnv, where: fwe.key == ^key) do
fwe
else
_ -> %FarmwareEnv{}
end

FarmwareEnv.changeset(fwe, params)
|> Repo.insert_or_update()
@@ -8,6 +8,7 @@ defmodule FarmbotOS.SysCalls do
alias FarmbotCore.Asset.{
BoxLed,
Peripheral,
Private,
Sensor
}

@@ -126,8 +127,16 @@ defmodule FarmbotOS.SysCalls do

@impl true
def set_user_env(key, value) do
_ = Asset.new_farmware_env(%{key: key, value: value})
:ok
with {:ok, fwe} <- Asset.new_farmware_env(%{key: key, value: value}),
_ <- Private.mark_dirty!(fwe) do
:ok
else
{:error, reason} ->
{:error, inspect(reason)}

error ->
{:error, inspect(error)}
end
end

@impl true

0 comments on commit 8f56045

Please sign in to comment.
You can’t perform that action at this time.