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