Skip to content

Commit

Permalink
Merge pull request #1264 from SmartThingsCommunity/main
Browse files Browse the repository at this point in the history
  • Loading branch information
dljsjr authored Mar 7, 2024
2 parents c348d5c + 0b18e67 commit 6faa03b
Show file tree
Hide file tree
Showing 32 changed files with 1,225 additions and 31 deletions.
43 changes: 39 additions & 4 deletions drivers/SmartThings/jbl/src/lunchbox/rest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ local function connect(client)
port = 443
use_ssl = true
end


if client.base_url.port ~= port then port = client.base_url.port end
local sock, err = client.socket_builder(client.base_url.host, port, use_ssl)

if sock == nil then
Expand Down Expand Up @@ -143,6 +144,38 @@ local function parse_chunked_response(original_response, sock)
return full_response
end

local function recv_additional_response(original_response, sock)
local full_response = Response.new(original_response.status, nil)
local headers = original_response:get_headers()
local content_length_str = headers:get_one("Content-Length")
local content_length = nil
local bytes_read = 0
if content_length_str then
content_length = math.tointeger(content_length_str)
end

local next_recv, next_err, partial

repeat
next_recv, next_err, partial = sock:receive(content_length - bytes_read)

if next_recv ~= nil and #next_recv >= 1 then
full_response:append_body(next_recv)
bytes_read = bytes_read + #next_recv
end

if partial ~= nil and #partial >= 1 then
full_response:append_body(partial)
bytes_read = bytes_read + #partial
end
until next_err == "closed" or bytes_read >= content_length

full_response._received_body = true
full_response._parsed_headers = true

return full_response
end

local function handle_response(sock)
if api_version >= 9 then
local response, err = Response.tcp_source(sock)
Expand All @@ -157,7 +190,9 @@ local function handle_response(sock)
if initial_recv ~= nil then
local headers = initial_recv:get_headers()

if headers and headers:get_one("Transfer-Encoding") == "chunked" then
if headers:get_one("Content-Length") then
full_response = recv_additional_response(initial_recv, sock)
elseif headers and headers:get_one("Transfer-Encoding") == "chunked" then
local response, err = parse_chunked_response(initial_recv, sock)
if err ~= nil then
return nil, err
Expand Down Expand Up @@ -267,15 +302,15 @@ RestClient.__index = RestClient

function RestClient.one_shot_get(full_url, additional_headers, socket_builder)
local url_table = lb_utils.force_url_table(full_url)
local client = RestClient.new(url_table.scheme .. "://" .. url_table.host, socket_builder)
local client = RestClient.new(url_table.scheme .. "://" .. url_table.authority, socket_builder)
local ret, err = client:get(url_table.path, additional_headers)
client:shutdown()
return ret, err
end

function RestClient.one_shot_post(full_url, body, additional_headers, socket_builder)
local url_table = lb_utils.force_url_table(full_url)
local client = RestClient.new(url_table.scheme .. "://" .. url_table.host, socket_builder)
local client = RestClient.new(url_table.scheme .. "://" .. url_table.authority, socket_builder)
local ret, err = client:post(url_table.path, body, additional_headers)
client:shutdown()
return ret, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ test.register_coroutine_test(
test.socket.zigbee:__expect_send({
mock_device.id,
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(
mock_device, 30, 300, 16
mock_device, 30, 600, 100
)
})
test.socket.zigbee:__expect_send({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ test.register_coroutine_test(
})
test.socket.zigbee:__expect_send({
mock_device.id,
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(mock_device, 30, 300, 16)
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(mock_device, 30, 600, 100)
})
test.socket.zigbee:__expect_send({
mock_device.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ test.register_coroutine_test(
})
test.socket.zigbee:__expect_send({
mock_device.id,
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(mock_device, 30, 300, 16)
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(mock_device, 30, 600, 100)
})
test.socket.zigbee:__expect_send({
mock_device.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ test.register_coroutine_test(
})
test.socket.zigbee:__expect_send({
mock_device.id,
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(mock_device, 30, 300, 16)
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(mock_device, 30, 600, 100)
})
test.socket.zigbee:__expect_send({
mock_device.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ test.register_coroutine_test(
mock_device.id,
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(mock_device,
30,
300,
0x10)
600,
100)
}
)
test.socket.zigbee:__expect_send(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ test.register_coroutine_test(
})
test.socket.zigbee:__expect_send({
mock_device.id,
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(mock_device, 30, 300, 16)
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(mock_device, 30, 600, 100)
})
test.socket.zigbee:__expect_send({
mock_device.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ test.register_coroutine_test(
})
test.socket.zigbee:__expect_send({
mock_device.id,
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(mock_device, 30, 300, 16)
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(mock_device, 30, 600, 100)
})
test.socket.zigbee:__expect_send({ mock_device.id, RelativeHumidity.attributes.MeasuredValue:read(mock_device):to_endpoint(0x02) })
test.socket.zigbee:__expect_send({ mock_device.id, TemperatureMeasurement.attributes.MeasuredValue:read(mock_device) })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ test.register_coroutine_test(
})
test.socket.zigbee:__expect_send({
mock_device.id,
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(mock_device, 30, 300, 0x10)
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(mock_device, 30, 600, 100)
})
test.socket.zigbee:__expect_send({
mock_device.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ test.register_coroutine_test(
})
test.socket.zigbee:__expect_send({
mock_device.id,
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(mock_device, 30, 300, 0x10)
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(mock_device, 30, 600, 100)
})
test.socket.zigbee:__expect_send({
mock_device.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ test.register_coroutine_test(
})
test.socket.zigbee:__expect_send({
mock_device.id,
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(mock_device, 30, 300, 0x10)
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(mock_device, 30, 600, 100)
})
test.socket.zigbee:__expect_send({
mock_device.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ test.register_coroutine_test(
})
test.socket.zigbee:__expect_send({
mock_device.id,
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(mock_device, 30, 300, 16)
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(mock_device, 30, 600, 100)
})
test.socket.zigbee:__expect_send({
mock_device.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ test.register_coroutine_test(
})
test.socket.zigbee:__expect_send({
mock_device.id,
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(mock_device, 30, 300, 16)
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(mock_device, 30, 600, 100)
})
test.socket.zigbee:__expect_send({
mock_device.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ test.register_coroutine_test(
})
test.socket.zigbee:__expect_send({
mock_device.id,
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(mock_device, 30, 300, 16)
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(mock_device, 30, 600, 100)
})
test.socket.zigbee:__expect_send({
mock_device.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ test.register_coroutine_test(
})
test.socket.zigbee:__expect_send({
mock_device.id,
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(mock_device, 30, 300, 0x10)
TemperatureMeasurement.attributes.MeasuredValue:configure_reporting(mock_device, 30, 600, 100)
})
test.socket.zigbee:__expect_send({
mock_device.id,
Expand Down
5 changes: 5 additions & 0 deletions drivers/SmartThings/zigbee-switch/fingerprints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ zigbeeManufacturer:
manufacturer: LUMI
model: lumi.light.acn004
deviceProfileName: aqara-light
- id: "Aqara/lumi.light.acn014"
deviceLabel: Aqara LED Light Bulb T1 (Tunable White)
manufacturer: Aqara
model: lumi.light.acn014
deviceProfileName: aqara-led-bulb
# VIMAR
- id: "Vimar/xx592-2-way-smart-switch"
deviceLabel: Vimar 2-way Smart Switch
Expand Down
27 changes: 27 additions & 0 deletions drivers/SmartThings/zigbee-switch/profiles/aqara-led-bulb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: aqara-led-bulb
components:
- id: main
capabilities:
- id: switch
version: 1
- id: switchLevel
version: 1
config:
values:
- key: "level.value"
range: [1, 100]
- id: colorTemperature
version: 1
config:
values:
- key: "colorTemperature.value"
range: [2700, 6500]
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: Light
preferences:
- preferenceId: stse.restorePowerState
explicit: true
16 changes: 15 additions & 1 deletion drivers/SmartThings/zigbee-switch/src/aqara-light/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local clusters = require "st.zigbee.zcl.clusters"
local cluster_base = require "st.zigbee.cluster_base"
local data_types = require "st.zigbee.data_types"
local capabilities = require "st.capabilities"

local OnOff = clusters.OnOff
local Level = clusters.Level
Expand All @@ -11,7 +12,8 @@ local PRIVATE_ATTRIBUTE_ID = 0x0009
local MFG_CODE = 0x115F

local FINGERPRINTS = {
{ mfr = "LUMI", model = "lumi.light.acn004" }
{ mfr = "LUMI", model = "lumi.light.acn004" },
{ mfr = "Aqara", model = "lumi.light.acn014" }
}

local function is_aqara_products(opts, driver, device)
Expand Down Expand Up @@ -43,12 +45,24 @@ local function device_added(driver, device, event)
device:send(Level.attributes.OffTransitionTime:write(device, 0))
end

local function set_level_handler(driver, device, cmd)
local level = math.floor(cmd.args.level / 100.0 * 254)
local dimming_rate = 0x0000

device:send(Level.commands.MoveToLevelWithOnOff(device, level, dimming_rate))
end

local aqara_light_handler = {
NAME = "Aqara Light Handler",
lifecycle_handlers = {
added = device_added,
doConfigure = do_configure
},
capability_handlers = {
[capabilities.switchLevel.ID] = {
[capabilities.switchLevel.commands.setLevel.NAME] = set_level_handler
}
},
can_handle = is_aqara_products
}

Expand Down
9 changes: 9 additions & 0 deletions drivers/SmartThings/zigbee-switch/src/preferences.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ local devices = {
return clusters.Level.attributes.OffTransitionTime:write(device, raw_value)
end
}
},
AQARA_LIGHT_BULB = {
MATCHING_MATRIX = { mfr = "Aqara", model = "lumi.light.acn014" },
PARAMETERS = {
["stse.restorePowerState"] = function(device, value)
return cluster_base.write_manufacturer_specific_attribute(device, 0xFCC0,
0x0201, 0x115F, data_types.Boolean, value)
end
}
}
}
local preferences = {}
Expand Down
Loading

0 comments on commit 6faa03b

Please sign in to comment.