fix(import): add bridge_mqtt compatible <4.2.x
This commit is contained in:
parent
622edcd536
commit
83b99c09a4
|
@ -32,4 +32,4 @@
|
||||||
-define(ERROR14, 114). %% OldPassword error
|
-define(ERROR14, 114). %% OldPassword error
|
||||||
-define(ERROR15, 115). %% bad topic
|
-define(ERROR15, 115). %% bad topic
|
||||||
|
|
||||||
-define(VERSIONS, ["1", "3.2", "3.4", "4.0", "4.1", "4.2"]).
|
-define(VERSIONS, ["1", "3.2", "3.4", "4.0", "4.1", "4.2", "4.3"]).
|
|
@ -212,8 +212,8 @@ map_to_action(Map = #{<<"id">> := ActionInstId, <<"name">> := Name, <<"args">> :
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
import_rules(Rules) ->
|
import_rules(Rules) ->
|
||||||
lists:foreach(fun(Resource) ->
|
lists:foreach(fun(Rule) ->
|
||||||
import_resource(Resource)
|
import_rule(Rule)
|
||||||
end, Rules).
|
end, Rules).
|
||||||
|
|
||||||
import_resources(Reources) ->
|
import_resources(Reources) ->
|
||||||
|
@ -242,7 +242,9 @@ import_resources_and_rules(Resources, Rules, _FromVersion) ->
|
||||||
import_rules(Rules).
|
import_rules(Rules).
|
||||||
-else.
|
-else.
|
||||||
import_resources_and_rules(Resources, Rules, FromVersion)
|
import_resources_and_rules(Resources, Rules, FromVersion)
|
||||||
when FromVersion =:= "4.0" orelse FromVersion =:= "4.1" orelse FromVersion =:= "4.2" ->
|
when FromVersion =:= "4.0" orelse
|
||||||
|
FromVersion =:= "4.1" orelse
|
||||||
|
FromVersion =:= "4.2" ->
|
||||||
Configs = lists:foldl(fun compatible_version/2 , [], Resources),
|
Configs = lists:foldl(fun compatible_version/2 , [], Resources),
|
||||||
lists:foreach(fun(#{<<"actions">> := Actions} = Rule) ->
|
lists:foreach(fun(#{<<"actions">> := Actions} = Rule) ->
|
||||||
NActions = apply_new_config(Actions, Configs),
|
NActions = apply_new_config(Actions, Configs),
|
||||||
|
@ -253,7 +255,6 @@ import_resources_and_rules(Resources, Rules, _FromVersion) ->
|
||||||
import_resources(Resources),
|
import_resources(Resources),
|
||||||
import_rules(Rules).
|
import_rules(Rules).
|
||||||
|
|
||||||
|
|
||||||
%% 4.2.5 +
|
%% 4.2.5 +
|
||||||
compatible_version(#{<<"id">> := ID,
|
compatible_version(#{<<"id">> := ID,
|
||||||
<<"type">> := <<"web_hook">>,
|
<<"type">> := <<"web_hook">>,
|
||||||
|
@ -284,9 +285,30 @@ compatible_version(#{<<"id">> := ID,
|
||||||
Cfg = make_new_config(#{<<"method">> => Method,
|
Cfg = make_new_config(#{<<"method">> => Method,
|
||||||
<<"url">> => URL}),
|
<<"url">> => URL}),
|
||||||
{ok, _Resource} = import_resource(Resource#{<<"config">> := Cfg}),
|
{ok, _Resource} = import_resource(Resource#{<<"config">> := Cfg}),
|
||||||
NHeaders = maps:put(<<"content-type">>, <<"application/json">> , Headers),
|
NHeaders = maps:put(<<"content-type">>, <<"application/json">> ,
|
||||||
|
case Headers of
|
||||||
|
[] -> #{};
|
||||||
|
Other -> Other
|
||||||
|
end),
|
||||||
[{ID, #{headers => NHeaders, method => Method}} | Acc];
|
[{ID, #{headers => NHeaders, method => Method}} | Acc];
|
||||||
% 4.2.3
|
|
||||||
|
%% bridge mqtt
|
||||||
|
%% 4.2.0 - 4.2.5 bridge_mqtt, ssl enabled from on/off to true/false
|
||||||
|
compatible_version(#{<<"type">> := <<"bridge_mqtt">>,
|
||||||
|
<<"id">> := ID, %% begin 4.2.0.
|
||||||
|
<<"config">> := #{<<"ssl">> := Ssl} = Config} = Resource, Acc) ->
|
||||||
|
F = fun(B) ->
|
||||||
|
case B of
|
||||||
|
<<"on">> -> true;
|
||||||
|
<<"off">> -> false;
|
||||||
|
Other -> Other
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
NewConfig = Config#{<<"ssl">> := F(Ssl)},
|
||||||
|
{ok, _Resource} = import_resource(Resource#{<<"config">> := NewConfig}),
|
||||||
|
[{ID, NewConfig} | Acc];
|
||||||
|
|
||||||
|
% 4.2.3, add :content_type
|
||||||
compatible_version(#{<<"id">> := ID,
|
compatible_version(#{<<"id">> := ID,
|
||||||
<<"type">> := <<"web_hook">>,
|
<<"type">> := <<"web_hook">>,
|
||||||
<<"config">> := #{<<"headers">> := Headers,
|
<<"config">> := #{<<"headers">> := Headers,
|
||||||
|
@ -310,7 +332,7 @@ make_new_config(Cfg) ->
|
||||||
<<"cacertfile">> => <<>>,
|
<<"cacertfile">> => <<>>,
|
||||||
<<"certfile">> => <<>>,
|
<<"certfile">> => <<>>,
|
||||||
<<"keyfile">> => <<>>,
|
<<"keyfile">> => <<>>,
|
||||||
<<"verify">> => true},
|
<<"verify">> => false},
|
||||||
maps:merge(Cfg, Config).
|
maps:merge(Cfg, Config).
|
||||||
|
|
||||||
apply_new_config(Actions, Configs) ->
|
apply_new_config(Actions, Configs) ->
|
||||||
|
|
Loading…
Reference in New Issue