I don’t feel proud about myself but yeah, the following code did the trick… now it is keeping track of the statuses of all 5 endpoints by default, not only the first 4:
local utils = require('st.utils')
local json = require("dkjson")
local lifecycle_handler = {}
function lifecycle_handler.init(driver, device, event, args)
local device_cloud = json.decode(driver.device_api.get_device_info(device.id))
device_cloud.zigbee_endpoints = utils.merge({
["5"] = utils.merge({
id = 5
}, device_cloud.zigbee_endpoints["2"])
}, device_cloud.zigbee_endpoints)
device:load_updated_data(device_cloud)
}
return lifecycle_handler
Basically, the logic here is to copy the 2º endpoint (it could be any from 2 to 4) and place it in the 5º position of zigbee_endpoints
.
Now, my endpoints are these (the bold one was included by the code above):
{
1={
client_clusters={
1=25,
2=10,
},
device_id=266,
id=1,
manufacturer="_TZ3000_o005nuxx",
model="TS011F",
profile_id=260,
server_clusters={
1=0,
2=3,
3=4,
4=5,
5=6,
6=57344,
7=57345,
},
},
2={
client_clusters={},
device_id=266,
id=2,
profile_id=260,
server_clusters={
1=3,
2=4,
3=5,
4=6,
5=57344,
6=57345,
},
},
3={
client_clusters={},
device_id=266,
id=3,
profile_id=260,
server_clusters={
1=3,
2=4,
3=5,
4=6,
5=57344,
6=57345,
},
},
4={
client_clusters={},
device_id=266,
id=4,
profile_id=260,
server_clusters={
1=3,
2=4,
3=5,
4=6,
5=57344,
6=57345,
},
},
5={
client_clusters={},
device_id=266,
id=5,
profile_id=260,
server_clusters={
1=3,
2=4,
3=5,
4=6,
5=57344,
6=57345,
},
},
}
I am still testing what is the best lifecycle handler to invoke this code.
This code doesn’t update endpoints in the cloud, just locally in the hub.
In other words, every time your code (or elsewhere in the native code) call get_device_info(device_id)
, it will receive the original 4 endpoints.
I won’t mark this post as the solution because I think there could be a cleaner/official way to update endpoints.
References:
st.Device.load_updated_data
st.utils.merge
Part XIII: Appendices - D. Custom Endpoints