chore: fix elvis warnings
This commit is contained in:
parent
f194ae65d2
commit
2be33b33e3
|
@ -606,8 +606,6 @@ default_conninfo(ConnInfo) ->
|
||||||
ConnInfo#{clean_start => true,
|
ConnInfo#{clean_start => true,
|
||||||
clientid => undefined,
|
clientid => undefined,
|
||||||
username => undefined,
|
username => undefined,
|
||||||
proto_name => undefined,
|
|
||||||
proto_ver => undefined,
|
|
||||||
conn_props => #{},
|
conn_props => #{},
|
||||||
connected => true,
|
connected => true,
|
||||||
connected_at => erlang:system_time(millisecond),
|
connected_at => erlang:system_time(millisecond),
|
||||||
|
|
|
@ -74,7 +74,8 @@ call(Pid, Msg, Timeout) ->
|
||||||
Error -> {error, Error}
|
Error -> {error, Error}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
init(CoapPid, EndpointName, Peername = {_Peerhost, _Port}, RegInfo = #{<<"lt">> := LifeTime, <<"lwm2m">> := Ver}) ->
|
init(CoapPid, EndpointName, Peername = {_Peerhost, _Port},
|
||||||
|
RegInfo = #{<<"lt">> := LifeTime, <<"lwm2m">> := Ver}) ->
|
||||||
Mountpoint = proplists:get_value(mountpoint, lwm2m_coap_responder:options(), ""),
|
Mountpoint = proplists:get_value(mountpoint, lwm2m_coap_responder:options(), ""),
|
||||||
Lwm2mState = #lwm2m_state{peername = Peername,
|
Lwm2mState = #lwm2m_state{peername = Peername,
|
||||||
endpoint_name = EndpointName,
|
endpoint_name = EndpointName,
|
||||||
|
@ -105,7 +106,8 @@ init(CoapPid, EndpointName, Peername = {_Peerhost, _Port}, RegInfo = #{<<"lt">>
|
||||||
emqx_cm:insert_channel_info(EndpointName, info(Lwm2mState1), stats(Lwm2mState1)),
|
emqx_cm:insert_channel_info(EndpointName, info(Lwm2mState1), stats(Lwm2mState1)),
|
||||||
emqx_lwm2m_cm:register_channel(EndpointName, RegInfo, LifeTime, Ver, Peername),
|
emqx_lwm2m_cm:register_channel(EndpointName, RegInfo, LifeTime, Ver, Peername),
|
||||||
|
|
||||||
{ok, Lwm2mState1#lwm2m_state{life_timer = emqx_lwm2m_timer:start_timer(LifeTime, {life_timer, expired})}};
|
NTimer = emqx_lwm2m_timer:start_timer(LifeTime, {life_timer, expired}),
|
||||||
|
{ok, Lwm2mState1#lwm2m_state{life_timer = NTimer}};
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
_ = run_hooks('client.connack', [conninfo(Lwm2mState), not_authorized], undefined),
|
_ = run_hooks('client.connack', [conninfo(Lwm2mState), not_authorized], undefined),
|
||||||
{error, Error}
|
{error, Error}
|
||||||
|
@ -186,7 +188,8 @@ deliver(#message{topic = Topic, payload = Payload},
|
||||||
started_at = StartedAt,
|
started_at = StartedAt,
|
||||||
endpoint_name = EndpointName}) ->
|
endpoint_name = EndpointName}) ->
|
||||||
IsCacheMode = is_cache_mode(RegInfo, StartedAt),
|
IsCacheMode = is_cache_mode(RegInfo, StartedAt),
|
||||||
?LOG(debug, "Get MQTT message from broker, IsCacheModeNow?: ~p, Topic: ~p, Payload: ~p", [IsCacheMode, Topic, Payload]),
|
?LOG(debug, "Get MQTT message from broker, IsCacheModeNow?: ~p, "
|
||||||
|
"Topic: ~p, Payload: ~p", [IsCacheMode, Topic, Payload]),
|
||||||
AlternatePath = maps:get(<<"alternatePath">>, RegInfo, <<"/">>),
|
AlternatePath = maps:get(<<"alternatePath">>, RegInfo, <<"/">>),
|
||||||
deliver_to_coap(AlternatePath, Payload, CoapPid, IsCacheMode, EndpointName),
|
deliver_to_coap(AlternatePath, Payload, CoapPid, IsCacheMode, EndpointName),
|
||||||
Lwm2mState.
|
Lwm2mState.
|
||||||
|
@ -256,7 +259,8 @@ time_now() -> erlang:system_time(millisecond).
|
||||||
%% Deliver downlink message to coap
|
%% Deliver downlink message to coap
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
deliver_to_coap(AlternatePath, JsonData, CoapPid, CacheMode, EndpointName) when is_binary(JsonData)->
|
deliver_to_coap(AlternatePath, JsonData,
|
||||||
|
CoapPid, CacheMode, EndpointName) when is_binary(JsonData)->
|
||||||
try
|
try
|
||||||
TermData = emqx_json:decode(JsonData, [return_maps]),
|
TermData = emqx_json:decode(JsonData, [return_maps]),
|
||||||
deliver_to_coap(AlternatePath, TermData, CoapPid, CacheMode, EndpointName)
|
deliver_to_coap(AlternatePath, TermData, CoapPid, CacheMode, EndpointName)
|
||||||
|
@ -285,7 +289,8 @@ deliver_to_coap(AlternatePath, TermData, CoapPid, CacheMode, EndpointName) when
|
||||||
send_to_broker(EventType, Payload = #{}, Lwm2mState) ->
|
send_to_broker(EventType, Payload = #{}, Lwm2mState) ->
|
||||||
do_send_to_broker(EventType, Payload, Lwm2mState).
|
do_send_to_broker(EventType, Payload, Lwm2mState).
|
||||||
|
|
||||||
do_send_to_broker(EventType, #{<<"data">> := Data} = Payload, #lwm2m_state{endpoint_name = EndpointName} = Lwm2mState) ->
|
do_send_to_broker(EventType, #{<<"data">> := Data} = Payload,
|
||||||
|
#lwm2m_state{endpoint_name = EndpointName} = Lwm2mState) ->
|
||||||
ReqPath = maps:get(<<"reqPath">>, Data, undefined),
|
ReqPath = maps:get(<<"reqPath">>, Data, undefined),
|
||||||
Code = maps:get(<<"code">>, Data, undefined),
|
Code = maps:get(<<"code">>, Data, undefined),
|
||||||
CodeMsg = maps:get(<<"codeMsg">>, Data, undefined),
|
CodeMsg = maps:get(<<"codeMsg">>, Data, undefined),
|
||||||
|
@ -333,12 +338,21 @@ observe_object_list(AlternatePath, ObjectList, CoapPid, EndpointName) ->
|
||||||
[ObjInsId | _LastPath1] = LastPath,
|
[ObjInsId | _LastPath1] = LastPath,
|
||||||
case ObjInsId of
|
case ObjInsId of
|
||||||
<<"0">> ->
|
<<"0">> ->
|
||||||
observe_object_slowly(AlternatePath, <<"/19/0/0">>, CoapPid, 100, EndpointName);
|
observe_object_slowly(
|
||||||
|
AlternatePath, <<"/19/0/0">>,
|
||||||
|
CoapPid, 100, EndpointName
|
||||||
|
);
|
||||||
_ ->
|
_ ->
|
||||||
observe_object_slowly(AlternatePath, ObjectPath, CoapPid, 100, EndpointName)
|
observe_object_slowly(
|
||||||
|
AlternatePath, ObjectPath,
|
||||||
|
CoapPid, 100, EndpointName
|
||||||
|
)
|
||||||
end;
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
observe_object_slowly(AlternatePath, ObjectPath, CoapPid, 100, EndpointName)
|
observe_object_slowly(
|
||||||
|
AlternatePath, ObjectPath,
|
||||||
|
CoapPid, 100, EndpointName
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end, ObjectList).
|
end, ObjectList).
|
||||||
|
|
||||||
|
@ -392,11 +406,12 @@ get_cached_downlink_messages() ->
|
||||||
is_cache_mode(RegInfo, StartedAt) ->
|
is_cache_mode(RegInfo, StartedAt) ->
|
||||||
case is_psm(RegInfo) orelse is_qmode(RegInfo) of
|
case is_psm(RegInfo) orelse is_qmode(RegInfo) of
|
||||||
true ->
|
true ->
|
||||||
QModeTimeWind = proplists:get_value(qmode_time_window, lwm2m_coap_responder:options(), 22),
|
QModeTimeWind = proplists:get_value(
|
||||||
Now = time_now(),
|
qmode_time_window,
|
||||||
if (Now - StartedAt) >= QModeTimeWind -> true;
|
lwm2m_coap_responder:options(),
|
||||||
true -> false
|
22
|
||||||
end;
|
),
|
||||||
|
(time_now() - StartedAt) >= QModeTimeWind;
|
||||||
false -> false
|
false -> false
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
|
@ -108,6 +108,8 @@
|
||||||
, init/2
|
, init/2
|
||||||
]}).
|
]}).
|
||||||
|
|
||||||
|
-elvis([{elvis_style, dont_repeat_yourself, disable}]).
|
||||||
|
|
||||||
-type(pstate() :: #pstate{}).
|
-type(pstate() :: #pstate{}).
|
||||||
|
|
||||||
%% @doc Init protocol
|
%% @doc Init protocol
|
||||||
|
@ -132,7 +134,6 @@ init(ConnInfo = #{peername := {PeerHost, _Port},
|
||||||
|
|
||||||
AllowAnonymous = get_value(allow_anonymous, Opts, false),
|
AllowAnonymous = get_value(allow_anonymous, Opts, false),
|
||||||
DefaultUser = get_value(default_user, Opts),
|
DefaultUser = get_value(default_user, Opts),
|
||||||
|
|
||||||
#pstate{
|
#pstate{
|
||||||
conninfo = NConnInfo,
|
conninfo = NConnInfo,
|
||||||
clientinfo = ClientInfo,
|
clientinfo = ClientInfo,
|
||||||
|
@ -288,7 +289,12 @@ received(#stomp_frame{command = <<"CONNECT">>}, State = #pstate{connected = true
|
||||||
received(Frame = #stomp_frame{command = <<"SEND">>, headers = Headers}, State) ->
|
received(Frame = #stomp_frame{command = <<"SEND">>, headers = Headers}, State) ->
|
||||||
case header(<<"transaction">>, Headers) of
|
case header(<<"transaction">>, Headers) of
|
||||||
undefined -> {ok, handle_recv_send_frame(Frame, State)};
|
undefined -> {ok, handle_recv_send_frame(Frame, State)};
|
||||||
TransactionId -> add_action(TransactionId, {fun ?MODULE:handle_recv_send_frame/2, [Frame]}, receipt_id(Headers), State)
|
TransactionId ->
|
||||||
|
add_action(TransactionId,
|
||||||
|
{fun ?MODULE:handle_recv_send_frame/2, [Frame]},
|
||||||
|
receipt_id(Headers),
|
||||||
|
State
|
||||||
|
)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
received(#stomp_frame{command = <<"SUBSCRIBE">>, headers = Headers},
|
received(#stomp_frame{command = <<"SUBSCRIBE">>, headers = Headers},
|
||||||
|
@ -346,7 +352,11 @@ received(#stomp_frame{command = <<"UNSUBSCRIBE">>, headers = Headers},
|
||||||
received(Frame = #stomp_frame{command = <<"ACK">>, headers = Headers}, State) ->
|
received(Frame = #stomp_frame{command = <<"ACK">>, headers = Headers}, State) ->
|
||||||
case header(<<"transaction">>, Headers) of
|
case header(<<"transaction">>, Headers) of
|
||||||
undefined -> {ok, handle_recv_ack_frame(Frame, State)};
|
undefined -> {ok, handle_recv_ack_frame(Frame, State)};
|
||||||
TransactionId -> add_action(TransactionId, {fun ?MODULE:handle_recv_ack_frame/2, [Frame]}, receipt_id(Headers), State)
|
TransactionId ->
|
||||||
|
add_action(TransactionId,
|
||||||
|
{fun ?MODULE:handle_recv_ack_frame/2, [Frame]},
|
||||||
|
receipt_id(Headers),
|
||||||
|
State)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
%% NACK
|
%% NACK
|
||||||
|
@ -357,7 +367,11 @@ received(Frame = #stomp_frame{command = <<"ACK">>, headers = Headers}, State) ->
|
||||||
received(Frame = #stomp_frame{command = <<"NACK">>, headers = Headers}, State) ->
|
received(Frame = #stomp_frame{command = <<"NACK">>, headers = Headers}, State) ->
|
||||||
case header(<<"transaction">>, Headers) of
|
case header(<<"transaction">>, Headers) of
|
||||||
undefined -> {ok, handle_recv_nack_frame(Frame, State)};
|
undefined -> {ok, handle_recv_nack_frame(Frame, State)};
|
||||||
TransactionId -> add_action(TransactionId, {fun ?MODULE:handle_recv_nack_frame/2, [Frame]}, receipt_id(Headers), State)
|
TransactionId ->
|
||||||
|
add_action(TransactionId,
|
||||||
|
{fun ?MODULE:handle_recv_nack_frame/2, [Frame]},
|
||||||
|
receipt_id(Headers),
|
||||||
|
State)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
%% BEGIN
|
%% BEGIN
|
||||||
|
|
Loading…
Reference in New Issue