forked from luca/mineqtt
feat: return error if not/already connected
This commit is contained in:
parent
0fae036609
commit
5d0c1bdec4
8
mqtt.lua
8
mqtt.lua
|
@ -84,6 +84,10 @@ function MqttClient:new (conn)
|
||||||
end
|
end
|
||||||
|
|
||||||
function MqttClient:handle ()
|
function MqttClient:handle ()
|
||||||
|
if not (self.is_connecting or self.is_connected) then
|
||||||
|
return "no connection"
|
||||||
|
end
|
||||||
|
|
||||||
local data, err = self.conn:safeRead(2)
|
local data, err = self.conn:safeRead(2)
|
||||||
if err ~= nil then
|
if err ~= nil then
|
||||||
return err
|
return err
|
||||||
|
@ -159,7 +163,7 @@ end
|
||||||
|
|
||||||
function MqttClient:connect (username, password)
|
function MqttClient:connect (username, password)
|
||||||
if self.is_connecting or self.is_connected then
|
if self.is_connecting or self.is_connected then
|
||||||
return nil
|
return "already connected"
|
||||||
end
|
end
|
||||||
|
|
||||||
local length = 13
|
local length = 13
|
||||||
|
@ -198,7 +202,7 @@ end
|
||||||
|
|
||||||
function MqttClient:disconnect (reason)
|
function MqttClient:disconnect (reason)
|
||||||
if not (self.is_connecting or self.is_connected) then
|
if not (self.is_connecting or self.is_connected) then
|
||||||
return nil
|
return "no connection"
|
||||||
end
|
end
|
||||||
|
|
||||||
if reason == nil then
|
if reason == nil then
|
||||||
|
|
Loading…
Reference in New Issue