1.0.1 • Published 2 years ago

@awarns/battery v1.0.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

@awarns/battery

npm (scoped) npm

This framework module includes a task that allows to access phone's battery level on demand.

Install the plugin using the following command line instruction:

ns plugin add @awarns/battery

Usage

After installing and setting up this plugin, you'll have access to a task that allows to acquire the current phone's battery level and the BatteryLevel record that it will output on demand.

Tasks

Task nameDescription
acquirePhoneBatteryLevelAcquires phone's current battery level

Acquire phone's battery level

To register this task for its use, you just need to import it and call its generator function inside your application's task list:

import { Task } from '@awarns/core/tasks';
import { acquireBatteryLevelTask } from '@awarns/battery';

export const demoTasks: Array<Task> = [
  // ... other tasks
  acquireBatteryLevelTask(),
  // ...
];

Task generator parameters:

The task generator takes no parameters.

Task output events:

Example usage in the application task graph:

on('startEvent', run('acquirePhoneBatteryLevel')
  .every(1, 'minutes')
  .cancelOn('stopEvent'));

on('batteryLevelAcquired', run('writeRecords'))

Note: To use the writeRecords task, the persistence package must be installed and configured. See persistence package docs.

Events

NamePayloadDescription
batteryLevelAcquiredBatteryLevelIndicates that a new battery level snapshot (record) has been acquired

Records

BatteryLevel

PropertyTypeDescription
idstringRecord's unique id
typestringAlways battery-level
changeChangeAlways none. Never starts or ends, always exists
timestampDateThe local time when the battery level was acquired
valuenumberThe battery level. Always an integer. Ranges from 0 to 100

License

Apache License Version 2.0