Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added actions for shelly and rest API commands #129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions app/lang/i18n.de.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
{
"inputIpAddress": "IP-Adresse eingeben",
"keyParameter": "Key",
"valueParameter": "Value",
"getMethod": "GET",
"postMethod": "POST",
"method": "Method: ",
"urlRequest": "URL Request",
"turnOn": "On",
"turnOff": "Off",
"turn": "Zustand",
"turnToggle": "Toggle",
"http": "http",
"https": "https",
"http/https": "HTTP/HTTPS",
"format": "Format",
"body": "Body",
"params": "Parameters",
"bodyData": "Data",


"GridActionKeyValueRequest": "HTTP Key-Value Abfrage",
"GridActionTurnOnShelly": "Shelly ein-/aus-/umschalten",


"GridActionSpeak": "Label aussprechen",
"GridActionSpeakCustom": "Benutzerdefinierten Text aussprechen",
"GridActionNavigate": "Zu anderem Grid navigieren",
Expand Down
25 changes: 25 additions & 0 deletions app/lang/i18n.en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
{

"inputIpAddress": "Input IP-Adress",
"keyParameter": "Key",
"valueParameter": "Value",
"getMethod": "GET",
"postMethod": "POST",
"method": "Method: ",
"urlRequest": "URL Request",
"turnOn": "On",
"turnOff": "Off",
"turnToggle": "Toggle",
"turn": "State",
"http": "http",
"https": "https",
"http/https": "HTTP/HTTPS",
"format": "Format",
"body": "Body",
"params": "Parameters",
"bodyData": "Data",


"GridActionKeyValueRequest": "HTTP Key-Value Request",
"GridActionTurnOnShelly": "Shelly turn on/off/toggle",


"GridActionSpeak": "Speak label",
"GridActionSpeakCustom": "Speak custom text",
"GridActionNavigate": "Navigate to other grid",
Expand Down
246 changes: 144 additions & 102 deletions index.html

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"predictionary": "^1.6.0",
"superlogin-client": "^0.8.0",
"vue": "^2.5.17",
"vue-i18n": "8"
"vue-i18n": "8",
"vue-simple-search-dropdown": "^1.0.1"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
Expand Down
38 changes: 38 additions & 0 deletions src/js/model/GridActionKeyValueRequest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {modelUtil} from "../util/modelUtil";
import {constants} from "../util/constants";
import {Model} from "../externals/objectmodel";

class GridActionKeyValueRequest extends Model({
id: String,
modelName: String,
modelVersion: String,

keyParameter: [String],
valueParameter: [String],
urlRequest: [String],
format: [String],
bodyData: [String],
// body: [String],
// params: [String],
method: [String]

}) {
constructor(properties, elementToCopy) {
properties = modelUtil.setDefaults(properties, elementToCopy, GridActionKeyValueRequest);
super(properties);
this.id = this.id || modelUtil.generateId('grid-action-key-value-request')
// this.id = this.id || modelUtil.generateId(GridActionOpenWebpage.getModelName()) /
}

static getModelName() {
return "GridActionKeyValueRequest";
}
}

GridActionKeyValueRequest.defaults({
id: "", //will be replaced by constructor
modelName: GridActionKeyValueRequest.getModelName(),
modelVersion: constants.MODEL_VERSION
});

export {GridActionKeyValueRequest};
31 changes: 31 additions & 0 deletions src/js/model/GridActionTurnOnShelly.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {modelUtil} from "../util/modelUtil";
import {constants} from "../util/constants";
import {Model} from "../externals/objectmodel";

class GridActionTurnOnShelly extends Model({
id: String,
modelName: String,
modelVersion: String,

shellyIP: [String],
turn: [String]
}) {
constructor(properties, elementToCopy) {
properties = modelUtil.setDefaults(properties, elementToCopy, GridActionTurnOnShelly);
super(properties);
this.id = this.id || modelUtil.generateId('grid-action-turn-on-shelly')
// this.id = this.id || modelUtil.generateId(GridActionOpenWebpage.getModelName()) /
}

static getModelName() {
return "GridActionTurnOnShelly";
}
}

GridActionTurnOnShelly.defaults({
id: "", //will be replaced by constructor
modelName: GridActionTurnOnShelly.getModelName(),
modelVersion: constants.MODEL_VERSION
});

export {GridActionTurnOnShelly};
4 changes: 3 additions & 1 deletion src/js/model/GridElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {GridActionWebradio} from "./GridActionWebradio";
import {GridActionChangeLang} from "./GridActionChangeLang";
import {GridActionYoutube} from "./GridActionYoutube";
import {GridActionOpenWebpage} from "./GridActionOpenWebpage.js";
import {GridActionTurnOnShelly} from "./GridActionTurnOnShelly.js";
import {GridActionKeyValueRequest} from "./GridActionKeyValueRequest.js";

class GridElement extends Model({
id: String,
Expand Down Expand Up @@ -73,7 +75,7 @@ class GridElement extends Model({
}

static getActionTypes() {
return [GridActionSpeak, GridActionNavigate, GridActionSpeakCustom, GridActionPredict, GridActionCollectElement, GridActionARE, GridActionWebradio, GridActionYoutube, GridActionChangeLang, GridActionOpenWebpage];
return [GridActionSpeak, GridActionNavigate, GridActionSpeakCustom, GridActionPredict, GridActionCollectElement, GridActionARE, GridActionWebradio, GridActionYoutube, GridActionChangeLang, GridActionOpenWebpage, GridActionTurnOnShelly, GridActionKeyValueRequest];
}

static getActionTypeModelNames() {
Expand Down
47 changes: 47 additions & 0 deletions src/js/service/actionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,53 @@ function doAction(gridElement, action, gridId, gridData) {
}, action.timeoutSeconds * 1000);
}
break;

case 'GridActionTurnOnShelly':
if (action.turn === "On") {
console.log("Turn On")
$.get(action.httpHttps + "://" + action.shellyIP + "/relay/0?turn=on");
}
if (action.turn === "Off") {
console.log("Turn Off")
$.get(action.httpHttps + "://" + action.shellyIP + "/relay/0?turn=off");
}
if (action.turn === "Toggle") {
console.log("Toggle")
$.get(action.httpHttps + "://" + action.shellyIP + "/relay/0?turn=toggle");
}
break;

case 'GridActionKeyValueRequest':

if (action.format === "Parameters")
{
if (action.method === "POST") {
console.log("do POST request")
$.post(action.urlRequest + "?" + action.keyParameter + "=" + action.valueParameter).then(data => {
console.log(data);
});
}
if (action.method === "GET") {
console.log("do GET request")
$.get(action.urlRequest + "?" + action.keyParameter + "=" + action.valueParameter).then(data => {
console.log(data);
});
}
}

if (action.format === "Body")
{
$.ajax({
url: action.urlRequest,
type: action.method,
data: action.bodyData,
contentType:"text/plain",
dataType:"text/plain"
}).then(data => { console.log(data);
});
}
break;

}
}

Expand Down
Loading