@@ -17,7 +17,12 @@ local PRIVATE_CLUSTER_ID = 0xFCC0
17
17
local PRIVATE_ATTR_ID = 0xFFF1
18
18
local MFG_CODE = 0x115F
19
19
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 )
21
26
return function ()
22
27
device :emit_event (capabilities .feederOperatingState .feederOperatingState (" idle" ))
23
28
end
64
69
-- [[ capability_handlers ]]
65
70
local function do_refresh (driver , device )
66
71
-- 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 )
71
73
do_payload (device , 8 , 0 , 2001 , OP_REPORT , 1 , 0 )
72
74
device :emit_event (capabilities .feederOperatingState .feederOperatingState (" idle" ))
73
75
end
@@ -104,23 +106,25 @@ local function petFeeder_handler(driver, device, value, zb_rx)
104
106
elseif funcID == " 14.92.85" then
105
107
-- feed portion
106
108
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
109
111
if feed_source == 0 then
110
112
device :emit_event (capabilities .feederOperatingState .feederOperatingState (" feeding" ))
111
113
end
112
114
device :set_field (FEED_SOURCE , 0 , { persist = true })
113
115
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 ))
115
123
end
116
124
end
117
125
118
126
-- [[ lifecycle_handlers ]]
119
127
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
124
128
do_payload (device , 4 , 24 , 85 , OP_WRITE , 1 , 0 )
125
129
device :emit_event (capabilities .feederOperatingState .feederOperatingState (" idle" ))
126
130
device :emit_event (capabilities .feederPortion .feedPortion ({ value = 1 , unit = " servings" }))
@@ -143,6 +147,10 @@ local function device_info_changed(driver, device, event, args)
143
147
end
144
148
145
149
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 )
146
154
end
147
155
148
156
-- [[ Registration ]]
0 commit comments