Zigbee.Interview (zigbee v0.1.0)

Copy Markdown View Source

Orchestrates the join → interview → bind → report flow for a device that has joined the coordinator's network.

It is backend-agnostic: it drives a Zigbee.Adapter through the Zigbee facade and consumes only normalized events, so it works over any radio. The calling process must be the adapter's subscriber (Zigbee.subscribe/2) so {:zigbee, :device_joined, _} and {:zigbee, :message, %Zigbee.Message{}} arrive here.

Typical use:

{:ok, zb} = Zigbee.start_link(Zigbee.EZSP.Adapter, device: "/dev/ttyACM0", speed: 460_800)
{:ok, _} = Zigbee.form_network(zb)   # registers the default HA endpoint too
:ok = Zigbee.subscribe(zb, self())

{:ok, dev} = Zigbee.Interview.open_and_wait(zb)          # press pair on the sensor
{:ok, report} = Zigbee.Interview.run(zb, dev.node_id, dev.eui64)
Zigbee.Interview.collect(zb, 60_000)                     # watch temp/humidity reports

NOTE: the flow is written against the spec but has not yet been exercised against live Zigbee end-devices, so expect to tune Aqara-specific quirks (some devices need a Basic-cluster read after binding before they report).

Summary

Functions

Collect and decode incoming Report Attributes for duration_ms, returning a list of %{cluster, endpoint, attr_id, value, unit} (temperature in °C, humidity in %).

Open the network for joining and block until a device joins, returning %{node_id, eui64} (or {:error, :timeout}).

Interview node_id: enumerate endpoints, read each simple descriptor, then bind + configure reporting for every temperature/humidity cluster found.

Functions

collect(zb, duration_ms \\ 60000)

Collect and decode incoming Report Attributes for duration_ms, returning a list of %{cluster, endpoint, attr_id, value, unit} (temperature in °C, humidity in %).

open_and_wait(zb, duration \\ 180, timeout \\ 180_000)

Open the network for joining and block until a device joins, returning %{node_id, eui64} (or {:error, :timeout}).

run(zb, node_id, device_eui64, opts \\ [])

Interview node_id: enumerate endpoints, read each simple descriptor, then bind + configure reporting for every temperature/humidity cluster found.