fix device auth status

This commit is contained in:
anlicheng 2023-08-21 18:00:05 +08:00
parent 97dd938363
commit 54f7acc3f7

View File

@ -153,21 +153,22 @@ handle_event(cast, reload, _, State = #state{device_uuid = DeviceUUID}) ->
end;
%%
handle_event(cast, {auth, false}, ?STATE_DENIED, State = #state{device_uuid = DeviceUUID}) ->
lager:debug("[iot_device] device_uuid: ~p, auth: false, will keep state_name: ~p", [DeviceUUID, ?STATE_DENIED]),
{ok, _} = device_bo:change_status(DeviceUUID, ?DEVICE_OFFLINE),
{keep_state, State};
handle_event(cast, {auth, Auth}, StateName, State = #state{device_uuid = DeviceUUID}) ->
case {StateName, Auth} of
{?STATE_DENIED, false} ->
lager:debug("[iot_device] device_uuid: ~p, auth: false, will keep state_name: ~p", [DeviceUUID, ?STATE_DENIED]),
{keep_state, State};
{?STATE_DENIED, true} ->
{next_state, ?STATE_ACTIVATED, State};
handle_event(cast, {auth, true}, ?STATE_DENIED, State) ->
{next_state, ?STATE_ACTIVATED, State};
handle_event(cast, {auth, true}, ?STATE_ACTIVATED, State = #state{device_uuid = DeviceUUID}) ->
lager:debug("[iot_device] device_uuid: ~p, auth: true, will keep state_name: ~p", [DeviceUUID, ?STATE_ACTIVATED]),
{keep_state, State};
handle_event(cast, {auth, false}, ?STATE_ACTIVATED, State = #state{device_uuid = DeviceUUID}) ->
lager:debug("[iot_device] device_uuid: ~p, auth: false, state_name from: ~p, to: ~p", [DeviceUUID, ?STATE_ACTIVATED, ?STATE_DENIED]),
{ok, _} = device_bo:change_status(DeviceUUID, ?DEVICE_OFFLINE),
{next_state, ?STATE_DENIED, State#state{status = ?DEVICE_OFFLINE}}.
{?STATE_ACTIVATED, false} ->
lager:debug("[iot_device] device_uuid: ~p, auth: false, state_name from: ~p, to: ~p", [DeviceUUID, ?STATE_ACTIVATED, ?STATE_DENIED]),
{ok, _} = device_bo:change_status(DeviceUUID, ?DEVICE_OFFLINE),
{next_state, ?STATE_DENIED, State#state{status = ?DEVICE_OFFLINE}};
{?STATE_ACTIVATED, true} ->
lager:debug("[iot_device] device_uuid: ~p, auth: true, will keep state_name: ~p", [DeviceUUID, ?STATE_ACTIVATED]),
{keep_state, State}
end.
%% @private
%% @doc This function is called by a gen_statem when it is about to