Skip to main content

General API

Overview

Our API is broken into 6 categories. While this may sound like a lot, each category is small and isolated to a specific task.

  • General API: Found below in this document is a list of helper functions to reduce the boiler plate code you need to write
  • Remote Control API: Allows you to interact with the Remote Control and emit IR, Bluetooth, CEC or WiFi signals to the device under test
  • Vision API: Used to interact with content on the screen through a combination of machine vision and neural networks
  • Testing API: Standard cucumber assertion interface API
  • Keyboard API: API to select a system keyboad or define a custom keyboard built for your app

Find below a list of general methods meant to reduce the boiler plate code you are required to write. Please see the Vision API for interacting with a device.

General

print()

Prints out info to a debug log

SIGNATURE

print(
itemToPrint: String|Number|List
debugLevel: LogLevel = LogLevel.Info
)
returns void

USAGE

print("Hello, world") -- Normally seen unless log level is set to Error
print("Hello, world", LogLevel.Debug) -- Won't be seen unless log level is set to Debug or above

seconds()

DESCRIPTION

As our system is based in ms, this tool helps you by converting seconds into ms for readability.

SIGNATURE

seconds(
timeInSeconds: Number
)
timeInMs: Number

USAGE

wait(seconds(3)) -- equivelant of wait(3_000)

wait()

SIGNATURE

wait(
timeoutInMs: Number
)
returns void

USAGE

print("Executes right away")
wait(500) -- Waits 500ms
print("Executes after 500ms delay")

List / Array Utilities

count()

DESCRIPTION

Alternative to luas built in length

SIGNATURE

count(
list: List
)
returns Number

USAGE

list = {1,2,3}

print(count(list)) -- Prints 3
print(#list) -- Also prints 3

filter()

DESCRIPTION

Returns a list of all matching items

SIGNATURE

filter(
list: <T>[]
matchFn: Function(itemFromList: <T>, index: Number)<Boolean>
)
returns <T>[]

USAGE

numbers = {1, 2, 3, 4, 5 ,6}

-- returns {2, 5}
filter(numbers, function (number, index)
return number == 2 or index == 4
end)

find()

DESCRIPTION

Returns the first matching item in a list

SIGNATURE

find(
list: <T>[]
matchFn: Function(itemFromList: <T>, index: Number)<Boolean>
)
returns <T> | void

USAGE

numbers = {1, 2, 3, 4, 5 ,6}

-- returns 2
filter(numbers, function (number, index)
return number == 2 or index == 4
end)

join()

DESCRIPTION

Combines two lists into a new list

join(
list1: List
list2: List
)
returns List

USAGE

list1 = {1,2,3}
list2 = {3,4,5}

-- returns {1,2,3,3,4,5}
join(list1, list2)

unique()

DESCRIPTION

Takes a list and returns a new list without duplicates

SIGNATURE

unique(
list: List
)
returns List

USAGE

list = {1,1,1,1,2,2,2,2,3,3,3,3,3}

unique(list) -- returns {1,2,3}

Metric

metric.record()

DESCRIPTION

Allows you to upload a result of an action and associate it with a specific KPI for usage in a graph

SIGNATURE

metric.record(
metricKey: String
value: Number
attributes: Map = {}
)
returns void

USAGE

time = Timer.record(function ()
launchApp("Netflix")
end)

metric.record("app_start_time", time, { version: 1 })

Storage / Upload

Functions for interacting with internal TV Labs storage

storage.put()

DESCRIPTION

Puts a new item into storage

SIGNATURE

storage.put(
item: Text|Image|Video
key: ID = generateUUID()
)
returns key

USAGE

frame = screen.capture()

uploadId = storage.put(frame)

print(uploadId) -- to be used to retrieve later

storage.fetch()

DESCRIPTION

Retrieves an item from TV Labs' cloud storage

SIGNATURE

storage.fetch(
storageKey: ID
)

USAGE

-- storage.put(screen.capture(), "explicit_storage_key")

frame = storage.fetch("explicit_storage_key")

Timer

A timer function used for keeping track of time

timer()

DESCRIPTION

Instantiates a new unstarted timer

SIGNATURE

timer()
returns TimerInstance

USAGE

t = timer()

t:start()
wait(seconds(4))
t:stop()

print(timer:elapsed()) -- Outputs 4_000

timer:start()

USAGE

t = timer()

t:start()
wait(seconds(4))
t:stop()

print(t:elapsed()) -- Outputs 4_000

timer:stop()

SIGNATURE

t:stop()
returns Number

USAGE

t = timer()

t:start()
wait(seconds(4))
t:stop() -- Returns 4_000 or the current count

print(t:elapsed()) -- Outputs 4_000

SIGNATURE

t:start()
returns void

USAGE

t = timer()

t:start()
wait(seconds(4))
t:stop()

print(t:elapsed()) -- Outputs 4_000

timer:elapsed()

SIGNATURE

t:elapsed()
returns Number

USAGE

timer = timer()

t:start()
wait(seconds(4))
t:stop()

print(t:elapsed()) -- Outputs 4_000

screen.print()

Prints a text overlay on the recorded video stream.

SIGNATURE

screen.print(
itemToPrint: String|Number|List
)
returns void

USAGE

screen.print("log 1") -- Displays text overlay on recording. Message disappears after 500 ms.
screen.print("log 2") -- Displays a second line of text on the recording, which will disappears after 500 ms.