Skip to content

Commit

Permalink
first jsdoc examples
Browse files Browse the repository at this point in the history
  • Loading branch information
hobbyquaker committed Sep 12, 2019
1 parent 565b5cd commit 9ead960
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
42 changes: 42 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<a name="Controller"></a>

## Controller
<p>Herdsman Controller Class</p>

**Kind**: global class

* [Controller](#Controller)
* [new Controller(options)](#new_Controller_new)
* [.start()](#Controller+start) ⇒ <code>Promise</code>
* ["deviceAnnounce"](#Controller+event_deviceAnnounce)

<a name="new_Controller_new"></a>

### new Controller(options)
<p>Create a controller</p>


| Param | Type | Default |
| --- | --- | --- |
| options | | |
| options.network | <code>Object</code> | |
| [options.network.networkKeyDistribute] | <code>Boolean</code> | <code>false</code> |
| [options.network.networkKey] | <code>Array.&lt;Byte&gt;</code> | |
| [options.network.panID] | <code>uint16</code> | <code>0x1a62</code> |

<a name="Controller+start"></a>

### controller.start() ⇒ <code>Promise</code>
<p>Start the Herdsman controller</p>

**Kind**: instance method of [<code>Controller</code>](#Controller)
<a name="Controller+event_deviceAnnounce"></a>

### "deviceAnnounce"
**Kind**: event emitted by [<code>Controller</code>](#Controller)
**Properties**

| Name | Type |
| --- | --- |
| device | <code>Device</code> |

21 changes: 21 additions & 0 deletions src/controller/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ const debug = {

const OneJanuary2000 = new Date('January 01, 2000 00:00:00').getTime();

/**
* Herdsman Controller Class
*/
class Controller extends events.EventEmitter {
private options: Options;
private database: Database;
Expand All @@ -52,6 +55,15 @@ class Controller extends events.EventEmitter {
// eslint-disable-next-line
private backupTimer: any;

/**
* Create a controller
* @constructs Controller
* @param options
* @param {Object} options.network
* @param {Boolean} [options.network.networkKeyDistribute=false]
* @param {Byte[]} [options.network.networkKey]
* @param {uint16} [options.network.panID=0x1a62]
*/
public constructor(options: Options) {
super();
this.options = mixin(DefaultOptions, options);
Expand All @@ -71,6 +83,10 @@ class Controller extends events.EventEmitter {
}
}

/**
* Start the Herdsman controller
* @returns {Promise}
*/
public async start(): Promise<void> {
debug.log(`Starting with options '${JSON.stringify(this.options)}'`);
this.database = await Database.open(this.options.databasePath);
Expand Down Expand Up @@ -189,6 +205,11 @@ class Controller extends events.EventEmitter {
private async onDeviceAnnounce(payload: AdapterEvents.DeviceAnnouncePayload): Promise<void> {
debug.log(`Device announce '${payload.ieeeAddr}'`);
const data: Events.DeviceAnnouncePayload = {device: await Device.findSingle({ieeeAddr: payload.ieeeAddr})};
/**
* @event Controller#deviceAnnounce
* @type Object
* @property {Device} device
*/
this.emit(Events.Events.deviceAnnounce, data);
}

Expand Down

0 comments on commit 9ead960

Please sign in to comment.