[ST Edge] How can device's metadata, provided in try_create_device be retrieved?

Hi,

When creating devices with driver:try_create_device call, there are manufacturer and model fields are provided.
How can those fields can be accessed when the device is created, for example from device’s init function?
For zigbee devices, there are device:get_model() and device:get_manufacturer(), which allow to implement can handle for sub drivers.
It seems get_model and get_manufacturer are not available for LAN devices.
Are there any alternatives?

Thanks

Hey, @ygerlovin

You can call the device.device_api.get_device_info API and then parse the JSON string into a table with the dkjson module, e.g.:

local json = require 'dkjson'

local function device_init(driver, device)
  ...

  local str_json = device.device_api.get_device_info(device.id)
  local device_info = json.decode(str_json)
  --[[
  {
    data={},
    device_network_id="...",
    driver={
      id="...",
      name="...",
      type="LAN"},
    execution_environment="HUBCORE",
    id="...",
    label="...",
    manufacturer="...",
    model="...",
    network_type="DEVICE_LAN",
    parent_device_id="...",
    preferences={},
    profile={...},
    vendor_provided_label="..."
  }
  --]]
end
1 Like

That’s very useful, thanks @erickv .

I noticed that json output contains model. That’s interesting, because if I try to print device as a table, I don’t see that field.
It is probably hidden in index metatable.

However, it seems that simple device.model works fine. The only problem with this solution is that I’m not sure, whether I’m allowed to use this undocumented field, as it might be removed in the future versions.
Thanks

1 Like

This is great feedback!

I’ll be sharing this finding with our engineers to improve the consistency of logging outputs.

2 Likes