Skip to content

Commit

Permalink
Merge pull request #1337 from seojune79/Aqara-Smart-Pet-Feeder-C1
Browse files Browse the repository at this point in the history
[Aqara/Smart Pet Feeder] add new event and fix issues
  • Loading branch information
lelandblue authored Apr 29, 2024
2 parents a55e393 + 9942b52 commit ae1ea7d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 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

0 comments on commit ae1ea7d

Please sign in to comment.