Skip to content

Commit 123e68f

Browse files
author
vzakharchenko
committed
added more actions
1 parent 3475c98 commit 123e68f

13 files changed

+77
-12
lines changed

lib/executeService.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const { exec } = require('child_process');
22

33
const { offDeviceFromSmartThings } = require('./smartthings');
44
const { logger } = require('./logger');
5+
const { saveConfig } = require('./env');
56

67
const lastMessage = {
78
};
@@ -80,6 +81,36 @@ const actionToCommands = {
8081
reboot: () => 'reboot',
8182
halt: () => 'halt',
8283
upgrade: () => 'nohup npm i smartthings-phevctl -g >/dev/null 2>1 &',
84+
shutdown2H: (readConfig) => {
85+
// eslint-disable-next-line no-param-reassign
86+
readConfig.upsMaxTimeHours = '2';
87+
saveConfig(readConfig);
88+
return null;
89+
},
90+
shutdown5H: (readConfig) => {
91+
// eslint-disable-next-line no-param-reassign
92+
readConfig.upsMaxTimeHours = '5';
93+
saveConfig(readConfig);
94+
return null;
95+
},
96+
shutdown8H: (readConfig) => {
97+
// eslint-disable-next-line no-param-reassign
98+
readConfig.upsMaxTimeHours = '8';
99+
saveConfig(readConfig);
100+
return null;
101+
},
102+
shutdown1D: (readConfig) => {
103+
// eslint-disable-next-line no-param-reassign
104+
readConfig.upsMaxTimeHours = '24';
105+
saveConfig(readConfig);
106+
return null;
107+
},
108+
shutdown2D: (readConfig) => {
109+
// eslint-disable-next-line no-param-reassign
110+
readConfig.upsMaxTimeHours = '48';
111+
saveConfig(readConfig);
112+
return null;
113+
},
83114
};
84115

85116
const transformResponse = {
@@ -135,6 +166,10 @@ function sleep(ms) {
135166
function execute0(device, readConfig) {
136167
return new Promise((resolve) => {
137168
const command = actionToCommands[device.actionId](readConfig, device);
169+
if (!command) {
170+
resolve({ code: 0, output: null });
171+
return;
172+
}
138173
logger.info(`run command ${command}`);
139174
let scriptOutput = '';
140175
const child = exec(command);

lib/shutdownService.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ function execute(command) {
4040
logger.info('halt force killed');
4141
resolve();
4242
}
43-
}, 10000);
43+
}, 40000);
4444
});
4545
}
4646

4747
async function halt() {
48-
await execute('halt');
48+
await execute('sleep 30s &&halt');
4949
}
5050

5151
async function data() {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "smartthings-phevctl",
3-
"version": "1.8.11",
3+
"version": "1.9.0",
44
"description": "smartthings remote ctrl",
55
"main": "smartthings-phevctl.js",
66
"scripts": {

remote-ctrl-ui/src/components/SmartthingsAddDevice.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class SmartthingsAddDevice extends React.Component {
6464
if (data.name === 'actionId') {
6565
return (
6666
<Select
67-
style={{ width: 200 }}
67+
style={{ width: 600 }}
6868
onChange={(event) => {
6969
this.onActionChange(event);
7070
}}
@@ -91,6 +91,13 @@ export class SmartthingsAddDevice extends React.Component {
9191
<Select.Option value="evseSlow">{getLabels().evseSlow}</Select.Option>
9292
<Select.Option value="evseFastCharge">{getLabels().evseFastCharge}</Select.Option>
9393
<Select.Option value="evseDisableCharge">{getLabels().evseDisableCharge}</Select.Option>
94+
<Select.Option value="reboot">{getLabels().reboot}</Select.Option>
95+
<Select.Option value="halt">{getLabels().halt}</Select.Option>
96+
<Select.Option value="upgrade">{getLabels().upgrade}</Select.Option>
97+
<Select.Option value="shutdown2H">{getLabels().shutdown2H}</Select.Option>
98+
<Select.Option value="shutdown5H">{getLabels().shutdown5H}</Select.Option>
99+
<Select.Option value="shutdown1D">{getLabels().shutdown1D}</Select.Option>
100+
<Select.Option value="shutdown2D">{getLabels().shutdown2D}</Select.Option>
94101
</Select>
95102
);
96103
}

remote-ctrl-ui/src/components/SmartthingsViewDevice.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class SmartthingsViewDevice extends React.Component {
109109
return (
110110
<Select
111111
defaultValue={this.state.actionId}
112-
style={{ width: 200 }}
112+
style={{ width: 600 }}
113113
disabled={this.state.updatable}
114114
onChange={(event) => {
115115
this.onActionChange(event);
@@ -137,6 +137,13 @@ export class SmartthingsViewDevice extends React.Component {
137137
<Select.Option value="evseSlow">{getLabels().evseSlow}</Select.Option>
138138
<Select.Option value="evseFastCharge">{getLabels().evseFastCharge}</Select.Option>
139139
<Select.Option value="evseDisableCharge">{getLabels().evseDisableCharge}</Select.Option>
140+
<Select.Option value="reboot">{getLabels().reboot}</Select.Option>
141+
<Select.Option value="halt">{getLabels().halt}</Select.Option>
142+
<Select.Option value="upgrade">{getLabels().upgrade}</Select.Option>
143+
<Select.Option value="shutdown2H">{getLabels().shutdown2H}</Select.Option>
144+
<Select.Option value="shutdown5H">{getLabels().shutdown5H}</Select.Option>
145+
<Select.Option value="shutdown1D">{getLabels().shutdown1D}</Select.Option>
146+
<Select.Option value="shutdown2D">{getLabels().shutdown2D}</Select.Option>
140147
</Select>
141148
);
142149
}

remote-ctrl-ui/src/utils/Localization.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ const Labels = {
127127
pullUpDownShutdown: 'pull Up or Down',
128128
edgeShutdown: 'Edge',
129129
levelShutdown: 'Logic Level',
130+
reboot: 'Reboot device',
131+
halt: 'Shutdown device',
132+
upgrade: 'upgrade smartthings phevctl',
133+
shutdown2H: 'Shutdown device after 2 hours',
134+
shutdown5H: 'Shutdown device after 5 hours',
135+
shutdown8H: 'Shutdown device after 8 hours',
136+
shutdown1D: 'Shutdown device after 1 day',
137+
shutdown2D: 'Shutdown device after 2 days',
130138
};
131139

132140
export function getLabels() {

remote-ctrl-ui/src/utils/RussianLanguage.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,12 @@ export const RussianLabels = {
106106
ups1D: '1 день',
107107
ups2D: '2 дня',
108108
gpioMenu: 'GPIO',
109+
reboot: 'Перезапустить устройство',
110+
halt: 'Выключить устройство',
111+
upgrade: 'Обновить приложение smartthings phevctl',
112+
shutdown2H: 'Отключение устройство через 2 часа после включения ',
113+
shutdown5H: 'Отключение устройство через 5 часов после включения',
114+
shutdown8H: 'Отключение устройство через 8 часов после включения',
115+
shutdown1D: 'Отключение устройство через 1 день после включения',
116+
shutdown2D: 'Отключение устройство через 2 дня после включения',
109117
};

ui/asset-manifest.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"files": {
33
"main.css": "/static/css/main.32eb8335.chunk.css",
4-
"main.js": "/static/js/main.3cbdbbd4.chunk.js",
5-
"main.js.map": "/static/js/main.3cbdbbd4.chunk.js.map",
4+
"main.js": "/static/js/main.88269063.chunk.js",
5+
"main.js.map": "/static/js/main.88269063.chunk.js.map",
66
"runtime-main.js": "/static/js/runtime-main.fd3c3b07.js",
77
"runtime-main.js.map": "/static/js/runtime-main.fd3c3b07.js.map",
88
"static/css/2.a95be28f.chunk.css": "/static/css/2.a95be28f.chunk.css",
@@ -20,6 +20,6 @@
2020
"static/css/2.a95be28f.chunk.css",
2121
"static/js/2.eebff65e.chunk.js",
2222
"static/css/main.32eb8335.chunk.css",
23-
"static/js/main.3cbdbbd4.chunk.js"
23+
"static/js/main.88269063.chunk.js"
2424
]
2525
}

ui/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>Outlander PHEV Smartthings server</title><link href="/static/css/2.a95be28f.chunk.css" rel="stylesheet"><link href="/static/css/main.32eb8335.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function r(r){for(var n,i,a=r[0],c=r[1],l=r[2],s=0,p=[];s<a.length;s++)i=a[s],Object.prototype.hasOwnProperty.call(o,i)&&o[i]&&p.push(o[i][0]),o[i]=0;for(n in c)Object.prototype.hasOwnProperty.call(c,n)&&(e[n]=c[n]);for(f&&f(r);p.length;)p.shift()();return u.push.apply(u,l||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,a=1;a<t.length;a++){var c=t[a];0!==o[c]&&(n=!1)}n&&(u.splice(r--,1),e=i(i.s=t[0]))}return e}var n={},o={1:0},u=[];function i(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,i),t.l=!0,t.exports}i.e=function(e){var r=[],t=o[e];if(0!==t)if(t)r.push(t[2]);else{var n=new Promise((function(r,n){t=o[e]=[r,n]}));r.push(t[2]=n);var u,a=document.createElement("script");a.charset="utf-8",a.timeout=120,i.nc&&a.setAttribute("nonce",i.nc),a.src=function(e){return i.p+"static/js/"+({}[e]||e)+"."+{3:"4c39a317"}[e]+".chunk.js"}(e);var c=new Error;u=function(r){a.onerror=a.onload=null,clearTimeout(l);var t=o[e];if(0!==t){if(t){var n=r&&("load"===r.type?"missing":r.type),u=r&&r.target&&r.target.src;c.message="Loading chunk "+e+" failed.\n("+n+": "+u+")",c.name="ChunkLoadError",c.type=n,c.request=u,t[1](c)}o[e]=void 0}};var l=setTimeout((function(){u({type:"timeout",target:a})}),12e4);a.onerror=a.onload=u,document.head.appendChild(a)}return Promise.all(r)},i.m=e,i.c=n,i.d=function(e,r,t){i.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,r){if(1&r&&(e=i(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(i.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)i.d(t,n,function(r){return e[r]}.bind(null,n));return t},i.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(r,"a",r),r},i.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},i.p="/",i.oe=function(e){throw console.error(e),e};var a=this["webpackJsonpremote-ctrl-ui"]=this["webpackJsonpremote-ctrl-ui"]||[],c=a.push.bind(a);a.push=r,a=a.slice();for(var l=0;l<a.length;l++)r(a[l]);var f=c;t()}([])</script><script src="/static/js/2.eebff65e.chunk.js"></script><script src="/static/js/main.3cbdbbd4.chunk.js"></script></body></html>
1+
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>Outlander PHEV Smartthings server</title><link href="/static/css/2.a95be28f.chunk.css" rel="stylesheet"><link href="/static/css/main.32eb8335.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function r(r){for(var n,i,a=r[0],c=r[1],l=r[2],s=0,p=[];s<a.length;s++)i=a[s],Object.prototype.hasOwnProperty.call(o,i)&&o[i]&&p.push(o[i][0]),o[i]=0;for(n in c)Object.prototype.hasOwnProperty.call(c,n)&&(e[n]=c[n]);for(f&&f(r);p.length;)p.shift()();return u.push.apply(u,l||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,a=1;a<t.length;a++){var c=t[a];0!==o[c]&&(n=!1)}n&&(u.splice(r--,1),e=i(i.s=t[0]))}return e}var n={},o={1:0},u=[];function i(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,i),t.l=!0,t.exports}i.e=function(e){var r=[],t=o[e];if(0!==t)if(t)r.push(t[2]);else{var n=new Promise((function(r,n){t=o[e]=[r,n]}));r.push(t[2]=n);var u,a=document.createElement("script");a.charset="utf-8",a.timeout=120,i.nc&&a.setAttribute("nonce",i.nc),a.src=function(e){return i.p+"static/js/"+({}[e]||e)+"."+{3:"4c39a317"}[e]+".chunk.js"}(e);var c=new Error;u=function(r){a.onerror=a.onload=null,clearTimeout(l);var t=o[e];if(0!==t){if(t){var n=r&&("load"===r.type?"missing":r.type),u=r&&r.target&&r.target.src;c.message="Loading chunk "+e+" failed.\n("+n+": "+u+")",c.name="ChunkLoadError",c.type=n,c.request=u,t[1](c)}o[e]=void 0}};var l=setTimeout((function(){u({type:"timeout",target:a})}),12e4);a.onerror=a.onload=u,document.head.appendChild(a)}return Promise.all(r)},i.m=e,i.c=n,i.d=function(e,r,t){i.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,r){if(1&r&&(e=i(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(i.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)i.d(t,n,function(r){return e[r]}.bind(null,n));return t},i.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(r,"a",r),r},i.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},i.p="/",i.oe=function(e){throw console.error(e),e};var a=this["webpackJsonpremote-ctrl-ui"]=this["webpackJsonpremote-ctrl-ui"]||[],c=a.push.bind(a);a.push=r,a=a.slice();for(var l=0;l<a.length;l++)r(a[l]);var f=c;t()}([])</script><script src="/static/js/2.eebff65e.chunk.js"></script><script src="/static/js/main.88269063.chunk.js"></script></body></html>

ui/static/js/main.3cbdbbd4.chunk.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)