Skip to content

Commit

Permalink
2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-j-davies committed Aug 1, 2021
1 parent 93e4cea commit 966176e
Show file tree
Hide file tree
Showing 15 changed files with 251 additions and 262 deletions.
35 changes: 16 additions & 19 deletions @marcus-j-davies/haprouter-route-console/index.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
'use strict'
'use strict';

/* UI Params */
const Params = [
]
const Params = [];

/* Metadata */
const Name = "Console Output";
const Icon = "icon.png";
const Name = 'Console Output';
const Icon = 'icon.png';

/* Route Class */
class ConsoleClass {

/* Constructor */
constructor(route, statusnotify) {
statusnotify(true)
}
/* Constructor */
constructor(route, statusnotify) {
statusnotify(true);
}
}

ConsoleClass.prototype.process = async function (payload) {
console.log(payload)
}
console.log(payload);
};

ConsoleClass.prototype.close = function (reason) {
}
ConsoleClass.prototype.close = function (reason) {};

module.exports = {
"Route": ConsoleClass,
"Inputs": Params,
"Name": Name,
"Icon": Icon
}
Route: ConsoleClass,
Inputs: Params,
Name: Name,
Icon: Icon
};
2 changes: 1 addition & 1 deletion @marcus-j-davies/haprouter-route-console/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@marcus-j-davies/haprouter-route-console",
"description": "The stock HAP Router CONSOLE route",
"version": "2.0.0",
"version": "3.0.0",
"main": "index.js",
"author": {
"name": "Marcus Davies",
Expand Down
89 changes: 43 additions & 46 deletions @marcus-j-davies/haprouter-route-file/index.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,62 @@
'use strict'
const path = require("path");
const fs = require("fs");
'use strict';
const path = require('path');
const fs = require('fs');

/* UI Params */
const Params = [
{
id: "directory",
label: "Storage Location/Directoy"
}
]
{
id: 'directory',
label: 'Storage Location/Directoy'
}
];

/* Metadata */
const Name = "File Output";
const Icon = "icon.png";
const Name = 'File Output';
const Icon = 'icon.png';

/* Route Class */
class File {

/* Constructor */
constructor(route, statusnotify) {
this.Route = route;
statusnotify(true)
}

/* Constructor */
constructor(route, statusnotify) {
this.Route = route;
statusnotify(true);
}
}

File.prototype.process = async function (payload) {
const JSONs = JSON.stringify(payload);

let JSONs = JSON.stringify(payload);
const Directory = this.Route.directory.replace(
'{{AccessoryID}}',
payload.accessory.AccessoryID
);

let Directory = this.Route.directory.replace("{{AccessoryID}}", payload.accessory.AccessoryID)
if (!fs.existsSync(Directory)) {
try {
fs.mkdirSync(Directory, { recursive: true });
} catch (err) {
console.log(' FILE Route error: ' + err);
return;
}
}

if (!fs.existsSync(Directory)) {
try {
fs.mkdirSync(Directory, { recursive: true });
}
catch (err) {
console.log(" FILE Route error: "+err)
return;
}
}
const DT = new Date().getTime();
const FileName = DT + '_' + payload.accessory.AccessoryID + '.json';

let DT = new Date().getTime();
let FileName = DT + '_' + payload.accessory.AccessoryID + ".json"
const _Path = path.join(Directory, FileName);

let _Path = path.join(Directory, FileName);
try {
fs.writeFileSync(_Path, JSONs, 'utf8');
} catch (err) {
console.log(' FILE Route error: ' + err);
}
};

try {
fs.writeFileSync(_Path, JSONs, 'utf8')
}
catch (err) {
console.log(" FILE Route error: "+err)
}
}

File.prototype.close = function (reason) {
}
File.prototype.close = function (reason) {};

module.exports = {
"Route": File,
"Inputs": Params,
"Name": Name,
"Icon": Icon
}
Route: File,
Inputs: Params,
Name: Name,
Icon: Icon
};
2 changes: 1 addition & 1 deletion @marcus-j-davies/haprouter-route-file/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@marcus-j-davies/haprouter-route-file",
"description": "The stock HAP Router FILE route",
"version": "2.0.0",
"version": "3.0.0",
"main": "index.js",
"author": {
"name": "Marcus Davies",
Expand Down
82 changes: 40 additions & 42 deletions @marcus-j-davies/haprouter-route-http/index.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,53 @@
'use strict'
const axios = require('axios')
'use strict';
const axios = require('axios');

/* UI Params */
const Params = [
{
id: "destinationURI",
label: "HTTP URI"
}
]
{
id: 'destinationURI',
label: 'HTTP URI'
}
];

/* Metadata */
const Name = "HTTP POST Output";
const Icon = "icon.png";
const Name = 'HTTP POST Output';
const Icon = 'icon.png';

/* Route Class */
class HTTPRoute {

/* Constructor */
constructor(route, statusnotify) {
this.Route = route
statusnotify(true)
}
/* Constructor */
constructor(route, statusnotify) {
this.Route = route;
statusnotify(true);
}
}

HTTPRoute.prototype.process = async function (payload) {

let CFG = {
headers: {
'Content-Type': 'application/json',
'User-Agent': 'HAP Router'
},
method: 'post',
url: this.Route.destinationURI.replace('{{AccessoryID}}', payload.accessory.AccessoryID),
data: payload
}

try{
let Res = await axios.request(CFG)
}
catch(err){
console.log(" HTTP Route error: "+err)
}

}

HTTPRoute.prototype.close = function (reason) {
}
const CFG = {
headers: {
'Content-Type': 'application/json',
'User-Agent': 'HAP Router'
},
method: 'post',
url: this.Route.destinationURI.replace(
'{{AccessoryID}}',
payload.accessory.AccessoryID
),
data: payload
};

try {
await axios.request(CFG);
} catch (err) {
console.log(' HTTP Route error: ' + err);
}
};

HTTPRoute.prototype.close = function (reason) {};

module.exports = {
"Route": HTTPRoute,
"Inputs": Params,
"Name": Name,
"Icon": Icon
}
Route: HTTPRoute,
Inputs: Params,
Name: Name,
Icon: Icon
};
2 changes: 1 addition & 1 deletion @marcus-j-davies/haprouter-route-http/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@marcus-j-davies/haprouter-route-http",
"description": "The stock HAP Router HTTP route",
"version": "2.0.0",
"version": "3.0.0",
"main": "index.js",
"author": {
"name": "Marcus Davies",
Expand Down
Loading

0 comments on commit 966176e

Please sign in to comment.