Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/KhaosT/master' into random…
Browse files Browse the repository at this point in the history
…-setup-codes

# Conflicts:
#	src/lib/Accessory.ts
#	src/lib/gen/importAsClasses.ts
  • Loading branch information
samuelthomas2774 committed Nov 28, 2019
2 parents b4d95e8 + 6fbafa8 commit 4abd809
Show file tree
Hide file tree
Showing 35 changed files with 4,056 additions and 216 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "hap-nodejs",
"version": "0.5.2",
"version": "0.5.3",
"description": "HAP-NodeJS is a Node.js implementation of HomeKit Accessory Server.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
3 changes: 3 additions & 0 deletions src/accessories/AirConditioner_accessory.ts
Expand Up @@ -6,6 +6,7 @@
import {
Accessory,
AccessoryEventTypes,
Categories,
Characteristic,
CharacteristicEventTypes, CharacteristicGetCallback, CharacteristicSetCallback,
CharacteristicValue,
Expand Down Expand Up @@ -33,6 +34,8 @@ var ACTest = exports.accessory = new Accessory('Air Conditioner', uuid.generate(
ACTest.username = "1A:2B:3C:4D:5E:FF";
// @ts-ignore
ACTest.pincode = "031-45-154";
// @ts-ignore
ACTest.category = Categories.THERMOSTAT;

// set some basic properties (these values are arbitrary and setting them is optional)
ACTest
Expand Down
44 changes: 19 additions & 25 deletions src/accessories/AppleTVRemote_accessory.ts
@@ -1,10 +1,9 @@
import { Accessory, Categories, uuid } from '..';
import { ButtonState, ButtonType, HomeKitRemoteController } from "../lib/HomeKitRemoteController";
import { Accessory, ButtonState, ButtonType, Categories, HomeKitRemoteController, uuid } from '..';
import * as http from "http";
import url, { UrlWithParsedQuery } from "url";
import { GStreamerAudioProducer, GStreamerOptions } from "./gstreamer-audioProducer";

const remoteUUID = uuid.generate('hap-nodejs:accessories:remote');

const remote = exports.accessory = new Accessory('Remote', remoteUUID);

// @ts-ignore
Expand All @@ -13,23 +12,31 @@ remote.username = "DB:AF:E0:5C:69:76";
remote.pincode = "874-23-897";
remote.category = Categories.TARGET_CONTROLLER;

const controller = new HomeKitRemoteController();
// ----------------- for siri support -----------------
// CHANGE this to enable siri support. Read docs in 'gstreamer-audioProducer.ts' for necessary package dependencies
const siriSupport = false;
const gstreamerOptions: Partial<GStreamerOptions> = { // any configuration regarding the producer can be made here
};
// ----------------------------------------------------

const controller = siriSupport
? new HomeKitRemoteController(GStreamerAudioProducer, gstreamerOptions)
: new HomeKitRemoteController();
controller.addServicesToAccessory(remote);

/*
This example plugin exposes an simple http api to interact with the remote and play around.
The supported routes are listed below. The http server runs on port 8080 as default.
This example should not be used except for testing as the http server is unsecured.
/press?button=<buttonId>&time=<timeInMS> - presses a given button for a given time. Time is optional and defaults to 200
/listTargets - list all currently configured apple tvs and their respective configuration
/getActiveTarget - return the current target id of the controlled device
/getActive - get the value of the active characteristic (active means the apple tv for the activeTarget is listening)
/press?button=<buttonId>&time=<timeInMS> - presses a given button for a given time. Time is optional and defaults to 200ms
/button?button=<buttonId>&state=<stateId> - send a single button event
/getTargetId?name=<name of apple TV> - get the target identifier for the given name of the apple tv
/setActiveTarget?identifier=<id> - set currently controlled apple tv
/listTargets - list all currently configured apple tvs and their respective configuration
/getActiveTarget - return the current target id of the controlled device
/getActive - get the value of the active characteristic
/setActive - set the value of the active characteristic (HomeKit seems to set the accessory active itself after configuration)
*/

http.createServer((request, response) => {
Expand Down Expand Up @@ -132,8 +139,7 @@ http.createServer((request, response) => {
return;
}

controller.pushButton(button);
setTimeout(() => controller.releaseButton(button), time);
controller.pushAndReleaseButton(button, time);

response.writeHead(200, {"Content-Type": "text/html"});
response.end("OK");
Expand All @@ -144,21 +150,9 @@ http.createServer((request, response) => {
response.writeHead(200, {"Content-Type": "application/json"});
response.end(JSON.stringify(targets, undefined, 4));
return;
} else if (pathname === "setActive") {
if (query === undefined || query.active === undefined) {
response.writeHead(400, {"Content-Type": "text/html"});
response.end("Bad request. Must include 'active' in query string!");
return;
}

const str = (query.active as string).toLowerCase();
controller.active = str === "true" || str === "1";
response.writeHead(200, {"Content-Type": "text/html"});
response.end("OK");
return;
} else if (pathname === "getActive") {
response.writeHead(200, {"Content-Type": "text/html"});
response.end(controller.active? "true": "false");
response.end(controller.isActive()? "true": "false");
return;
} else {
response.writeHead(404, {"Content-Type": "text/html"});
Expand Down
3 changes: 3 additions & 0 deletions src/accessories/Fan_accessory.ts
Expand Up @@ -2,6 +2,7 @@
import {
Accessory,
AccessoryEventTypes,
Categories,
Characteristic,
CharacteristicEventTypes, CharacteristicSetCallback,
CharacteristicValue,
Expand Down Expand Up @@ -43,6 +44,8 @@ var fan = exports.accessory = new Accessory('Fan', uuid.generate('hap-nodejs:acc
fan.username = "1A:2B:3C:4D:5E:FF";
// @ts-ignore
fan.pincode = "031-45-154";
// @ts-ignore
fan.category = Categories.FAN;

// set some basic properties (these values are arbitrary and setting them is optional)
fan
Expand Down
3 changes: 3 additions & 0 deletions src/accessories/GarageDoorOpener_accessory.ts
@@ -1,6 +1,7 @@
import {
Accessory,
AccessoryEventTypes,
Categories,
Characteristic,
CharacteristicEventTypes, CharacteristicSetCallback, CharacteristicValue,
NodeCallback,
Expand Down Expand Up @@ -40,6 +41,8 @@ var garage = exports.accessory = new Accessory('Garage Door', garageUUID);
garage.username = "C1:5D:3F:EE:5E:FA"; //edit this if you use Core.js
// @ts-ignore
garage.pincode = "031-45-154";
// @ts-ignore
garage.category = Categories.GARAGE_DOOR_OPENER;

garage
.getService(Service.AccessoryInformation)!
Expand Down
3 changes: 3 additions & 0 deletions src/accessories/Light_accessory.ts
@@ -1,6 +1,7 @@
import {
Accessory,
AccessoryEventTypes,
Categories,
Characteristic,
CharacteristicEventTypes, CharacteristicSetCallback,
CharacteristicValue,
Expand Down Expand Up @@ -86,6 +87,8 @@ var lightAccessory = exports.accessory = new Accessory(LightController.name as s
lightAccessory.username = LightController.username;
// @ts-ignore
lightAccessory.pincode = LightController.pincode;
// @ts-ignore
lightAccessory.category = Categories.LIGHTBULB;

// set some basic properties (these values are arbitrary and setting them is optional)
lightAccessory
Expand Down
3 changes: 3 additions & 0 deletions src/accessories/Lock_accessory.ts
@@ -1,6 +1,7 @@
import {
Accessory,
AccessoryEventTypes,
Categories,
Characteristic,
CharacteristicEventTypes, CharacteristicSetCallback,
CharacteristicValue,
Expand Down Expand Up @@ -38,6 +39,8 @@ var lock = exports.accessory = new Accessory('Lock', lockUUID);
lock.username = "C1:5D:3A:EE:5E:FA";
// @ts-ignore
lock.pincode = "031-45-154";
// @ts-ignore
lock.category = Categories.DOOR_LOCK;

// set some basic properties (these values are arbitrary and setting them is optional)
lock
Expand Down
3 changes: 3 additions & 0 deletions src/accessories/MotionSensor_accessory.ts
Expand Up @@ -2,6 +2,7 @@
import {
Accessory,
AccessoryEventTypes,
Categories,
Characteristic,
CharacteristicEventTypes,
CharacteristicValue,
Expand Down Expand Up @@ -35,6 +36,8 @@ var motionSensor = exports.accessory = new Accessory('Motion Sensor', motionSens
motionSensor.username = "1A:2B:3D:4D:2E:AF";
// @ts-ignore
motionSensor.pincode = "031-45-154";
// @ts-ignore
motionSensor.category = Categories.SENSOR;

// set some basic properties (these values are arbitrary and setting them is optional)
motionSensor
Expand Down
3 changes: 3 additions & 0 deletions src/accessories/Outlet_accessory.ts
@@ -1,6 +1,7 @@
import {
Accessory,
AccessoryEventTypes,
Categories,
Characteristic,
CharacteristicEventTypes, CharacteristicSetCallback,
CharacteristicValue, NodeCallback,
Expand Down Expand Up @@ -45,6 +46,8 @@ var outlet = exports.accessory = new Accessory('Outlet', outletUUID);
outlet.username = "1A:2B:3C:4D:5D:FF";
// @ts-ignore
outlet.pincode = "031-45-154";
// @ts-ignore
outlet.category = Categories.OUTLET;

// set some basic properties (these values are arbitrary and setting them is optional)
outlet
Expand Down
4 changes: 3 additions & 1 deletion src/accessories/Sprinkler_accessory.ts
@@ -1,6 +1,7 @@
// here's a fake hardware device that we'll expose to HomeKit
import {
Accessory,
Categories,
Characteristic,
CharacteristicEventTypes,
CharacteristicSetCallback,
Expand Down Expand Up @@ -40,6 +41,8 @@ var sprinkler = exports.accessory = new Accessory('💦 Sprinkler', sprinklerUUI
sprinkler.username = "A3:AB:3D:4D:2E:A3";
// @ts-ignore
sprinkler.pincode = "123-44-567";
// @ts-ignore
sprinkler.category = Categories.SPRINKLER;

// Add the actual Valve Service and listen for change events from iOS.
// We can see the complete list of Services and Characteristics in `lib/gen/HomeKit.ts`
Expand Down Expand Up @@ -173,4 +176,3 @@ sprinkler
function closeVentile() {
// Add your code here
}

3 changes: 3 additions & 0 deletions src/accessories/TV_accessory.ts
@@ -1,5 +1,6 @@
import {
Accessory,
Categories,
Characteristic,
CharacteristicEventTypes,
CharacteristicSetCallback,
Expand All @@ -21,6 +22,8 @@ var tv = exports.accessory = new Accessory('TV', tvUUID);
tv.username = "A3:FB:3D:4D:2E:AC";
// @ts-ignore
tv.pincode = "031-45-154";
// @ts-ignore
tv.category = Categories.TELEVISION;

// Add the actual TV Service and listen for change events from iOS.
// We can see the complete list of Services and Characteristics in `lib/gen/HomeKit.ts`
Expand Down
4 changes: 3 additions & 1 deletion src/accessories/TemperatureSensor_accessory.ts
@@ -1,5 +1,5 @@
// here's a fake temperature sensor device that we'll expose to HomeKit
import { Accessory, Characteristic, CharacteristicEventTypes, CharacteristicValue, NodeCallback, Service, uuid } from '..';
import { Accessory, Categories, Characteristic, CharacteristicEventTypes, CharacteristicValue, NodeCallback, Service, uuid } from '..';

var FAKE_SENSOR = {
currentTemperature: 50,
Expand Down Expand Up @@ -27,6 +27,8 @@ var sensor = exports.accessory = new Accessory('Temperature Sensor', sensorUUID)
sensor.username = "C1:5D:3A:AE:5E:FA";
// @ts-ignore
sensor.pincode = "031-45-154";
// @ts-ignore
sensor.category = Categories.SENSOR;

// Add the actual TemperatureSensor Service.
// We can see the complete list of Services and Characteristics in `lib/gen/HomeKit.ts`
Expand Down
25 changes: 18 additions & 7 deletions src/accessories/Thermostat_accessory.ts
@@ -1,6 +1,6 @@
// HomeKit types required
import * as types from "./types";
import { CharacteristicValue } from '..';
import { Categories, CharacteristicValue } from '..';

const execute = (accessory: string, characteristic: string, value: CharacteristicValue) => {
console.log("executed accessory: " + accessory + ", and characteristic: " + characteristic + ", with value: " + value + ".");
Expand All @@ -10,6 +10,7 @@ export const accessory = {
displayName: "Thermostat 1",
username: "CA:3E:BC:4D:5E:FF",
pincode: "031-45-154",
category: Categories.THERMOSTAT,
services: [{
sType: types.ACCESSORY_INFORMATION_STYPE,
characteristics: [{
Expand Down Expand Up @@ -53,6 +54,16 @@ export const accessory = {
manfDescription: "Bla",
designedMaxLength: 255
},{
cType: types.FIRMWARE_REVISION_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: "1.0.0",
supportEvents: false,
supportBonjour: false,
manfDescription: "Bla",
designedMaxLength: 255
},{
cType: types.IDENTIFY_CTYPE,
onUpdate: null,
perms: ["pw"],
Expand All @@ -79,7 +90,7 @@ export const accessory = {
cType: types.CURRENTHEATINGCOOLING_CTYPE,
onUpdate: (value: CharacteristicValue) => { console.log("Change:",value); execute("Thermostat", "Current HC", value); },
perms: ["pr","ev"],
format: "int",
format: "uint8",
initialValue: 0,
supportEvents: false,
supportBonjour: false,
Expand All @@ -92,7 +103,7 @@ export const accessory = {
cType: types.TARGETHEATINGCOOLING_CTYPE,
onUpdate: (value: CharacteristicValue) => { console.log("Change:",value); execute("Thermostat", "Target HC", value); },
perms: ["pw","pr","ev"],
format: "int",
format: "uint8",
initialValue: 0,
supportEvents: false,
supportBonjour: false,
Expand All @@ -104,7 +115,7 @@ export const accessory = {
cType: types.CURRENT_TEMPERATURE_CTYPE,
onUpdate: (value: CharacteristicValue) => { console.log("Change:",value); execute("Thermostat", "Current Temperature", value); },
perms: ["pr","ev"],
format: "int",
format: "float",
initialValue: 20,
supportEvents: false,
supportBonjour: false,
Expand All @@ -114,7 +125,7 @@ export const accessory = {
cType: types.TARGET_TEMPERATURE_CTYPE,
onUpdate: (value: CharacteristicValue) => { console.log("Change:",value); execute("Thermostat", "Target Temperature", value); },
perms: ["pw","pr","ev"],
format: "int",
format: "float",
initialValue: 20,
supportEvents: false,
supportBonjour: false,
Expand All @@ -126,8 +137,8 @@ export const accessory = {
},{
cType: types.TEMPERATURE_UNITS_CTYPE,
onUpdate: (value: CharacteristicValue) => { console.log("Change:",value); execute("Thermostat", "Unit", value); },
perms: ["pr","ev"],
format: "int",
perms: ["pw","pr","ev"],
format: "uint8",
initialValue: 0,
supportEvents: false,
supportBonjour: false,
Expand Down
26 changes: 26 additions & 0 deletions src/accessories/Wi-FiRouter_accessory.ts
@@ -0,0 +1,26 @@
import {
Accessory,
AccessoryEventTypes,
Categories,
Characteristic,
Service,
uuid,
VoidCallback,
} from '..';

const UUID = uuid.generate('hap-nodejs:accessories:wifi-router');
export const accessory = new Accessory('Wi-Fi Router', UUID);

// @ts-ignore
accessory.username = 'FA:3C:ED:D2:1A:A2';
// @ts-ignore
accessory.pincode = '031-45-154';
// @ts-ignore
accessory.category = Categories.ROUTER;

accessory.on(AccessoryEventTypes.IDENTIFY, (paired: boolean, callback: VoidCallback) => {
console.log("Identify the '%s'", accessory.displayName);
callback();
});

const router = accessory.addService(Service.WiFiRouter);

0 comments on commit 4abd809

Please sign in to comment.