Skip to content

Commit ae1ea7d

Browse files
authored
Merge pull request #1337 from seojune79/Aqara-Smart-Pet-Feeder-C1
[Aqara/Smart Pet Feeder] add new event and fix issues
2 parents a55e393 + 9942b52 commit ae1ea7d

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

drivers/Aqara/aqara-feeder/src/init.lua

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ local PRIVATE_CLUSTER_ID = 0xFCC0
1717
local PRIVATE_ATTR_ID = 0xFFF1
1818
local MFG_CODE = 0x115F
1919

20-
local callback_timer = function(driver, device, cmd)
20+
local function reload_portion(device)
21+
local lastPortion = device:get_latest_state("main", capabilities.feederPortion.ID,
22+
capabilities.feederPortion.feedPortion.NAME) or 0
23+
device:emit_event(capabilities.feederPortion.feedPortion({ value = lastPortion, unit = "servings" }))
24+
end
25+
local callback_feed = function(device)
2126
return function()
2227
device:emit_event(capabilities.feederOperatingState.feederOperatingState("idle"))
2328
end
@@ -64,10 +69,7 @@ end
6469
-- [[ capability_handlers ]]
6570
local function do_refresh(driver, device)
6671
-- refresh
67-
local lastPortion = device:get_latest_state("main", capabilities.feederPortion.ID,
68-
capabilities.feederPortion.feedPortion.NAME) or 0
69-
device:emit_event(capabilities.feederPortion.feedPortion({ value = lastPortion, unit = "servings" },
70-
{ state_change = true }))
72+
reload_portion(device)
7173
do_payload(device, 8, 0, 2001, OP_REPORT, 1, 0)
7274
device:emit_event(capabilities.feederOperatingState.feederOperatingState("idle"))
7375
end
@@ -104,23 +106,25 @@ local function petFeeder_handler(driver, device, value, zb_rx)
104106
elseif funcID == "14.92.85" then
105107
-- feed portion
106108
device:emit_event(capabilities.feederPortion.feedPortion({ value = conv_data(param), unit = "servings" }))
107-
elseif funcID == "13.104.85" then
108-
local feed_source = device:get_field(FEED_SOURCE)
109+
elseif funcID == "13.104.85" and conv_data(param) ~= 0 then
110+
local feed_source = device:get_field(FEED_SOURCE) or 0
109111
if feed_source == 0 then
110112
device:emit_event(capabilities.feederOperatingState.feederOperatingState("feeding"))
111113
end
112114
device:set_field(FEED_SOURCE, 0, { persist = true })
113115
delete_timer(device)
114-
device:set_field(FEED_TIMER, device.thread:call_with_delay(FEED_TIME, callback_timer(driver, device)))
116+
device:set_field(FEED_TIMER, device.thread:call_with_delay(FEED_TIME, callback_feed(device)))
117+
elseif funcID == "13.11.85" then
118+
-- error
119+
delete_timer(device)
120+
local evt = "idle"
121+
if conv_data(param) == 1 then evt = "error" end
122+
device:emit_event(capabilities.feederOperatingState.feederOperatingState(evt))
115123
end
116124
end
117125

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

145149
local function device_configure(driver, device)
150+
-- private protocol enable
151+
device:send(cluster_base.write_manufacturer_specific_attribute(device,
152+
PRIVATE_CLUSTER_ID, 0x0009, MFG_CODE, data_types.Uint8, 1))
153+
do_payload(device, 4, 24, 85, OP_WRITE, 1, 0)
146154
end
147155

148156
-- [[ Registration ]]

drivers/Aqara/aqara-feeder/src/test/test_aqara_pet_feeder.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ test.register_coroutine_test(
5151
test.socket.zigbee:__set_channel_ordering("relaxed")
5252
test.socket.capability:__set_channel_ordering("relaxed")
5353
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" })
54-
test.socket.zigbee:__expect_send({ mock_device.id,
55-
cluster_base.write_manufacturer_specific_attribute(mock_device, PRIVATE_CLUSTER_ID, 0x0009, MFG_CODE, data_types.Uint8, 1) })
5654
test.socket.zigbee:__expect_send({ mock_device.id, cluster_base.write_manufacturer_specific_attribute(mock_device,
5755
PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID, MFG_CODE, data_types.OctetString, "\x00\x02\x01\x04\x18\x00\x55\x01\x00") })
5856
test.socket.capability:__expect_send(mock_device:generate_test_message("main",
@@ -69,7 +67,7 @@ test.register_coroutine_test(
6967
function()
7068
test.socket.capability:__queue_receive({ mock_device.id, { capability = "refresh", component = "main", command = "refresh", args = {} } })
7169
test.socket.capability:__expect_send(mock_device:generate_test_message("main",
72-
capabilities.feederPortion.feedPortion({value=0, unit="servings"}, {state_change=true})))
70+
capabilities.feederPortion.feedPortion({value=0, unit="servings"})))
7371
test.socket.zigbee:__expect_send({ mock_device.id, cluster_base.write_manufacturer_specific_attribute(mock_device,
7472
PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID, MFG_CODE, data_types.OctetString, "\x00\x05\x01\x08\x00\x07\xD1\x01\x00") })
7573
test.socket.capability:__expect_send(mock_device:generate_test_message("main",

0 commit comments

Comments
 (0)