Skip to content

Commit 8fc00d6

Browse files
Merge pull request #9 from devicehive/bugfix/#7
API type refs updated. Fix #7
2 parents 645bedd + 43088f0 commit 8fc00d6

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

lib/Device.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { getAPI, type } = require(`../src/api`);
1+
const { getAPI, getType } = require(`../src/api`);
22
const DeviceCommand = require(`./DeviceCommand`);
33
const DeviceNotification = require(`./DeviceNotification`);
44
let api;
@@ -231,7 +231,7 @@ class Device {
231231
* @memberof Device
232232
*/
233233
subscribeCommands(subscriber, commandFilter = {}){
234-
if (type === `ht`){
234+
if (getType() === `ht`){
235235
const filterKey = JSON.stringify(commandFilter);
236236
this._commandsSubscribers[filterKey] = subscriber;
237237
this._pollCommands(commandFilter);
@@ -250,7 +250,7 @@ class Device {
250250
* @memberof Device
251251
*/
252252
unsubscribeCommands(commandFilter={}){
253-
if (type === `ht`){
253+
if (getType() === `ht`){
254254
const filterKey = JSON.stringify(commandFilter);
255255
delete this._commandsSubscribers[filterKey];
256256
return Promise.resolve();
@@ -269,7 +269,7 @@ class Device {
269269
* @memberof Device
270270
*/
271271
subscribeNotifications(subscriber, notificationFilter = {}){
272-
if (type === `ht`){
272+
if (getType() === `ht`){
273273
const filterKey = JSON.stringify(notificationFilter);
274274
this._notificationsSubscribers[filterKey] = subscriber;
275275
this._pollNotifications(notificationFilter);
@@ -288,7 +288,7 @@ class Device {
288288
* @memberof Device
289289
*/
290290
unsubscribeNotifications(notificationFilter = {}){
291-
if (type === `ht`){
291+
if (getType() === `ht`){
292292
const filterKey = JSON.stringify(notificationFilter);
293293
delete this._notificationsSubscribers[filterKey];
294294
return Promise.resolve();

lib/DeviceCommand.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { getAPI, type } = require(`../src/api`);
1+
const { getAPI } = require(`../src/api`);
22
let api;
33

44
class DeviceCommand {

lib/DeviceHive.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { init, type } = require(`../src/api`);
1+
const { init, getType } = require(`../src/api`);
22
const Device = require(`./Device`);
33
const DeviceCommand = require(`./DeviceCommand`);
44
const DeviceNotification = require(`./DeviceNotification`);
@@ -334,7 +334,7 @@ class DeviceHive{
334334
*/
335335
subscribeCommands(deviceIds, subscriber, commandFilter){
336336
commandFilter.deviceIds = deviceIds;
337-
if (type === `ht`){
337+
if (getType() === `ht`){
338338
const filterKey = JSON.stringify(commandFilter);
339339
this._commandsSubscribers[filterKey] = subscriber;
340340
this._pollCommands(commandFilter);
@@ -354,7 +354,7 @@ class DeviceHive{
354354
*/
355355
unsubscribeCommands(deviceIds, commandFilter){
356356
commandFilter.deviceIds = deviceIds;
357-
if (type === `ht`){
357+
if (getType() === `ht`){
358358
const filterKey = JSON.stringify(commandFilter);
359359
delete this._commandsSubscribers[filterKey];
360360
return Promise.resolve();
@@ -378,7 +378,7 @@ class DeviceHive{
378378
*/
379379
subscribeNotifications(deviceIds, subscriber, notificationFilter){
380380
notificationFilter.deviceIds = deviceIds;
381-
if (type === `ht`){
381+
if (getType() === `ht`){
382382
const filterKey = JSON.stringify(notificationFilter);
383383
this._notificationsSubscribers[filterKey] = subscriber;
384384
this._pollNotifications(notificationFilter);
@@ -398,7 +398,7 @@ class DeviceHive{
398398
*/
399399
unsubscribeNotifications(deviceIds, notificationFilter){
400400
notificationFilter.deviceIds = deviceIds;
401-
if (type === `ht`){
401+
if (getType() === `ht`){
402402
const filterKey = JSON.stringify(notificationFilter);
403403
delete this._notificationsSubscribers[filterKey];
404404
return Promise.resolve();

src/api.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ function init(serverURL){
1717
}
1818
}
1919

20+
/**
21+
* Returns api type
22+
* @returns {*}
23+
*/
24+
function getType(){
25+
return type;
26+
}
27+
2028
/**
2129
* Returns current API
2230
*
@@ -33,5 +41,6 @@ function getAPI(){
3341
module.exports = {
3442
init,
3543
getAPI,
36-
type
44+
type,
45+
getType
3746
}

0 commit comments

Comments
 (0)