Skip to main content

Device API

Handles TV-related operations, such as rebooting, shutting down, and resetting to factory conditions.

device.adbState

Signatures

adbState()

Description

Returns the current ADB connection state for the device as a string.

Possible return values:

  • "device" — ADB is connected and the device is responsive.
  • "unauthorized" — The device is visible over USB/network but has not authorized this host's ADB key. The user needs to accept the RSA key prompt on the device.
  • "offline" — ADB can see the device but it is not responding (common during boot or after a USB-reset glitch).
  • "absent" — ADB cannot find the device at all on the saved port.

This is the branching primitive for CableGuy auto-heal automations: a "device" state means ADB is usable; "absent" paired with a known USB product-id visible in lsusb output means the ADB daemon wedged and maintenance.usbReset() may recover it.

Example

local state = device.adbState()
if state == "device" then
-- ADB is healthy, proceed
elseif state == "absent" then
-- USB present but ADB daemon wedged — try maintenance.usbReset("1949:0588")
end

device.foregroundApp

Signatures

foregroundApp(lua)

Description

Queries the device for the app currently running on it.

Returns a Lua-friendly map with app_id, app_version, and app_name fields. app_version and app_name may be nil if the protocol can't cheaply report them.

If the live query fails (e.g. the platform does not expose the running app), falls back to the app stored in the automation context from launch time. If neither is available, all fields are returned as nil so automations can handle the case gracefully.

local info = device.foregroundApp() print(info.app_id, info.app_version, info.app_name)