Skip to content

Commit

Permalink
Fixed async object creation
Browse files Browse the repository at this point in the history
  • Loading branch information
klein0r committed Feb 6, 2021
1 parent edfaa5b commit 267eaac
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class Youtube extends utils.Adapter {
timeout: 4500,
responseType: 'json'
}).then(
(response) => {
async (response) => {
this.log.debug('youtube/v3/search Request done - ' + id);
this.log.debug('received data (' + response.status + '): ' + JSON.stringify(response.data));

Expand All @@ -240,15 +240,15 @@ class Youtube extends utils.Adapter {
const v = content['items'][i];
const path = cpath + '.video.' + i + '.';

this.setObjectNotExists(path.slice(0, -1), { // remove trailing dot
await this.setObjectNotExists(path.slice(0, -1), { // remove trailing dot
type: 'channel',
common: {
name: 'Video data ' + (i + 1)
},
native: {}
});

this.setObjectNotExists(path + 'id', {
await this.setObjectNotExists(path + 'id', {
type: 'state',
common: {
name: 'Id',
Expand All @@ -261,7 +261,7 @@ class Youtube extends utils.Adapter {
});
this.setState(path + 'id', {val: v.id.videoId, ack: true});

this.setObjectNotExists(path + 'url', {
await this.setObjectNotExists(path + 'url', {
type: 'state',
common: {
name: 'URL',
Expand All @@ -274,7 +274,7 @@ class Youtube extends utils.Adapter {
});
this.setState(path + 'url', {val: 'https://youtu.be/' + v.id.videoId, ack: true});

this.setObjectNotExists(path + 'title', {
await this.setObjectNotExists(path + 'title', {
type: 'state',
common: {
name: 'Title',
Expand All @@ -287,7 +287,7 @@ class Youtube extends utils.Adapter {
});
this.setState(path + 'title', {val: v.snippet.title, ack: true});

this.setObjectNotExists(path + 'published', {
await this.setObjectNotExists(path + 'published', {
type: 'state',
common: {
name: 'Published',
Expand All @@ -300,7 +300,7 @@ class Youtube extends utils.Adapter {
});
this.setState(path + 'published', {val: new Date(v.snippet.publishedAt).getTime(), ack: true});

this.setObjectNotExists(path + 'description', {
await this.setObjectNotExists(path + 'description', {
type: 'state',
common: {
name: 'Description',
Expand Down Expand Up @@ -362,7 +362,7 @@ class Youtube extends utils.Adapter {

channelsKeep.push('channels.' + cleanChannelName);

this.setObjectNotExists('channels.' + cleanChannelName, {
await this.setObjectNotExists('channels.' + cleanChannelName, {
type: 'channel',
common: {
name: channel.name
Expand Down Expand Up @@ -395,8 +395,6 @@ class Youtube extends utils.Adapter {
});
}
}

this.stop();
}
);

Expand Down

0 comments on commit 267eaac

Please sign in to comment.