Skip to content

Commit

Permalink
0.4.11: Increase accessory limit
Browse files Browse the repository at this point in the history
  • Loading branch information
mhabedinpour committed Jan 2, 2018
1 parent 27f70ac commit e5ac9bd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
4 changes: 2 additions & 2 deletions package.json
@@ -1,12 +1,12 @@
{
"name": "has-node",
"version": "0.4.10",
"version": "0.4.11",
"description": "Homekit Accessory Server",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "npm run build && npm run watch",
"serve": "nodemon --ignore 'samples/*.json' -L samples/fan.js",
"serve": "nodemon --ignore 'samples/*.json' -L samples/bridge.js",
"build": "npm run tslint && npm run build-ts",
"watch": "concurrently -k -p \"[{name}]\" -n \"TypeScript,Node\" -c \"cyan.bold,green.bold\" \"npm run watch-ts\" \"npm run serve\"",
"build-ts": "tsc",
Expand Down
40 changes: 21 additions & 19 deletions samples/bridge.ts
Expand Up @@ -6,7 +6,7 @@

import * as HAS from '../';

const config = new HAS.Config('NodeJS Bridge2', '81:E6:B6:43:BC:2C', HAS.categories.bridge, __dirname + '/bridge.json', 8090, '200-20-200');
const config = new HAS.Config('NodeJS Fan Bridge', '81:E6:B6:43:BC:2D', HAS.categories.bridge, __dirname + '/bridge.json', 8090, '200-20-200');

const server = new HAS.Server(config);

Expand All @@ -29,28 +29,30 @@ server.addAccessory(bridge);
// server.onIdentify will be used only when server is not paired, If server is paired identify.onWrite will be used
server.onIdentify = identify.onWrite;

// Fan
const fan = new HAS.Accessory(2);
for (let i = 2; i <= 150; i++) {
// Fan
const fan = new HAS.Accessory(i);

const fanIdentify = HAS.predefined.Identify(1, undefined, (value, callback) => {
console.log('Fan Identify', value);
callback(HAS.statusCodes.OK);
}),
fanManufacturer = HAS.predefined.Manufacturer(2, 'Hamyar'),
fanModel = HAS.predefined.Model(3, 'Model2017'),
fanName = HAS.predefined.Name(4, 'Fan'),
fanSerialNumber = HAS.predefined.SerialNumber(5, 'ABCDEFGHIJ'),
fanFirmwareVersion = HAS.predefined.FirmwareRevision(6, '1.0.0');
fan.addServices(HAS.predefined.AccessoryInformation(1, [fanIdentify, fanManufacturer, fanModel, fanName, fanSerialNumber, fanFirmwareVersion]));
const fanIdentify = HAS.predefined.Identify(1, undefined, (value, callback) => {
console.log('Fan Identify', i, value);
callback(HAS.statusCodes.OK);
}),
fanManufacturer = HAS.predefined.Manufacturer(2, 'Hamyar'),
fanModel = HAS.predefined.Model(3, 'Model2017'),
fanName = HAS.predefined.Name(4, 'Fan'),
fanSerialNumber = HAS.predefined.SerialNumber(5, 'ABCDEFGHIJ'),
fanFirmwareVersion = HAS.predefined.FirmwareRevision(6, '1.0.0');
fan.addServices(HAS.predefined.AccessoryInformation(1, [fanIdentify, fanManufacturer, fanModel, fanName, fanSerialNumber, fanFirmwareVersion]));


const on = HAS.predefined.On(1, false, (value, callback) => {
console.log('Fan Status', value);
callback(HAS.statusCodes.OK);
});
fan.addServices(HAS.predefined.Fan(2, [on]));
const on = HAS.predefined.On(1, false, (value, callback) => {
console.log('Fan Status', i, value);
callback(HAS.statusCodes.OK);
});
fan.addServices(HAS.predefined.Fan(2, [on]));

server.addAccessory(fan);
server.addAccessory(fan);
}

// Starts the server
server.startServer();
4 changes: 2 additions & 2 deletions src/HAS.ts
Expand Up @@ -213,8 +213,8 @@ export default class HAS {
if (accessoryID < 1 || accessoryID > 999)
throw new Error('Accessory ID can not be less than 1 or more than 999: ' + accessoryID);

if (Object.keys(this.accessories).length >= 100)
throw new Error('Server can not have more than 100 accessories: ' + accessoryID);
if (Object.keys(this.accessories).length >= 150)
throw new Error('Server can not have more than 150 accessories: ' + accessoryID);

if (Object.keys(accessory.getServices()).length <= 0)
throw new Error('Accessory must contain at least one service: ' + accessoryID);
Expand Down

0 comments on commit e5ac9bd

Please sign in to comment.