Skip to content

Commit 07dcdba

Browse files
committed
Fixed all the warnings from the Luacheck linter tool
1 parent fc79578 commit 07dcdba

File tree

8 files changed

+38
-42
lines changed

8 files changed

+38
-42
lines changed

drivers/SmartThings/abb-scu200/src/abb/device_manager.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ end
104104
-- Method for monitoring the connection of the bridge devices
105105
function device_manager.bridge_monitor(driver, device, bridge_info)
106106
local child_devices = device:get_child_list()
107-
107+
108108
for _, thing_device in ipairs(child_devices) do
109109
device.thread:call_with_delay(0, function() -- Run within bridge thread to use the same connection
110110
device_manager.refresh(driver, thing_device)

drivers/SmartThings/abb-scu200/src/abb/device_refresher.lua

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ local device_refresher = {}
1212
local function refresh_current_sensor(driver, device, values)
1313
local dni = utils.get_dni_from_device(device)
1414
log.info("refresh_current_sensor(): Refreshing data of Current Sensor, dni = " .. dni)
15-
15+
1616
-- Refresh Current Measurement
1717
local current = values.current
1818

@@ -36,13 +36,13 @@ local function refresh_current_sensor(driver, device, values)
3636
-- Refresh Active Energy
3737
log.trace("refresh_current_sensor(): Refreshing Active Energy, dni = " .. dni)
3838
device.profile.components["main"]:emit_event(caps.energyMeter.energy({value=activeEnergy, unit="kWh"}))
39-
39+
4040
-- Verify whether the appropriate time have elapsed to report the energy values
4141
local last_energy_report = device:get_field(fields.LAST_ENERGY_REPORT) or 0.0
4242

4343
if (os.time() - last_energy_report) >= config.EDGE_CHILD_ENERGY_REPORT_INTERVAL then -- Report the energy consumption/production periodically
4444
local current_consumption_production_report = device:get_latest_state("main", caps.powerConsumptionReport.ID, caps.powerConsumptionReport.powerConsumption.NAME)
45-
45+
4646
-- Calculate delta consumption/production energy
4747
local delta_consumption_production_report = 0.0
4848
if current_consumption_production_report ~= nil then
@@ -119,15 +119,15 @@ local function refresh_energy_meter(driver, device, values)
119119
-- Refresh Active Energy Import Total
120120
log.trace("refresh_energy_meter(): Refreshing Active Energy Import Total, dni = " .. dni)
121121
device.profile.components["consumptionMeter"]:emit_event(caps.energyMeter.energy({value=activeEnergyImportTotal, unit="kWh"}))
122-
122+
123123
-- Refresh Active Energy Export Total
124124
log.trace("refresh_energy_meter(): Refreshing Active Energy Export Total, dni = " .. dni)
125125
device.profile.components["productionMeter"]:emit_event(caps.energyMeter.energy({value=activeEnergyExportTotal, unit="kWh"}))
126126

127127
-- Refresh Active Energy Net Negative
128128
log.trace("refresh_energy_meter(): Refreshing Active Energy Net Negative, dni = " .. dni)
129129
device.profile.components["surplus"]:emit_event(caps.energyMeter.energy({value=activeEnergyNetNegative, unit="kWh"}))
130-
130+
131131
-- Verify whether the appropriate time have elapsed to report the energy net, consumption and production
132132
local last_energy_report = device:get_field(fields.LAST_ENERGY_REPORT) or 0.0
133133

@@ -246,7 +246,7 @@ local function refresh_water_meter(driver, device, values)
246246
log.trace("refresh_water_meter(): Refreshing Water Meter: last hour, dni = " .. dni)
247247
device:emit_event(caps.waterMeter.lastHour({value=lastHourFlow, unit=unit}))
248248
end
249-
249+
250250
-- Refresh Water Meter: last 24 hours
251251
local lastTwentyFourHoursFlow = values.lastTwentyFourHoursFlow
252252

@@ -262,7 +262,7 @@ local function refresh_water_meter(driver, device, values)
262262
log.trace("refresh_water_meter(): Refreshing Water Meter: last 7 days, dni = " .. dni)
263263
device:emit_event(caps.waterMeter.lastSevenDays({value=lastSevenDaysFlow, unit=unit}))
264264
end
265-
265+
266266
return true
267267
end
268268

@@ -283,7 +283,7 @@ local function refresh_gas_meter(driver, device, values)
283283

284284
-- Refresh Gas Meter
285285
local gasMeterVolume = values.gasMeterVolume
286-
286+
287287
if gasMeterVolume ~= nil then
288288
log.trace("refresh_gas_meter(): Refreshing Gas Meter, dni = " .. dni)
289289
device:emit_event(caps.gasMeter.gasMeterVolume({value=gasMeterVolume, unit=gasMeterVolumeUnit}))

drivers/SmartThings/abb-scu200/src/commands.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
local caps = require('st.capabilities')
22
local log = require('log')
3-
local cosock = require "cosock"
43
local json = require('dkjson')
54

65
-- Local imports
@@ -19,7 +18,7 @@ local function post_payload(device, payload)
1918
local communication_device = device:get_parent_device() or device
2019
local conn_info = communication_device:get_field(fields.CONN_INFO)
2120

22-
local response, err, status = conn_info:post_device_by_id(dni, payload)
21+
local _, err, status = conn_info:post_device_by_id(dni, payload)
2322
if not err and status == 200 then
2423
log.info("post_payload(): Success, dni = " .. dni)
2524

@@ -36,7 +35,7 @@ end
3635

3736
-- Switch on command
3837
function commands.switch_on(driver, device, cmd)
39-
local dni, device_type = utils.get_dni_from_device(device)
38+
local dni, _ = utils.get_dni_from_device(device)
4039
log.info("commands.switch_on(): Switching on capablity within dni = " .. dni)
4140

4241
local device_model = utils.get_device_model(device)
@@ -62,7 +61,7 @@ end
6261

6362
-- Switch off commands
6463
function commands.switch_off(driver, device, cmd)
65-
local dni, device_type = utils.get_dni_from_device(device)
64+
local dni, _ = utils.get_dni_from_device(device)
6665
log.info("commands.switch_off(): Switching off capablity within dni = " .. dni)
6766

6867
local device_model = utils.get_device_model(device)

drivers/SmartThings/abb-scu200/src/discovery.lua

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ local joined_thing = {}
1717
-- Method for setting the device fields
1818
function discovery.set_device_fields(driver, device)
1919
local dni = utils.get_dni_from_device(device)
20-
20+
2121
if joined_bridge[dni] ~= nil then
2222
log.info("discovery.set_device_field(): Setting device field for bridge: " .. dni)
2323
local bridge_cache_value = driver.datastore.bridge_discovery_cache[dni]
24-
24+
2525
device:set_field(fields.BRIDGE_IPV4, bridge_cache_value.ip, {persist = true})
2626
device:set_field(fields.DEVICE_TYPE, fields.DEVICE_TYPE_BRIDGE, {persist = true})
2727
elseif joined_thing[dni] ~= nil then
2828
log.info("discovery.set_device_field(): Setting device field for thing: " .. dni)
2929
local thing_cache_value = driver.datastore.thing_discovery_cache[dni]
30-
30+
3131
device:set_field(fields.PARENT_BRIDGE_DNI, thing_cache_value.parent_bridge_dni, {persist = true})
3232
device:set_field(fields.THING_INFO, thing_cache_value.thing_info, {persist = true})
3333
device:set_field(fields.DEVICE_TYPE, fields.DEVICE_TYPE_THING, {persist = true})
@@ -146,8 +146,8 @@ local function parse_ssdp(data)
146146
res.status = data:sub(0, data:find('\r\n'))
147147

148148
for line in data:gmatch("[^\r\n]+") do
149-
_, _, header, value = string.find(line, "([%w-]+):%s*([%a+-:_ /=?]*)")
150-
149+
local _, _, header, value = string.find(line, "([%w-]+):%s*([%a+-:_ /=?]*)")
150+
151151
if header ~= nil and value ~= nil then
152152
res[header:lower()] = value
153153
end
@@ -226,7 +226,7 @@ local function discover_bridges(driver)
226226

227227
log.debug("discover_bridges(): Known devices: " .. dni .. " with type: " .. device_type)
228228
end
229-
229+
230230
-- Find new devices
231231
local found_devices = discovery.find_devices()
232232

@@ -238,8 +238,6 @@ local function discover_bridges(driver)
238238
if not joined_bridge[dni] then
239239
if try_add_bridge(driver, dni, device) then
240240
joined_bridge[dni] = true
241-
242-
bridge_ip = device["ip"]
243241
end
244242
else
245243
log.debug("discover_bridges(): Bridge already joined: " .. dni)
@@ -272,7 +270,7 @@ local function discover_things(driver)
272270

273271
if known_devices[bridge_dni] ~= nil and known_devices[bridge_dni]:get_field(fields.CONN_INFO) ~= nil then
274272
local thing_infos = api.get_thing_infos(bridge_ip, bridge_dni)
275-
273+
276274
if thing_infos and thing_infos.devices ~= nil then
277275
for _, thing_info in pairs(thing_infos.devices) do
278276
if thing_info ~= nil then

drivers/SmartThings/abb-scu200/src/eventsource_handler.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function eventsource_handler.handle_sse_event(driver, bridge, msg)
4747
device:online()
4848
else
4949
log.error("eventsource_handler.handle_sse_event(): Failed to update the device's values")
50-
50+
5151
-- Set device as offline
5252
device:offline()
5353
end

drivers/SmartThings/abb-scu200/src/fields.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ local fields = {
1212
DEVICE_TYPE_BRIDGE = "bridge",
1313
DEVICE_TYPE_THING = "thing"
1414
}
15-
15+
1616
return fields

drivers/SmartThings/abb-scu200/src/lifecycles.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ local utils = require('utils')
66
local discovery = require('discovery')
77
local commands = require('commands')
88
local connection_monitor = require('connection_monitor')
9-
local device_manager = require('abb.device_manager')
109
local eventsource_handler = require("eventsource_handler")
1110

1211
-- Lifecycles handlers for the driver
@@ -40,15 +39,15 @@ function lifecycles.init(driver, device)
4039
end
4140

4241
-- Refresh the device manually
43-
commands.refresh(driver, device, _)
44-
42+
commands.refresh(driver, device, nil)
43+
4544
-- Refresh schedule
4645
local refresh_period = utils.get_thing_refresh_period(device)
4746

4847
device.thread:call_on_schedule(
4948
refresh_period,
5049
function ()
51-
return commands.refresh(driver, device, _)
50+
return commands.refresh(driver, device, nil)
5251
end,
5352
"Refresh schedule")
5453
end

drivers/SmartThings/abb-scu200/src/utils.lua

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function utils.get_dni_from_device(device)
1818
else
1919
local bridge_dni = device.device_network_id
2020

21-
return bridge_dni, fields.DEVICE_TYPE_BRIDGE
21+
return bridge_dni, fields.DEVICE_TYPE_BRIDGE
2222
end
2323
end
2424

@@ -41,7 +41,7 @@ end
4141
-- Get the device IP address
4242
function utils.get_device_ip_address(device)
4343
local _, device_type = utils.get_dni_from_device(device)
44-
44+
4545
if device_type == fields.DEVICE_TYPE_BRIDGE then
4646
return device:get_field(fields.BRIDGE_IPV4)
4747
else
@@ -145,56 +145,56 @@ function utils.backoff_builder(max, inc, rand)
145145
if rand then
146146
randval = math.random() * rand * 2 - rand
147147
end
148-
148+
149149
local base = inc * (2 ^ count - 1)
150150
count = count + 1
151-
151+
152152
-- ensure base backoff (not including random factor) is less than max
153153
if max then base = math.min(base, max) end
154-
154+
155155
-- ensure total backoff is >= 0
156156
return math.max(base + randval, 0)
157157
end
158158
end
159159

160160
-- Method for creating a labeled socket
161-
function utils.labeled_socket_builder(label, ssl_config)
161+
function utils.labeled_socket_builder(label, ssl_config)
162162
label = (label or "")
163163
if #label > 0 then
164164
label = label .. " "
165165
end
166-
166+
167167
if not ssl_config then
168168
ssl_config = { mode = "client", protocol = "any", verify = "none", options = "all" }
169169
end
170-
170+
171171
local function make_socket(host, port, wrap_ssl)
172172
log.info("utils.labeled_socket_builder(): Creating TCP socket for REST Connection: " .. label)
173173
local _ = nil
174174
local sock, err = socket.tcp()
175-
175+
176176
if err ~= nil or (not sock) then
177177
return nil, (err or "unknown error creating TCP socket")
178178
end
179-
179+
180180
log.debug("utils.labeled_socket_builder(): Setting TCP socket timeout for REST Connection: " .. label)
181181
_, err = sock:settimeout(60)
182182
if err ~= nil then
183183
return nil, "settimeout error: " .. err
184184
end
185-
185+
186186
log.debug("utils.labeled_socket_builder(): Connecting TCP socket for REST Connection: " .. label)
187187
_, err = sock:connect(host, port)
188188
if err ~= nil then
189189
return nil, "Connect error: " .. err
190190
end
191-
191+
192192
log.debug("utils.labeled_socket_builder(): Set Keepalive for TCP socket for REST Connection: " .. label)
193193
_, err = sock:setoption("keepalive", true)
194194
if err ~= nil then
195195
return nil, "Setoption error: " .. err
196196
end
197-
197+
198198
if wrap_ssl then
199199
log.debug("utils.labeled_socket_builder(): Creating SSL wrapper for REST Connection: " .. label)
200200
sock, err = ssl.wrap(sock, ssl_config)
@@ -208,7 +208,7 @@ function utils.labeled_socket_builder(label, ssl_config)
208208
return nil, "Error with SSL handshake: " .. err
209209
end
210210
end
211-
211+
212212
log.info("utils.labeled_socket_builder(): Successfully created TCP connection: " .. label)
213213
return sock, err
214214
end

0 commit comments

Comments
 (0)