Skip to content

Commit 12324c1

Browse files
Merge pull request #127 from TakayukiHoshi1984/feature_smartmeter_plugin
SmartMeterプラグインの追加
2 parents e17c507 + b83647e commit 12324c1

11 files changed

Lines changed: 2043 additions & 85 deletions

File tree

dConnectJavascriptApp/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<script src="./js/profile/fabo.js" type="text/javascript"></script>
6363
<script src="./js/profile/mouse.js" type="text/javascript"></script>
6464
<script src="./js/profile/keyboard.js" type="text/javascript"></script>
65+
<script src="./js/profile/device.js" type="text/javascript"></script>
6566
<script src="./js/sdk/util.js" type="text/javascript"></script>
6667
<script src="./js/demo.js" type="text/javascript"></script>
6768

dConnectJavascriptApp/js/demo.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ function authorization(callback, oncalcel) {
251251
'tv', 'powermeter','humidity','illuminance', 'videochat',
252252
'airconditioner','gpio', 'ecg', 'stressEstimation', 'poseEstimation',
253253
'walkState', 'messagehook', 'atmosphericPressure', 'geolocation',
254-
'echonetLite', 'power', 'fabo', 'mouse', 'keyboard');
254+
'echonetLite', 'power', 'fabo', 'mouse', 'keyboard', 'device');
255255
dConnect.authorization(scopes, 'Demo Web Site',
256256
function(clientId, newAccessToken) {
257257
// Client ID
@@ -438,5 +438,7 @@ function searchProfile(serviceId, profile) {
438438
showMouse(serviceId);
439439
} else if (isEqualToStringIgnoreCase(profile, 'keyboard')) {
440440
showKeyboard(serviceId);
441+
} else if (isEqualToStringIgnoreCase(profile, 'device')) {
442+
showDevice(serviceId);
441443
}
442444
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
device.js
3+
Copyright (c) 2017 NTT DOCOMO,INC.
4+
Released under the MIT license
5+
http://opensource.org/licenses/mit-license.php
6+
*/
7+
8+
/**
9+
* Show Device Menu
10+
*
11+
* @param {String} serviceId service Id
12+
*/
13+
function showDevice(serviceId) {
14+
initAll();
15+
setTitle('Device Profile');
16+
17+
var sessionKey = currentClientId;
18+
19+
var btnStr = getBackButton('Device Top', 'doPowerMeterBack', serviceId, '');
20+
reloadHeader(btnStr);
21+
reloadFooter(btnStr);
22+
23+
var str = '';
24+
25+
str += makeInputText('Result', 'post-pairing', 'post-pairing');
26+
str += devMakeButton('PostPairing (Connect)','doDevicePostPairing',serviceId);
27+
str += '<hr>';
28+
29+
str += makeInputText('Result', 'delete-pairing', 'delete-pairing');
30+
str += devMakeButton('DeletePairing (Disconnect)','doDeviceDeletePairing',serviceId);
31+
str += '<hr>';
32+
33+
reloadContent(str);
34+
}
35+
36+
function doDevicePostPairing(serviceId){
37+
var builder = devMakeUriBuilder(serviceId, 'pairing');
38+
var successCallback = function (json){
39+
console.log('Response: ', json);
40+
$('#post-pairing').val(json.result);
41+
};
42+
console.log('Uri: ', builder.build());
43+
dConnect.post(builder.build(),null,null,successCallback,pmAlertError);
44+
}
45+
46+
function doDeviceDeletePairing(serviceId){
47+
var builder = devMakeUriBuilder(serviceId, 'pairing');
48+
var successCallback = function (json){
49+
console.log('Response: ', json);
50+
$('#delete-pairing').val(json.result);
51+
};
52+
console.log('Uri: ', builder.build());
53+
dConnect.delete(builder.build(),null,successCallback,devAlertError);
54+
}
55+
56+
/**
57+
* Back button
58+
*
59+
* @param {String}serviceId service id
60+
* @param {String}sessionKey session key
61+
*/
62+
function doDeviceBack(serviceId, sessionKey) {
63+
searchSystem(serviceId);
64+
}
65+
66+
//////common (dev = device)
67+
68+
function devMakeButton(title,functionName,params) {
69+
var paramStr = '';
70+
if(params !== null && params.length > 0){
71+
if( typeof params === 'string' ) {
72+
params = [ params ];
73+
}
74+
for (var i = 0;i<params.length;i++){
75+
paramStr += '\''+params[i]+'\'';
76+
paramStr += ',';
77+
}
78+
paramStr = paramStr.slice(0,-1);
79+
}
80+
return '<input onclick="'+functionName+'('+paramStr+');" type="button" value="'+title+'"/>';
81+
}
82+
83+
function devMakeUriBuilder(serviceId, attribute){
84+
var builder = new dConnect.URIBuilder();
85+
builder.setProfile('device');
86+
builder.setServiceId(serviceId);
87+
builder.setAccessToken(accessToken);
88+
if(typeof attribute !== 'undefined'){
89+
builder.setAttribute(attribute);
90+
}
91+
return builder;
92+
}
93+
94+
function devAlertError(errorCode, errorMessage){
95+
showError('device error', errorCode, errorMessage);
96+
}

dConnectJavascriptApp/js/profile/powermeter.js

Lines changed: 104 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function showPowerMeter(serviceId) {
2323
var str = '';
2424

2525
str += makeInputText('PowerStatus', 'power-status', 'power-status');
26-
str += pmMakeButton('GetPowerState','doPowerMeterGetPowerState',serviceId);
26+
str += pmMakeButton('GetPowerStatus','doPowerMeterGetPowerStatus',serviceId);
2727
str += pmMakeButton('PutPowerOn','doPowerMeterPutPowerOn',serviceId);
2828
str += pmMakeButton('DeletePowerOff','doPowerMeterDeletePowerOff',serviceId);
2929
str += '<hr>';
@@ -32,22 +32,76 @@ function showPowerMeter(serviceId) {
3232
str += '<input name="newDate" id="newDate" type="text" data-role="datebox" data-options=\'{"mode":"datebox"}\' />';
3333
str += '<input name="newTime" id="newTime" type="text" data-role="datebox" data-options=\'{"mode":"timebox"}\' />';
3434

35+
str += '<form name="integratedPowerUnitForm">';
36+
str += '<SELECT name="integrated-unit" id="integrated-unit">';
37+
str += '<OPTION value="null_value">unit : 指定なし</OPTION>';
38+
str += '<OPTION value="Wh">unit : Wh</OPTION>';
39+
str += '<OPTION value="kWh">unit : kWh</OPTION>';
40+
str += '<OPTION value="MWh">unit : MWh (Error Case)</OPTION>';
41+
str += '</SELECT>';
42+
str += '</form>';
43+
44+
str += '<form name="integratedPowerCountForm">';
45+
str += '<SELECT name="count-power" id="count-power">';
46+
str += '<OPTION value="null_value">count : 指定なし</OPTION>';
47+
str += '<OPTION value="24">count : 24</OPTION>';
48+
str += '<OPTION value="48">count : 48</OPTION>';
49+
str += '<OPTION value="96">count : 96 (Error Case)</OPTION>';
50+
str += '</SELECT>';
51+
str += '</form>';
52+
53+
str += '<form name="integratedPowerPowerFlowForm">';
54+
str += '<SELECT name="powerFlow-power" id="powerFlow-power">';
55+
str += '<OPTION value="null_value">powerFlow : 指定なし</OPTION>';
56+
str += '<OPTION value="normal">powerFlow : normal</OPTION>';
57+
str += '<OPTION value="reverse">powerFlow : reverse</OPTION>';
58+
str += '<OPTION value="turn">powerFlow : turn (Error Case)</OPTION>';
59+
str += '</SELECT>';
60+
str += '</form>';
61+
3562
str += makeInputText('IntegratedPower', 'integrated-power', 'integrated-power');
63+
str += makeInputText('Unit', 'integrated-power-unit', 'integrated-power-unit');
64+
str += makeInputText('Count', 'integrated-power-count', 'integrated-power-count');
65+
str += makeInputText('powerFlow', 'integrated-power-powerflow', 'integrated-power-powerflow');
3666
str += pmMakeButton('GetIntegratedPower','doPowerMeterGetIntegratedPower',serviceId);
3767
str += '<hr>';
3868

69+
str += '<form name="instantaneousPowerUnitForm">';
70+
str += '<SELECT name="unit-power" id="unit-power">';
71+
str += '<OPTION value="null_value">unit : 指定なし</OPTION>';
72+
str += '<OPTION value="W">unit : W</OPTION>';
73+
str += '<OPTION value="kW">unit : kW</OPTION>';
74+
str += '<OPTION value="MW">unit : MW (Error Case)</OPTION>';
75+
str += '</SELECT>';
76+
str += '</form>';
77+
3978
str += makeInputText('InstantaneousPower', 'instantaneous-power', 'instantaneous-power');
79+
str += makeInputText('Unit', 'instantaneous-power-unit', 'instantaneous-power-unit');
4080
str += pmMakeButton('GetInstantaneousPower','doPowerMeterGetInstantaneousPower',serviceId);
4181
str += '<hr>';
4282

83+
str += '<form name="integratedCurrentUnitForm">';
84+
str += '<SELECT name="unit-current" id="unit-current">';
85+
str += '<OPTION value="null_value">unit : 指定なし</OPTION>';
86+
str += '<OPTION value="A">unit : A</OPTION>';
87+
str += '<OPTION value="mA">unit : mA</OPTION>';
88+
str += '<OPTION value="uA">unit : uA (Error Case)</OPTION>';
89+
str += '</SELECT>';
90+
str += '</form>';
91+
92+
str += makeInputText('InstantaneousCurrent(R)', 'instantaneous-current-r', 'instantaneous-current-r');
93+
str += makeInputText('InstantaneousCurrent(T)', 'instantaneous-current-t', 'instantaneous-current-t');
94+
str += makeInputText('Unit', 'instantaneous-current-unit', 'instantaneous-current-unit');
95+
str += pmMakeButton('GetInstantaneousCurrent','doPowerMeterGetInstantaneousCurrent',serviceId);
96+
str += '<hr>';
4397
reloadContent(str);
4498
}
4599

46-
function doPowerMeterGetPowerState(serviceId){
100+
function doPowerMeterGetPowerStatus(serviceId){
47101
var builder = pmMakeUriBuilder(serviceId);
48102
var successCallback = function (json){
49103
console.log('Response: ', json);
50-
$('#power-stauts').val(json.powerstatus);
104+
$('#power-status').val(json.powerstatus);
51105
};
52106
dConnect.get(builder.build(), null, successCallback, pmAlertError);
53107
}
@@ -69,26 +123,66 @@ function doPowerMeterGetIntegratedPower(serviceId){
69123
var newTime = $('#newTime').val();
70124

71125
if(newDate && newTime){
72-
var newDateStr = newDate + 'T' + newTime + ':00+0900';
126+
var newDateStr = newDate + 'T' + newTime + ':00+09:00';
73127
builder.addParameter('date', newDateStr);
74128
}
75129

130+
var unit = $('#integrated-unit').val();
131+
132+
if (unit != 'null_value') {
133+
builder.addParameter('unit', unit);
134+
}
135+
136+
var count = $('#count-power').val();
137+
138+
if (count != 'null_value') {
139+
builder.addParameter('count', count);
140+
}
141+
142+
var powerFlow = $('#powerFlow-power').val();
143+
144+
if (powerFlow != 'null_value') {
145+
builder.addParameter('powerFlow', powerFlow);
146+
}
147+
76148
var successCallback = function (json){
77-
var integra = json.integratedpower;
78-
var total = 0;
79-
jQuery.each(integra,function(i,value){
80-
total+=value;
81-
});
82-
$('#integrated-power').val(total);
149+
$('#integrated-power').val(json.integratedpower);
150+
$('#integrated-power-unit').val(json.unit);
151+
$('#integrated-power-count').val(json.count);
152+
$('#integrated-power-powerflow').val(json.powerFlow);
83153
};
84154
dConnect.get(builder.build(), null, successCallback, pmAlertError);
85155
}
86156

87157
function doPowerMeterGetInstantaneousPower(serviceId){
88158
var builder = pmMakeUriBuilder(serviceId,'instantaneouspower');
159+
var unit = $('#unit-power').val();
160+
161+
if (unit != 'null_value') {
162+
builder.addParameter('unit', unit);
163+
}
164+
89165
var successCallback = function (json){
90166
console.log('Response: ', json);
91167
$('#instantaneous-power').val(json.instantaneouspower);
168+
$('#instantaneous-power-unit').val(json.unit);
169+
};
170+
dConnect.get(builder.build(), null, successCallback, pmAlertError);
171+
}
172+
173+
function doPowerMeterGetInstantaneousCurrent(serviceId){
174+
var builder = pmMakeUriBuilder(serviceId,'instantaneouscurrent');
175+
var unit = $('#unit-current').val();
176+
177+
if (unit != 'null_value') {
178+
builder.addParameter('unit', unit);
179+
}
180+
181+
var successCallback = function (json){
182+
console.log('Response: ', json);
183+
$('#instantaneous-current-r').val(json.instantaneouscurrent.rphase);
184+
$('#instantaneous-current-t').val(json.instantaneouscurrent.tphase);
185+
$('#instantaneous-current-unit').val(json.instantaneouscurrent.unit);
92186
};
93187
dConnect.get(builder.build(), null, successCallback, pmAlertError);
94188
}

dConnectSDKForJavascriptTest/dconnect-test-util.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ function initScopes() {
5353
'fabo',
5454
'mouse',
5555
'keyboard',
56-
'hogp'
56+
'hogp',
57+
'device'
5758

5859
);
5960
}

dConnectSDKForJavascriptTest/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ <H1>デバイスプラグインテスト</H1>
169169
<td><b>HOGPデバイスプラグイン</b></td>
170170
<td><button style="padding:10px;" type="button" name="テスト" onclick="onTestClick('tests/hogp_test.html');">テスト</button></td>
171171
</tr>
172+
<tr>
173+
<td><b>SmartMeterデバイスプラグイン</b></td>
174+
<td><button style="padding:10px;" type="button" name="テスト" onclick="onTestClick('tests/smartmeter_test.html');">テスト</button></td>
175+
</tr>
172176
</table>
173177
<H1>Javascript SDK テスト</H1>
174178
<table border="1" width="100%">
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
module('DeviceProfileAbnormalTest', {
2+
setup: function() {
3+
init();
4+
}
5+
});
6+
7+
/**
8+
* Deviceプロファイルの異常系テストを行うクラス。
9+
* @class
10+
*/
11+
var DeviceProfileAbnormalTest = {};
12+
13+
/**
14+
* 定義されていないPUTメソッドでアクセスするテストを行う。
15+
* <h3>【HTTP通信】</h3>
16+
* <p id='test'>
17+
* Method: PUT<br/>
18+
* Path: /device/pairing?serviceId=xxxx&accessToken=xxx<br/>
19+
* </p>
20+
* <h3>【期待する動作】</h3>
21+
* <p id='expected'>
22+
* ・resultに1が返ってくること。<br/>
23+
* </p>
24+
*/
25+
DeviceProfileAbnormalTest.pairingAbnormalTest001 = function(assert) {
26+
var accessToken = getCurrentAccessToken();
27+
var serviceId = getCurrentServiceId();
28+
var builder = new dConnect.URIBuilder();
29+
builder.setProfile('device');
30+
builder.setAttribute('pairing');
31+
builder.setServiceId(serviceId);
32+
builder.setAccessToken(accessToken);
33+
var uri = builder.build();
34+
dConnect.get(uri, null, function(json) {
35+
assert.ok(false, 'json: ' + JSON.stringify(json));
36+
QUnit.start();
37+
},
38+
function(errorCode, errorMessage) {
39+
if (errorCode == 8) {
40+
assert.ok(true, 'errorCode=' + errorCode + ', errorMessage=' + errorMessage);
41+
} else if (checkErrorCode(errorCode)) {
42+
assert.ok(true, 'not support');
43+
} else {
44+
assert.ok(false, 'errorCode=' + errorCode + ', errorMessage=' + errorMessage);
45+
}
46+
QUnit.start();
47+
});
48+
};
49+
QUnit.asyncTest('pairingAbnormalTest001(Calling a get method that does not support.)',
50+
DeviceProfileAbnormalTest.pairingAbnormalTest001);
51+
52+
/**
53+
* 定義されていないPUTメソッドでアクセスするテストを行う。
54+
* <h3>【HTTP通信】</h3>
55+
* <p id='test'>
56+
* Method: PUT<br/>
57+
* Path: /device/pairing?serviceId=xxxx&accessToken=xxx<br/>
58+
* </p>
59+
* <h3>【期待する動作】</h3>
60+
* <p id='expected'>
61+
* ・resultに1が返ってくること。<br/>
62+
* </p>
63+
*/
64+
DeviceProfileAbnormalTest.pairingAbnormalTest002 = function(assert) {
65+
var accessToken = getCurrentAccessToken();
66+
var serviceId = getCurrentServiceId();
67+
var builder = new dConnect.URIBuilder();
68+
builder.setProfile('device');
69+
builder.setAttribute('pairing');
70+
builder.setServiceId(serviceId);
71+
builder.setAccessToken(accessToken);
72+
var uri = builder.build();
73+
dConnect.put(uri, null, null, function(json) {
74+
assert.ok(false, 'json: ' + JSON.stringify(json));
75+
QUnit.start();
76+
},
77+
function(errorCode, errorMessage) {
78+
if (errorCode == 8) {
79+
assert.ok(true, 'errorCode=' + errorCode + ', errorMessage=' + errorMessage);
80+
} else if (checkErrorCode(errorCode)) {
81+
assert.ok(true, 'not support');
82+
} else {
83+
assert.ok(false, 'errorCode=' + errorCode + ', errorMessage=' + errorMessage);
84+
}
85+
QUnit.start();
86+
});
87+
};
88+
QUnit.asyncTest('pairingAbnormalTest002(Calling a put method that does not support.)',
89+
DeviceProfileAbnormalTest.pairingAbnormalTest002);

0 commit comments

Comments
 (0)