From 6bd2528ad5fcfac5add250eca82a9fae16bb148f Mon Sep 17 00:00:00 2001 From: anlicheng Date: Mon, 4 Sep 2023 12:24:40 +0800 Subject: [PATCH] fix --- apps/iot/src/iot_host.erl | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/apps/iot/src/iot_host.erl b/apps/iot/src/iot_host.erl index 12dd17c..5ed291c 100644 --- a/apps/iot/src/iot_host.erl +++ b/apps/iot/src/iot_host.erl @@ -228,19 +228,28 @@ handle_call({publish_message, _, _, _}, _From, State) -> {reply, {error, <<"主机状态错误,发送命令失败"/utf8>>}, State}; %% 关闭授权 -handle_call({activate, _}, _From, State = #state{has_session = false}) -> +handle_call({activate, Auth}, _From, State = #state{uuid = UUID, host_id = HostId, has_session = false}) -> + case Auth of + true -> + ok; + false -> + {ok, _} = host_bo:change_status(UUID, ?HOST_OFFLINE), + change_devices_status(HostId, ?DEVICE_UNKNOWN) + end, {reply, ok, State}; -handle_call({activate, true}, _From, State = #state{has_session = true}) -> - {reply, ok, State}; -handle_call({activate, false}, _From, State = #state{host_id = HostId, uuid = UUID, monitor_ref = MRef, channel_pid = ChannelPid, has_session = true}) -> - %% 取消之前的monitor - erlang:demonitor(MRef), - ws_channel:stop(ChannelPid, closed), - - {ok, _} = host_bo:change_status(UUID, ?HOST_OFFLINE), - change_devices_status(HostId, ?DEVICE_UNKNOWN), +handle_call({activate, Auth}, _From, State = #state{host_id = HostId, uuid = UUID, monitor_ref = MRef, channel_pid = ChannelPid, has_session = true}) -> + case Auth of + true -> + ok; + false -> + %% 取消之前的monitor + erlang:demonitor(MRef), + ws_channel:stop(ChannelPid, closed), + {ok, _} = host_bo:change_status(UUID, ?HOST_OFFLINE), + change_devices_status(HostId, ?DEVICE_UNKNOWN) + end, {reply, ok, State#state{monitor_ref = undefined, channel_pid = undefined, has_session = false}}; %% 绑定channel