Skip to content

Commit

Permalink
Merge pull request #61 from chaveiro/master
Browse files Browse the repository at this point in the history
Bug fix
  • Loading branch information
TrystanLea authored Sep 22, 2021
2 parents 28fb5f6 + 4bd32c6 commit 817d70a
Show file tree
Hide file tree
Showing 12 changed files with 621 additions and 52 deletions.
11 changes: 7 additions & 4 deletions Views/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,25 @@ var device = {
$.ajax({ url: path+"device/set.json", data: "id="+id+"&fields="+JSON.stringify(fields), async: false, success: function(data) {result = data;} });
return result;
},

'generatekey':function(id) {
var result = {};
$.ajax({ url: path+"device/generatekey.json", async: false, success: function(data) {result = data;} });
return result;
},
'setNewDeviceKey':function(id) {
var result = {};
$.ajax({ url: path+"device/setnewdevicekey.json", data: "id="+id, async: false, success: function(data) {result = data;} });
return result;
},

'remove':function(id) {
var result = {};
$.ajax({ url: path+"device/delete.json", data: "id="+id, async: false, success: function(data) {result = data;} });
return result;
},

'create':function(nodeid, name, description, type) {
'create':function(nodeid, name, description, type, devicekey) {
var result = {};
$.ajax({ url: path+"device/create.json", data: "nodeid="+nodeid+"&name="+name+"&description="+description+"&type="+type, async: false, success: function(data) {result = data;} });
$.ajax({ url: path+"device/create.json", data: "nodeid="+nodeid+"&name="+name+"&description="+description+"&type="+type+"&dkey="+devicekey, async: false, success: function(data) {result = data;} });
return result;
},

Expand Down
8 changes: 5 additions & 3 deletions Views/device_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
<table class="table">
<tr><td><?php echo _('List devices'); ?></td><td><a href="<?php echo $path; ?>device/list.json"><?php echo $path; ?>device/list.json</a></td></tr>
<tr><td><?php echo _('Get device details'); ?></td><td><a href="<?php echo $path; ?>device/get.json?id=1"><?php echo $path; ?>device/get.json?id=1</a></td></tr>
<tr><td><?php echo _('Add a device'); ?></td><td><a href="<?php echo $path; ?>device/create.json?nodeid=Test&name=Test"><?php echo $path; ?>device/create.json?nodeid=Test&name=Test</a></td></tr>
<tr><td><?php echo _('Add a device'); ?></td><td><a href="<?php echo $path; ?>device/create.json?nodeid=Room&name=Test&description=House&type=test&dkey=DEVICEKEY"><?php echo $path; ?>device/set.json?nodeid=Room&name=Test&description=House&type=test&dkey=DEVICEKEY</a></td></tr>
<tr><td><?php echo _('Delete device'); ?></td><td><a href="<?php echo $path; ?>device/delete.json?id=1"><?php echo $path; ?>device/delete.json?id=1</a></td></tr>
<tr><td><?php echo _('Update device'); ?></td><td><a href="<?php echo $path; ?>device/set.json?id=1&fields={%22name%22:%22Test%22,%22description%22:%22Room%22,%22nodeid%22:%22House%22,%22type%22:%22test%22}"><?php echo $path; ?>device/set.json?id=1&fields={"name":"Test","description":"Room","nodeid":"House","type":"test"}</a></td></tr>
<tr><td><?php echo _('Update device'); ?></td><td><a href="<?php echo $path; ?>device/set.json?id=1&nodeid=Room&name=Test&description=House&type=test&dkey=DEVICEKEY"><?php echo $path; ?>device/set.json?id=1&nodeid=Room&name=Test&description=House&type=test&dkey=DEVICEKEY</a></td></tr>
<tr><td><?php echo _('Generate a random device key'); ?></td><td><a href="<?php echo $path; ?>device/generatekey.json"><?php echo $path; ?>device/generatekey.json</a></td></tr>
<tr><td><?php echo _('Set a new random device key'); ?></td><td><a href="<?php echo $path; ?>device/setNewDeviceKey.json?id=1"><?php echo $path; ?>device/setNewDeviceKey.json?id=1</a></td></tr>
<tr><td><?php echo _('Initialize device'); ?></td><td><a href="<?php echo $path; ?>device/init.json?id=1"><?php echo $path; ?>device/init.json?id=1</a></td></tr>
</table>

Expand All @@ -60,7 +62,7 @@
<tr><td><?php echo _('List template metadata'); ?></td><td><a href="<?php echo $path; ?>device/template/listshort.json"><?php echo $path; ?>device/template/listshort.json</a></td></tr>
<tr><td><?php echo _('List templates'); ?></td><td><a href="<?php echo $path; ?>device/template/list.json"><?php echo $path; ?>device/template/list.json</a></td></tr>
<tr><td><?php echo _('Reload templates'); ?></td><td><a href="<?php echo $path; ?>device/template/reload.json"><?php echo $path; ?>device/template/reload.json</a></td></tr>
<tr><td><?php echo _('get template details'); ?></td><td><a href="<?php echo $path; ?>device/template/get.json?type=example"><?php echo $path; ?>device/template/get.json?type=example</a></td></tr>
<tr><td><?php echo _('Get template details'); ?></td><td><a href="<?php echo $path; ?>device/template/get.json?type=example"><?php echo $path; ?>device/template/get.json?type=example</a></td></tr>
<tr><td><?php echo _('Prepare device initialization'); ?></td><td><a href="<?php echo $path; ?>device/template/prepare.json?id=1"><?php echo $path; ?>device/template/prepare.json?id=1</a></td></tr>
</table>

Expand Down
36 changes: 16 additions & 20 deletions Views/device_dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ var device_dialog =

body.append(
"<div id='template-"+categoryid+"-"+groupid+"-"+id.replace('/', '-')+"'" +
"data-type='"+id+"' class='group-device'>" +
"data-type='"+id+"' class='group-device'>" +
"<span>"+name+"</span>" +
"</div>"
);
Expand Down Expand Up @@ -146,8 +146,7 @@ var device_dialog =
$('#device-config-node').val(this.device.nodeid);
$('#device-config-name').val(this.device.name);
$('#device-config-description').val(this.device.description);
$('#device-config-devicekey').val(this.device.devicekey).prop("disabled", false);
$("#device-config-devicekey-new").prop("disabled", false);
$('#device-config-devicekey').val(this.device.devicekey);
$('#device-delete').show();
$("#device-save").html("Save");
if (this.device.type != null && this.device.type != '') {
Expand All @@ -163,8 +162,7 @@ var device_dialog =
$('#device-config-node').val('');
$('#device-config-name').val('');
$('#device-config-description').val('');
$('#device-config-devicekey').val('').prop("disabled", true);
$("#device-config-devicekey-new").prop("disabled", true);
$('#device-config-devicekey').val('');
$('#device-delete').hide();
$("#device-init").hide();
$("#device-save").html("Save & Initialize");
Expand Down Expand Up @@ -260,11 +258,10 @@ var device_dialog =
alert('Unable to update device fields:\n'+result.message);
return false;
}
update();
}
else {
var type = device_dialog.deviceType;
var result = device.create(node, name, desc, type);
var result = device.create(node, name, desc, type, devicekey);
if (typeof result.success !== 'undefined' && !result.success) {
alert('Unable to create device:\n'+result.message);
return false;
Expand All @@ -278,13 +275,13 @@ var device_dialog =
};
init = true;
}
update();
}
update();
$('#device-config-modal').modal('hide');
if (init) device_dialog.loadInit();
}
else {
alert('Device needs to be configured first.');
alert('Please give Node and Name.');
return false;
}
});
Expand All @@ -300,8 +297,7 @@ var device_dialog =
});

$("#device-config-devicekey-new").off('click').on('click', function () {
device_dialog.device.devicekey = device.setNewDeviceKey(device_dialog.device.id);
$('#device-config-devicekey').val(device_dialog.device.devicekey);
$('#device-config-devicekey').val(device.generatekey());
});
},

Expand Down Expand Up @@ -433,44 +429,44 @@ var device_dialog =
var label;
switch(process['arguments']['type']) {
case 0: // VALUE
label = "important";
label = "important";
title = "Value - ";
break;

case 1: //INPUTID
label = "warning";
label = "warning";
title = "Input - ";
break;

case 2: //FEEDID
label = "info";
label = "info";
title = "Feed - ";
break;

case 3: // NONE
label = "important";
label = "important";
title = "";
break;

case 4: // TEXT
label = "important";
label = "important";
title = "Text - ";
break;

case 5: // SCHEDULEID
label = "warning";
label = "warning";
title = "Schedule - "
break;

default:
label = "important";
label = "important";
title = "ERROR - ";
break;
}
title += process["name"];
title += process["name"];

if (process['arguments']['value'] != undefined) {
title += ": " + process['arguments']['value'];
title += ": " + process['arguments']['value'];
}

out += "<span class='label label-"+label+"' title='"+title+"' style='cursor:default'><small>"+process["short"]+"</small></span> ";
Expand Down
14 changes: 7 additions & 7 deletions Views/device_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@

<div>
<div id="api-help-header" style="float:right;"><a href="api"><?php echo _('Devices Help'); ?></a></div>
<div id="device-header"><h2><?php echo _('Devices'); ?></h2></div>
<div id="device-header"><h2><?php echo _('Devices Location'); ?></h2></div>

<div id="table"></div>

<div id="device-none" class="hide">
<div class="alert alert-block">
<h4 class="alert-heading"><?php echo _('No devices'); ?></h4><br>
<p>
<?php echo _('Devices are used to configure and prepare the communication with different physical devices.'); ?>
<?php echo _('Devices are used to configure and prepare the communication with different physical devices. Devices are grouped by Location for easy tracking when deploying at scale.'); ?>
<br><br>
<?php echo _('A device configures and prepares inputs, feeds possible other settings, representing e.g. different registers of defined metering units.'); ?>
<?php echo _('A device configures and prepares inputs, feeds and other possible settings. e.g. representing different registers of defined metering units.'); ?>
<br>
<?php echo _('You may want the next link as a guide for generating your request: '); ?><a href="api"><?php echo _('Device API helper'); ?></a>
<?php echo _('Follow the next link as a guide for generating your request: '); ?><a href="api"><?php echo _('Device API helper'); ?></a>
</p>
</div>
</div>
Expand All @@ -48,8 +48,8 @@
<button id="device-reload" class="btn btn-small" >&nbsp;<i class="icon-refresh" ></i>&nbsp;<?php echo _('Reload device templates'); ?></button>
<?php } ?>
</div>
<div id="device-loader" class="ajax-loader"></div>
<div id="device-loader" class="ajax-loader"></div>
</div>

<?php require "Modules/device/Views/device_dialog.php"; ?>
Expand All @@ -60,7 +60,7 @@
// Extend table library field types
for (z in customtablefields) table.fieldtypes[z] = customtablefields[z];
table.element = "#table";
table.groupprefix = "Location ";
table.groupprefix = "";
table.groupby = 'description';
table.groupfields = {
'dummy-4':{'title':'', 'type':"blank"},
Expand Down
124 changes: 124 additions & 0 deletions data/Gtronica/AirSensor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"name": "Air Sensor",
"category": "Gtronica",
"group": "Custom",
"description": "Automatic inputs and feeds creation for IKEA Vindriktning + BME280 with a Tasmota device inside and websend rules.",
"inputs": [
{
"name": "T",
"description": "Temperature",
"processList": [
{
"process": "log_to_feed",
"arguments": {
"type": "ProcessArg::FEEDID",
"value": "Temperature"
}
}
]
},
{
"name": "H",
"description": "Humidity",
"processList": [
{
"process": "log_to_feed",
"arguments": {
"type": "ProcessArg::FEEDID",
"value": "Humidity"
}
}
]
},
{
"name": "P",
"description": "Pressure",
"processList": [
{
"process": "log_to_feed",
"arguments": {
"type": "ProcessArg::FEEDID",
"value": "Pressure"
}
}
]
},
{
"name": "PM1",
"description": "PM1",
"processList": [
{
"process": "log_to_feed",
"arguments": {
"type": "ProcessArg::FEEDID",
"value": "PM1"
}
}
]
},
{
"name": "PM2",
"description": "PM2.5",
"processList": [
{
"process": "log_to_feed",
"arguments": {
"type": "ProcessArg::FEEDID",
"value": "PM2"
}
}
]
},
{
"name": "PM10",
"description": "PM10",
"processList": [
{
"process": "log_to_feed",
"arguments": {
"type": "ProcessArg::FEEDID",
"value": "PM10"
}
}
]
}
],
"feeds": [
{
"name": "Temperature",
"type": "DataType::REALTIME",
"engine": "Engine::MYSQL",
"unit": "ºC"
},
{
"name": "Humidity",
"type": "DataType::REALTIME",
"engine": "Engine::MYSQL",
"unit": "%"
},
{
"name": "Pressure",
"type": "DataType::REALTIME",
"engine": "Engine::MYSQL",
"unit": "hPa"
},
{
"name": "PM1",
"type": "DataType::REALTIME",
"engine": "Engine::MYSQL",
"unit": "µg/m³"
},
{
"name": "PM2",
"type": "DataType::REALTIME",
"engine": "Engine::MYSQL",
"unit": "µg/m³"
},
{
"name": "PM10",
"type": "DataType::REALTIME",
"engine": "Engine::MYSQL",
"unit": "µg/m³"
}
]
}
Loading

0 comments on commit 817d70a

Please sign in to comment.