Skip to content

Commit

Permalink
Merge pull request #1368 from SmartThingsCommunity/beta
Browse files Browse the repository at this point in the history
Production Deployment Beta to Production Default
  • Loading branch information
lelandblue authored May 7, 2024
2 parents 61b14f7 + dad7137 commit f2b91b3
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 68 deletions.
32 changes: 20 additions & 12 deletions drivers/Aqara/aqara-feeder/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ local PRIVATE_CLUSTER_ID = 0xFCC0
local PRIVATE_ATTR_ID = 0xFFF1
local MFG_CODE = 0x115F

local callback_timer = function(driver, device, cmd)
local function reload_portion(device)
local lastPortion = device:get_latest_state("main", capabilities.feederPortion.ID,
capabilities.feederPortion.feedPortion.NAME) or 0
device:emit_event(capabilities.feederPortion.feedPortion({ value = lastPortion, unit = "servings" }))
end
local callback_feed = function(device)
return function()
device:emit_event(capabilities.feederOperatingState.feederOperatingState("idle"))
end
Expand Down Expand Up @@ -64,10 +69,7 @@ end
-- [[ capability_handlers ]]
local function do_refresh(driver, device)
-- refresh
local lastPortion = device:get_latest_state("main", capabilities.feederPortion.ID,
capabilities.feederPortion.feedPortion.NAME) or 0
device:emit_event(capabilities.feederPortion.feedPortion({ value = lastPortion, unit = "servings" },
{ state_change = true }))
reload_portion(device)
do_payload(device, 8, 0, 2001, OP_REPORT, 1, 0)
device:emit_event(capabilities.feederOperatingState.feederOperatingState("idle"))
end
Expand Down Expand Up @@ -104,23 +106,25 @@ local function petFeeder_handler(driver, device, value, zb_rx)
elseif funcID == "14.92.85" then
-- feed portion
device:emit_event(capabilities.feederPortion.feedPortion({ value = conv_data(param), unit = "servings" }))
elseif funcID == "13.104.85" then
local feed_source = device:get_field(FEED_SOURCE)
elseif funcID == "13.104.85" and conv_data(param) ~= 0 then
local feed_source = device:get_field(FEED_SOURCE) or 0
if feed_source == 0 then
device:emit_event(capabilities.feederOperatingState.feederOperatingState("feeding"))
end
device:set_field(FEED_SOURCE, 0, { persist = true })
delete_timer(device)
device:set_field(FEED_TIMER, device.thread:call_with_delay(FEED_TIME, callback_timer(driver, device)))
device:set_field(FEED_TIMER, device.thread:call_with_delay(FEED_TIME, callback_feed(device)))
elseif funcID == "13.11.85" then
-- error
delete_timer(device)
local evt = "idle"
if conv_data(param) == 1 then evt = "error" end
device:emit_event(capabilities.feederOperatingState.feederOperatingState(evt))
end
end

-- [[ lifecycle_handlers ]]
local function device_added(driver, device)
-- private protocol enable
device:send(cluster_base.write_manufacturer_specific_attribute(device,
PRIVATE_CLUSTER_ID, 0x0009, MFG_CODE, data_types.Uint8, 1))
-- init
do_payload(device, 4, 24, 85, OP_WRITE, 1, 0)
device:emit_event(capabilities.feederOperatingState.feederOperatingState("idle"))
device:emit_event(capabilities.feederPortion.feedPortion({ value = 1, unit = "servings" }))
Expand All @@ -143,6 +147,10 @@ local function device_info_changed(driver, device, event, args)
end

local function device_configure(driver, device)
-- private protocol enable
device:send(cluster_base.write_manufacturer_specific_attribute(device,
PRIVATE_CLUSTER_ID, 0x0009, MFG_CODE, data_types.Uint8, 1))
do_payload(device, 4, 24, 85, OP_WRITE, 1, 0)
end

-- [[ Registration ]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ test.register_coroutine_test(
test.socket.zigbee:__set_channel_ordering("relaxed")
test.socket.capability:__set_channel_ordering("relaxed")
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" })
test.socket.zigbee:__expect_send({ mock_device.id,
cluster_base.write_manufacturer_specific_attribute(mock_device, PRIVATE_CLUSTER_ID, 0x0009, MFG_CODE, data_types.Uint8, 1) })
test.socket.zigbee:__expect_send({ mock_device.id, cluster_base.write_manufacturer_specific_attribute(mock_device,
PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID, MFG_CODE, data_types.OctetString, "\x00\x02\x01\x04\x18\x00\x55\x01\x00") })
test.socket.capability:__expect_send(mock_device:generate_test_message("main",
Expand All @@ -69,7 +67,7 @@ test.register_coroutine_test(
function()
test.socket.capability:__queue_receive({ mock_device.id, { capability = "refresh", component = "main", command = "refresh", args = {} } })
test.socket.capability:__expect_send(mock_device:generate_test_message("main",
capabilities.feederPortion.feedPortion({value=0, unit="servings"}, {state_change=true})))
capabilities.feederPortion.feedPortion({value=0, unit="servings"})))
test.socket.zigbee:__expect_send({ mock_device.id, cluster_base.write_manufacturer_specific_attribute(mock_device,
PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID, MFG_CODE, data_types.OctetString, "\x00\x05\x01\x08\x00\x07\xD1\x01\x00") })
test.socket.capability:__expect_send(mock_device:generate_test_message("main",
Expand Down
6 changes: 5 additions & 1 deletion drivers/SmartThings/matter-switch/fingerprints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,11 @@ matterManufacturer:
vendorId: 0x1168
productId: 0x03f8
deviceProfileName: light-color-level-1800K-6500K

- id: "4456/1011"
deviceLabel: Smart Light Bulb A60
vendorId: 0x1168
productId: 0x03F3
deviceProfileName: light-color-level-1800K-6500K
#WiZ
- id: "WiZ A19"
deviceLabel: WiZ A19
Expand Down
42 changes: 42 additions & 0 deletions drivers/SmartThings/philips-hue/src/handlers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,34 @@ local function do_color_action(driver, device, args)
end
end

-- Function to allow changes to "setHue" attribute to Philips Hue light devices
---@param driver HueDriver
---@param device HueChildDevice
local function do_setHue_action(driver, device, args)

-- Use existing 'saturation' value for device or set to 0 and pass arg values to function 'do_color_action'
local currentSaturation = device:get_latest_state("main", capabilities.colorControl.ID, capabilities.colorControl.saturation.NAME, 0)
args.args.color = {
hue = args.args.hue,
saturation = currentSaturation
}
do_color_action(driver, device, args)
end

-- Function to allow changes to "setSaturation" attribute to Philips Hue light devices
---@param driver HueDriver
---@param device HueChildDevice
local function do_setSaturation_action(driver, device, args)

-- Use existing 'hue' value for device or set to 0 and pass arg values to function 'do_color_action'
local currentHue = device:get_latest_state("main", capabilities.colorControl.ID, capabilities.colorControl.hue.NAME, 0)
args.args.color = {
hue = currentHue,
saturation = args.args.saturation
}
do_color_action(driver, device, args)
end

function handlers.kelvin_to_mirek(kelvin) return 1000000 / kelvin end

function handlers.mirek_to_kelvin(mirek) return 1000000 / mirek end
Expand Down Expand Up @@ -248,6 +276,20 @@ function handlers.set_color_temp_handler(driver, device, args)
do_color_temp_action(driver, device, args)
end

---@param driver HueDriver
---@param device HueChildDevice
function handlers.set_hue_handler(driver, device, args)
do_setHue_action(driver, device, args)
end


---@param driver HueDriver
---@param device HueChildDevice
function handlers.set_saturation_handler(driver, device, args)
do_setSaturation_action(driver, device, args)
end


---@param driver HueDriver
---@param light_device HueChildDevice
---@param conn_status_cache table|nil
Expand Down
4 changes: 4 additions & 0 deletions drivers/SmartThings/philips-hue/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ local switch_on_handler = safe_wrap_handler(handlers.switch_on_handler)
local switch_off_handler = safe_wrap_handler(handlers.switch_off_handler)
local switch_level_handler = safe_wrap_handler(handlers.switch_level_handler)
local set_color_handler = safe_wrap_handler(handlers.set_color_handler)
local set_hue_handler = safe_wrap_handler(handlers.set_hue_handler)
local set_saturation_handler = safe_wrap_handler(handlers.set_saturation_handler)
local set_color_temp_handler = safe_wrap_handler(handlers.set_color_temp_handler)

---@param light_device HueChildDevice
Expand Down Expand Up @@ -1509,6 +1511,8 @@ local hue = Driver("hue",
},
[capabilities.colorControl.ID] = {
[capabilities.colorControl.commands.setColor.NAME] = set_color_handler,
[capabilities.colorControl.commands.setHue.NAME] = set_hue_handler,
[capabilities.colorControl.commands.setSaturation.NAME] = set_saturation_handler,
},
[capabilities.colorTemperature.ID] = {
[capabilities.colorTemperature.commands.setColorTemperature.NAME] = set_color_temp_handler,
Expand Down
9 changes: 3 additions & 6 deletions drivers/SmartThings/zigbee-switch/src/aqara-light/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@ local function do_refresh(self, device)
end

local function do_configure(self, device)
device:send(ColorControl.commands.MoveToColorTemperature(device, 200, 0x0000))
device:configure()
do_refresh(self, device)
end

local function device_added(driver, device, event)
device:send(cluster_base.write_manufacturer_specific_attribute(device,
PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID, MFG_CODE, data_types.Uint8, 1)) -- private

device:send(Level.attributes.OnTransitionTime:write(device, 0))
device:send(Level.attributes.OffTransitionTime:write(device, 0))
device:send(ColorControl.commands.MoveToColorTemperature(device, 200, 0x0000))

do_refresh(self, device)
end

local function set_level_handler(driver, device, cmd)
Expand All @@ -56,7 +54,6 @@ end
local aqara_light_handler = {
NAME = "Aqara Light Handler",
lifecycle_handlers = {
added = device_added,
doConfigure = do_configure
},
capability_handlers = {
Expand Down
4 changes: 2 additions & 2 deletions drivers/SmartThings/zigbee-switch/src/aqara/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ local function private_mode_handler(driver, device, value, zb_rx)
device:set_field(PRIVATE_MODE, value.value, { persist = true })

if value.value ~= 1 then
device:send(cluster_base.write_manufacturer_specific_attribute(device,
PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID, MFG_CODE, data_types.Uint8, 0x01)) -- private
device:send(SimpleMetering.attributes.CurrentSummationDelivered:configure_reporting(device, 900, 3600, 1)) -- minimal interval : 15min
device:set_field(constants.ELECTRICAL_MEASUREMENT_DIVISOR_KEY, 10, { persist = true })
device:set_field(constants.SIMPLE_METERING_DIVISOR_KEY, 1000, { persist = true })
Expand Down Expand Up @@ -225,8 +227,6 @@ local function device_added(driver, device)
device:emit_event(capabilities.powerMeter.power({ value = 0.0, unit = "W" }))
device:emit_event(capabilities.energyMeter.energy({ value = 0.0, unit = "Wh" }))

device:send(cluster_base.write_manufacturer_specific_attribute(device,
PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID, MFG_CODE, data_types.Uint8, 0x01)) -- private
end

local aqara_switch_handler = {
Expand Down
14 changes: 3 additions & 11 deletions drivers/SmartThings/zigbee-switch/src/test/test_aqara_led_bulb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ end
test.set_test_init_function(test_init)

test.register_coroutine_test(
"Handle added lifecycle",
"Configure should configure all necessary attributes and refresh device",
function()
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" })
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "doConfigure" })
test.socket.zigbee:__set_channel_ordering("relaxed")

test.socket.zigbee:__expect_send(
{
Expand All @@ -66,15 +67,6 @@ test.register_coroutine_test(
)
test.socket.zigbee:__expect_send({ mock_device.id, Level.attributes.OnTransitionTime:write(mock_device, 0) })
test.socket.zigbee:__expect_send({ mock_device.id, Level.attributes.OffTransitionTime:write(mock_device, 0) })
end
)

test.register_coroutine_test(
"Configure should configure all necessary attributes and refresh device",
function()
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "doConfigure" })
test.socket.zigbee:__set_channel_ordering("relaxed")

test.socket.zigbee:__expect_send(
{
mock_device.id,
Expand Down
14 changes: 3 additions & 11 deletions drivers/SmartThings/zigbee-switch/src/test/test_aqara_light.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ end
test.set_test_init_function(test_init)

test.register_coroutine_test(
"Handle added lifecycle",
"Configure should configure all necessary attributes and refresh device",
function()
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" })
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "doConfigure" })
test.socket.zigbee:__set_channel_ordering("relaxed")

test.socket.zigbee:__expect_send(
{
Expand All @@ -67,15 +68,6 @@ test.register_coroutine_test(
)
test.socket.zigbee:__expect_send({ mock_device.id, Level.attributes.OnTransitionTime:write(mock_device, 0) })
test.socket.zigbee:__expect_send({ mock_device.id, Level.attributes.OffTransitionTime:write(mock_device, 0) })
end
)

test.register_coroutine_test(
"Configure should configure all necessary attributes and refresh device",
function()
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "doConfigure" })
test.socket.zigbee:__set_channel_ordering("relaxed")

test.socket.zigbee:__expect_send(
{
mock_device.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,6 @@ test.register_coroutine_test(
test.socket.capability:__expect_send(
mock_device:generate_test_message("main", capabilities.energyMeter.energy({ value = 0.0, unit = "Wh" }))
)
test.socket.zigbee:__expect_send(
{
mock_device.id,
cluster_base.write_manufacturer_specific_attribute(mock_device, PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID
, MFG_CODE, data_types.Uint8, 1)
}
)
end
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,6 @@ test.register_coroutine_test(
test.socket.capability:__expect_send(
mock_device:generate_test_message("main", capabilities.energyMeter.energy({ value = 0.0, unit = "Wh" }))
)
test.socket.zigbee:__expect_send(
{
mock_device.id,
cluster_base.write_manufacturer_specific_attribute(mock_device, PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID
, MFG_CODE, data_types.Uint8, 1)
}
)
end
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ local AnalogInput = clusters.AnalogInput

local MFG_CODE = 0x115F
local PRIVATE_CLUSTER_ID = 0xFCC0
local PRIVATE_ATTRIBUTE_ID = 0x0009
local RESTORE_POWER_STATE_ATTRIBUTE_ID = 0x0201
local ELECTRIC_SWITCH_TYPE_ATTRIBUTE_ID = 0x000A

Expand Down Expand Up @@ -68,13 +67,6 @@ test.register_coroutine_test(
test.socket.capability:__expect_send(
mock_device:generate_test_message("main", capabilities.energyMeter.energy({ value = 0.0, unit = "Wh" }))
)
test.socket.zigbee:__expect_send(
{
mock_device.id,
cluster_base.write_manufacturer_specific_attribute(mock_device, PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID
, MFG_CODE, data_types.Uint8, 1)
}
)
end
)

Expand Down

0 comments on commit f2b91b3

Please sign in to comment.