Permalink
Browse files

Add `update_channel` to config_storage and use it to configure NervesHub

  • Loading branch information...
ConnorRigby committed Feb 8, 2019
1 parent 4f37006 commit 006297bf09c851a893bc86832f93558db04840ea
@@ -16,7 +16,8 @@ defmodule Farmbot.Bootstrap.SettingsSync do
"arduino_debug_messages",
"os_auto_update",
"firmware_hardware",
"network_not_found_timer"
"network_not_found_timer",
"update_channel"
]

@firmware_keys [
@@ -129,7 +130,8 @@ defmodule Farmbot.Bootstrap.SettingsSync do
]

@string_keys [
"firmware_hardware"
"firmware_hardware",
"update_channel"
]

@float_keys @firmware_keys ++ [
@@ -17,6 +17,9 @@ defmodule Farmbot.System.NervesHub do
## On host.
Just return :ok to everything.
"""
import Farmbot.System.ConfigStorage, only: [
get_config_value: 3, update_config_value: 4
]

@handler Application.get_env(:farmbot, :behaviour)[:nerves_hub_handler]
|| Mix.raise("missing :nerves_hub_handler module")
@@ -62,12 +65,7 @@ defmodule Farmbot.System.NervesHub do
end

def handle_info(:configure, :not_configured) do
channel = case Farmbot.Project.branch() do
"master" -> "channel:stable"
"beta" -> "channel:beta"
"staging" -> "channel:staging"
branch -> "channel:#{branch}"
end
channel = detect_channel()

if Process.whereis(Farmbot.HTTP) do
app_config = Application.get_env(:farmbot, __MODULE__, [])
@@ -85,9 +83,9 @@ defmodule Farmbot.System.NervesHub do
end

if channel == "channel:beta" do
Farmbot.System.ConfigStorage.update_config_value(:bool, "settings", "currently_on_beta", true)
update_config_value(:bool, "settings", "currently_on_beta", true)
else
Farmbot.System.ConfigStorage.update_config_value(:bool, "settings", "currently_on_beta", false)
update_config_value(:bool, "settings", "currently_on_beta", false)
end

{:noreply, :configured}
@@ -98,6 +96,15 @@ defmodule Farmbot.System.NervesHub do
end
end

def detect_channel do
get_config_value(:string, "settings", "update_channel") || case Farmbot.Project.branch() do
"master" -> "channel:stable"
"beta" -> "channel:beta"
"staging" -> "channel:staging"
branch -> "channel:#{branch}"
end
end

def get_config do
@handler.config()
end
@@ -0,0 +1,8 @@
defmodule Farmbot.System.ConfigStorage.Migrations.AddUpdateChannelField do
use Ecto.Migration
import Farmbot.System.ConfigStorage.MigrationHelpers

def change do
create_settings_config("update_channel", :string, nil)
end
end

0 comments on commit 006297b

Please sign in to comment.