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.
  • "absent" — the device is still on USB but ADB cannot drive it: the adb server lists it as offline, or dropped it while it is still enumerable over USB. maintenance.usbReset() may recover it.
  • "offline" — the device is not on USB at all, or the adb server is unreachable; there is nothing a USB reset could recover.

This is the branching primitive for CableGuy auto-heal automations: a "device" state means ADB is usable; "absent" means the ADB daemon wedged on a still-attached device 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)