Skip to content

Commit

Permalink
pin fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ansgar Schulte committed Aug 21, 2018
1 parent 84c767d commit 90740d3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
20 changes: 10 additions & 10 deletions heytech/service/heytech.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import {Telnet} from 'telnet-rxjs';
import config from 'config';

const newLine = String.fromCharCode(13);
const serverConfig = config.get('Heytech.lan');

const doTelNetStuff = (telnetCommands) => {
const serverConfig = config.get('Heytech.lan');


const client = Telnet.client(serverConfig.host + ':' + serverConfig.port);
let connected = false;
Expand All @@ -18,11 +19,12 @@ const doTelNetStuff = (telnetCommands) => {
});
client.connect();
};
let doCommandForFenster = function (client, fenster, commandStr) {
if(!_.isEmpty(serverConfig.pin)){
let doCommandForFenster = function (client, fenster, commandStr, pin) {
if(!_.isEmpty(pin)){
console.log('with pin')
client.send('rsc');
client.send(newLine);
client.send(serverConfig.pin);
client.send(pin);
client.send(newLine);
client.send(newLine);
}
Expand All @@ -36,33 +38,31 @@ let doCommandForFenster = function (client, fenster, commandStr) {
client.send(commandStr === 'stop' ? 'off' : commandStr);
client.send(newLine);
client.send(newLine);
client.send('rhe');
client.send(newLine);
};
export const rollershutter = (fenster, commandStr) => {
doTelNetStuff((client) => {
doCommandForFenster(client, fenster, commandStr);
doCommandForFenster(client, fenster, commandStr, serverConfig.pin);
});
};

export const rollershutters = (fensters, commandStr) => {
doTelNetStuff((client) => {
fensters.forEach(fenster => {
doCommandForFenster(client, fenster, commandStr);
doCommandForFenster(client, fenster, commandStr, serverConfig.pin);
});
});
};

export const rollershuttersWithTimeout = (fensters, downTime, commandStr) => {
doTelNetStuff((client) => {
fensters.forEach(fenster => {
doCommandForFenster(client, fenster, commandStr);
doCommandForFenster(client, fenster, commandStr, serverConfig.pin);
});
});
_.delay(() => {
doTelNetStuff((client) => {
fensters.forEach(fenster => {
doCommandForFenster(client, fenster, 'off');
doCommandForFenster(client, fenster, 'off', serverConfig.pin);
});
});
}, downTime)
Expand Down
6 changes: 3 additions & 3 deletions heytech/service/test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env node

import heytech from './heytech';
var heytech = require('../service/heytech');

heytech.rollershutter('13', 'up');
heytech.rollershutter('9', 'down');

setTimeout(function () {
heytech.rollershutter('13', 'off');
heytech.rollershutter('9', 'off');
}, 1000);


0 comments on commit 90740d3

Please sign in to comment.