feat: return error if not/already connected

This commit is contained in:
Luca 2024-09-05 22:02:20 +02:00
parent 0fae036609
commit 5d0c1bdec4
1 changed files with 6 additions and 2 deletions

View File

@ -84,6 +84,10 @@ function MqttClient:new (conn)
end
function MqttClient:handle ()
if not (self.is_connecting or self.is_connected) then
return "no connection"
end
local data, err = self.conn:safeRead(2)
if err ~= nil then
return err
@ -159,7 +163,7 @@ end
function MqttClient:connect (username, password)
if self.is_connecting or self.is_connected then
return nil
return "already connected"
end
local length = 13
@ -198,7 +202,7 @@ end
function MqttClient:disconnect (reason)
if not (self.is_connecting or self.is_connected) then
return nil
return "no connection"
end
if reason == nil then