homebridge-smartsystem
Version: 
SmartServer (Proxy TCP sockets to the cloud, Smappee MQTT, Duotecno IP Nodes, Homekit interface)
55 lines (40 loc) • 2.13 kB
text/typescript
import { Platform } from "./server/platform";
import { Unit, Node } from "./duotecno/protocol";
import { Sanitizers } from "./duotecno/types";
import { debug, log, LogLevel, logSettings, setLogFunction } from "./duotecno/logger";
import { Master } from "./duotecno/master";
import { API } from "homebridge";
import * as fs from "fs";
import * as os from "os";
setLogFunction(console.log);
logSettings["spec"] = LogLevel.log;
const osType = os.platform();
log("spec", "running in directory: " + process.cwd() + " on " + osType);
const isMac = (osType === "darwin");
const kConfigFiles = (isMac) ? (__dirname) : (os.homedir() + "/duotecno");
if (! fs.existsSync(kConfigFiles)) fs.mkdirSync(kConfigFiles);
function adder(plugin: string, platform: string, list: any[]) {
  log("spec", "************* plugin: " + plugin + ", platform: " + platform);
  log("spec", "************* list: " + JSON.stringify(list));
}
try {
  const fn = kConfigFiles + "/config.json";
  log("spec", "Reading config from " + fn);
  const configBuf = fs.readFileSync(fn);
  const configStr = configBuf.toString();
  const config = JSON.parse(configStr);
  debug("spec", config);
  config.debug = true;
  const platform = new Platform(console as any, config, <API>{registerPlatformAccessories: adder});
} catch(err) {
  log("spec", err);
}
// function tester() {
//   // testing
//   let m = new Master(platform.system, Sanitizers.masterConfig({name: "master1", address: "12", port: 21, password:"x", active: true, nodenames: {}}));
//   let n = new Node(m, Sanitizers.nodeInfo({name: "node1"}));
//   let u = new Unit(n, Sanitizers.unitInfo({name: "unit|123 $", type: 7}));
//   log("spec", "Testing names -> getName = " + u.getName() + ", getDisplayname = " + u.getDisplayName() + ", type " + u.type + ", extType = " + u.extendedType + ", getTypeName = " + u.typeName());
//   u = new Unit(n, Sanitizers.unitInfo({name: "unit|20", type: 1}));
//   log("spec", "Testing names -> getName = " + u.getName() + ", getDisplayname = " + u.getDisplayName() + ", type " + u.type + ", extType = " + u.extendedType + ", getTypeName = " + u.typeName());
// }