Skip to content

Commit

Permalink
fixing linters
Browse files Browse the repository at this point in the history
  • Loading branch information
nkrasko committed Dec 13, 2024
1 parent b63ca71 commit ce3fb85
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions cloud_services/electricity_maps/src/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ function get_data()
local lat = values[LAT_CONFIG]
local result = {}

local request = http.request('GET', 'https://api.electricitymap.org/v3/carbon-intensity/latest?lon=' .. lon .. '&lat=' .. lat)
local request =
http.request('GET', 'https://api.electricitymap.org/v3/carbon-intensity/latest?lon=' .. lon .. '&lat=' .. lat)
request:set_header('auth-token', token)
local client = http.client({ timeout = 5 })
local response, err = client:do_request(request)
Expand All @@ -72,16 +73,17 @@ function get_data()
enapter.log('Request returned non-OK code: ' .. response.code, 'error')
return nil, 'wrong_request'
else
local jb = json.decode(response.body)
if jb['error'] then
local jb = json.decode(response.body)
if jb['error'] then
return nil, 'no_data'
else
else
result['carbonIntensity'] = jb['carbonIntensity']
result['zone'] = jb['zone']
end
end
end

local request = http.request('GET', 'https://api.electricitymap.org/v3/power-breakdown/latest?lon=' .. lon .. '&lat=' .. lat)
local request =
http.request('GET', 'https://api.electricitymap.org/v3/power-breakdown/latest?lon=' .. lon .. '&lat=' .. lat)
request:set_header('auth-token', token)
local client = http.client({ timeout = 5 })
local response, err = client:do_request(request)
Expand All @@ -96,15 +98,15 @@ function get_data()
enapter.log('Request returned non-OK code: ' .. response.code, 'error')
return nil, 'wrong_request'
else
local jb = json.decode(response.body)
if jb['error'] then
local jb = json.decode(response.body)
if jb['error'] then
return nil, 'no_data'
else
else
result['powerConsumptionTotal'] = jb['powerConsumptionTotal']
result['powerProductionTotal'] = jb['powerProductionTotal']
result['fossilFreePercentage'] = jb['fossilFreePercentage']
result['renewablePercentage'] = jb['renewablePercentage']
end
end
end

return result, nil
Expand Down

0 comments on commit ce3fb85

Please # to comment.