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 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