iobroker.squeezeboxrpc 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -2
- package/io-package.json +14 -66
- package/lib/ioUtil.js +310 -0
- package/lib/iosbplayer.js +1217 -922
- package/lib/iosbserver.js +1310 -877
- package/lib/squeezenode/squeezeplayer.js +55 -58
- package/lib/squeezenode/squeezerequest.js +73 -65
- package/lib/squeezenode/squeezeserver.js +77 -71
- package/lib/tools.js +27 -47
- package/package.json +5 -6
- package/squeezeboxrpc.js +25 -21
- package/widgets/package.json +13 -0
- package/widgets/squeezeboxrpc/i18n/en.json +43 -0
- package/widgets/squeezeboxrpc/i18n/translations.json +366 -0
- package/widgets/squeezeboxrpc/img/playlist.png +0 -0
- package/widgets/squeezeboxrpc/js/bundle.js +3 -0
- package/widgets/squeezeboxrpc/js/squeezeboxrpc-dist.js +2658 -0
- package/widgets/squeezeboxrpc/js/squeezeboxrpc.js +1581 -1203
- package/widgets/squeezeboxrpc/js/textImage.js +218 -71
- package/widgets/squeezeboxrpc.html +18 -3
package/README.md
CHANGED
|
@@ -438,6 +438,20 @@ you must connect the button to the player widget.
|
|
|
438
438
|
| Comma as separator | Advanced settings | A comma is used to separate the decimal places. |
|
|
439
439
|
| Thousands separator | Advanced settings | For large numbers, a separator is inserted every 3 places. |
|
|
440
440
|
|
|
441
|
+
### Playlist
|
|
442
|
+
|
|
443
|
+

|
|
444
|
+
|
|
445
|
+
Display the playlist from the server. If you click on an entry the playlist
|
|
446
|
+
is loaded and the player starts.
|
|
447
|
+
The widged dosent refresh automaticly, you have to press the refreshh button.
|
|
448
|
+
|
|
449
|
+
#### Attributes for Playlist
|
|
450
|
+
|
|
451
|
+
| Group | Attribute | Description |
|
|
452
|
+
| --------------------- | ----------------- | ----------------------------------------------------------------- |
|
|
453
|
+
| Player widget | General group | Selection of the player widget. |
|
|
454
|
+
|
|
441
455
|
## SendTo-Befehle
|
|
442
456
|
|
|
443
457
|
### cmdGeneral
|
|
@@ -451,7 +465,7 @@ _Alle Playlists:_
|
|
|
451
465
|
|
|
452
466
|
```js
|
|
453
467
|
async function main() {
|
|
454
|
-
let data = await sendToAsync("squeezeboxrpc.0", "
|
|
468
|
+
let data = await sendToAsync("squeezeboxrpc.0", "cmdGeneral", {
|
|
455
469
|
playerid: "",
|
|
456
470
|
cmdArray: ["playlists", "0", "999", "tags:us"],
|
|
457
471
|
});
|
|
@@ -466,7 +480,7 @@ Dieser Befehl wird vom Adapter intern verwendet, um die Favoriten zu laden.
|
|
|
466
480
|
|
|
467
481
|
```js
|
|
468
482
|
async function main() {
|
|
469
|
-
let data = await sendToAsync("squeezeboxrpc.0", "
|
|
483
|
+
let data = await sendToAsync("squeezeboxrpc.0", "cmdGeneral", {
|
|
470
484
|
playerid: "",
|
|
471
485
|
cmdArray: ["favorites", "items", "0", "999", "want_url:1", "item_id:"],
|
|
472
486
|
});
|
|
@@ -508,6 +522,11 @@ der folgenden CLI-Dokumentation enthalten:
|
|
|
508
522
|
### **WORK IN PROGRESS**
|
|
509
523
|
|
|
510
524
|
-->
|
|
525
|
+
### 1.5.0 (2024-11-28)
|
|
526
|
+
|
|
527
|
+
- Umstellung auf iobroker/eslint
|
|
528
|
+
- Neues Widget playlist
|
|
529
|
+
|
|
511
530
|
### 1.4.0 (2024-11-27)
|
|
512
531
|
|
|
513
532
|
- fix some missing objects errors
|
package/io-package.json
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"common": {
|
|
3
3
|
"name": "squeezeboxrpc",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.5.0",
|
|
5
5
|
"news": {
|
|
6
|
+
"1.5.0": {
|
|
7
|
+
"en": "Umstellung auf iobroker/eslint\nNeues Widget playlist",
|
|
8
|
+
"de": "Anpassung an iobroker/eslint\nNeues Widget Playlist",
|
|
9
|
+
"ru": "Umstellung auf iobroker/eslint\nNeues Widget playlist",
|
|
10
|
+
"pt": "Umstellung auf iobroker/eslint\nLista de reprodução de Neues Widget",
|
|
11
|
+
"nl": "Umstellung auf iobroker/eslint\nNeues widget-afspeellijst",
|
|
12
|
+
"fr": "Umstellung auf iobroker/ester\nListe de lecture Neues Widget",
|
|
13
|
+
"it": "Impiegazione\nPlaylist di Neues Widget",
|
|
14
|
+
"es": "Umstellung auf iobroker/eslint\nNeues Widget lista de reproducción",
|
|
15
|
+
"pl": "Umstellung auf iobroker / eslint\nNeues Widget playlist",
|
|
16
|
+
"uk": "Umstellung auf iobroker/eslint\nNeues Widget список відтворення",
|
|
17
|
+
"zh-cn": "Umstellung auf io 经纪人/雇员\nNeues 部件播放列表"
|
|
18
|
+
},
|
|
6
19
|
"1.4.0": {
|
|
7
20
|
"en": "fix some missing objects errors\nsanitize more playernames in syncgroups\nadd sendTo Command \"cmdGeneral\"\nsanitize more the playername\nimprove translation\nif trackartist is avail then write to artist if empty\nimprove handling for artwork_url\nmove widget documentation from html to markdown\nadjust responsive tab style\nimprove attribute widgets\nchange TPE2 handling once more\njsonConfig add sizing options for differenz screen sizes\ntest implementation of TPE2 handling. switch in settings\nadd datapoints album_artist, track_artist, artistOriginal",
|
|
8
21
|
"de": "einige fehlende objektfehler beheben\nsanitize mehr spielernamen in syncgroups\nsendTo Command \"cmdGeneral\" hinzufügen\nsanitize mehr der spielername\nverbesserung der übersetzung\nwenn trackartist in anspruch genommen wird, dann schreiben sie an künstler, wenn leer\nverbesserung der handhabung für artwork_url\nwidget-dokumentation von html zu markdown verschieben\npassive tab-stil anpassen\nwidgets des attributs verbessern\ntPE2 Handling erneut ändern\njsonConfig Hinzufügen von Größenoptionen für unterschiedliche Bildschirmgrößen\ntestdurchführung des TPE2-Handlings. Schalter in Einstellungen\ndatapoints album_artist, track_artist, artistOriginal",
|
|
@@ -16,71 +29,6 @@
|
|
|
16
29
|
"uk": "виправити деякі помилки відсутніх об'єктів\nдезінфікувати більше назв гравців у синкгрупах\nдодати команду \"Команда\"\nсатизувати більше ім'я гравця\nполіпшення перекладу\nякщо трактист - аваїл, то напишіть художника, якщо порожня\nпокращити роботу для арт-роботи_url\nперемістити документацію віджету з html для розмітки\nрегулюйте чуйний стиль вкладки\nполіпшення віджетів атрибутів\nзміна обробки TPE2 ще раз\njsonConfig add sizing options для різних розмірів екрана\nтестування впровадження TPE2 обробки. Перемикач в налаштуваннях\nдодавати альбоми/артист, трек_artist, художникOriginal",
|
|
17
30
|
"zh-cn": "修正一些缺失的对象错误\n在同步组中消毒更多玩家名\n添加发送到命令“ cmdGeneral ”\n更多消毒玩家名称\n改进翻译\n如果 trackartist 有用, 如果空则写给艺人\n改进对艺术品的处理_ url\n将部件文档从 html 移动到下标记\n调整响应标签样式\n改进属性部件\n再次更改TPE2处理\njsonConfig 添加不同屏幕大小的大小选项\n试验实施TPE2处理。 在设置中切换\n添加数据点相册_艺人,音轨_艺人,艺人"
|
|
18
31
|
},
|
|
19
|
-
"1.4.0-alpha.4": {
|
|
20
|
-
"en": "sanitize more the playername\nimprove translation",
|
|
21
|
-
"de": "sanitize mehr der spielername\nverbesserung der übersetzung",
|
|
22
|
-
"ru": "обезвредить больше имя игрока\nулучшить перевод",
|
|
23
|
-
"pt": "higienizar mais o nome do jogador\nmelhorar a tradução",
|
|
24
|
-
"nl": "de naam van de speler deactiveren\nverbeteren van de vertaling",
|
|
25
|
-
"fr": "désinfecter plus le nom du joueur\naméliorer la traduction",
|
|
26
|
-
"it": "sanitizzare più il nome del giocatore\nmigliorare la traduzione",
|
|
27
|
-
"es": "sanitize más el nombre de jugador\nmejorar la traducción",
|
|
28
|
-
"pl": "sanitize more the playername\npoprawić tłumaczenie",
|
|
29
|
-
"uk": "сатизувати більше ім'я гравця\nполіпшення перекладу",
|
|
30
|
-
"zh-cn": "更多消毒玩家名称\n改进翻译"
|
|
31
|
-
},
|
|
32
|
-
"1.4.0-alpha.3": {
|
|
33
|
-
"en": "if trackartist is avail then write to artist if empty",
|
|
34
|
-
"de": "wenn trackartist in anspruch genommen wird, dann schreiben sie an künstler, wenn leer",
|
|
35
|
-
"ru": "если трекартист воспользуется, тогда напишите художнику, если пустой",
|
|
36
|
-
"pt": "se trackartist é aproveitado então escreva para artista se vazio",
|
|
37
|
-
"nl": "als track artist beschikbaar is schrijf dan naar artiest indien leeg",
|
|
38
|
-
"fr": "si trackartist est disponible alors écrire à l'artiste si vide",
|
|
39
|
-
"it": "se trackartist è avail poi scrivere all'artista se vuoto",
|
|
40
|
-
"es": "si el trackartista está disponible entonces escriba al artista si está vacío",
|
|
41
|
-
"pl": "jeśli trackartist jest użyteczny, napisz do artysty jeśli pusty",
|
|
42
|
-
"uk": "якщо трактист - аваїл, то напишіть художника, якщо порожня",
|
|
43
|
-
"zh-cn": "如果 trackartist 有用, 如果空则写给艺人"
|
|
44
|
-
},
|
|
45
|
-
"1.4.0-alpha.2": {
|
|
46
|
-
"en": "improve handlying for artwork_url",
|
|
47
|
-
"de": "handlying für artwork_url verbessern",
|
|
48
|
-
"ru": "улучшение ручной работы для art_url",
|
|
49
|
-
"pt": "melhorar a mão para artifício_url",
|
|
50
|
-
"nl": "verbeteren van de handlying voor artwork_url",
|
|
51
|
-
"fr": "améliorer la main pour artwork_url",
|
|
52
|
-
"it": "migliorare la handlying per art_url",
|
|
53
|
-
"es": "mejorar el manual para artwork_url",
|
|
54
|
-
"pl": "poprawa obsługi dla grafiki _ url",
|
|
55
|
-
"uk": "покращувати ручне розміщення для artwork_url",
|
|
56
|
-
"zh-cn": "改进手动艺术工具_url"
|
|
57
|
-
},
|
|
58
|
-
"1.4.0-alpha.1": {
|
|
59
|
-
"en": "move widget documentation from html to markdown\nadjust responsive tab style\nimprove attribute widgets\nchange TPE2 handling once more",
|
|
60
|
-
"de": "widget-dokumentation von html zu markdown verschieben\npassive tab-stil anpassen\nwidgets des attributs verbessern\ntPE2 Handling erneut ändern",
|
|
61
|
-
"ru": "переместить документацию виджета из html в отметку\nнастроить адаптивный стиль вкладки\nулучшить виджеты атрибутов\nизменение TPE2 снова",
|
|
62
|
-
"pt": "mover documentação do widget de html para marcação\najustar o estilo de guia responsivo\nmelhorar os widgets de atributos\nmudar o manuseio TPE2 mais uma vez",
|
|
63
|
-
"nl": "widget-documentatie verplaatsen van html naar markdown\nresponsieve tabstijl aanpassen\nattribuutwidgets verbeteren\ntPE2-behandeling opnieuw wijzigen",
|
|
64
|
-
"fr": "déplacer la documentation de widget de html à balisage\najuster le style de l'onglet responsive\naméliorer les widgets d'attribut\nchanger la manipulation TPE2 une fois de plus",
|
|
65
|
-
"it": "spostare la documentazione del widget da html a markdown\nregolare stile di scheda reattiva\nmigliorare widget attributo\ncambiare la gestione di TPE2 ancora una volta",
|
|
66
|
-
"es": "mover la documentación del widget de html a marcadown\najuste estilo de pestaña sensible\nmejorar widgets de atributo\ncambio de manejo TPE2 una vez más",
|
|
67
|
-
"pl": "przenieść dokumentację widget z html do markdown\ndopasowanie odpowiadającego stylu karty\npoprawić widżety atrybutów\nzmienić obsługę TPE2 jeszcze raz",
|
|
68
|
-
"uk": "перемістити документацію віджету з html для розмітки\nрегулюйте чуйний стиль вкладки\nполіпшення віджетів атрибутів\nзміна обробки TPE2 ще раз",
|
|
69
|
-
"zh-cn": "将部件文档从 html 移动到下标记\n调整响应标签样式\n改进属性部件\n再次更改TPE2处理"
|
|
70
|
-
},
|
|
71
|
-
"1.4.0-alpha.0": {
|
|
72
|
-
"en": "jsonConfig add sizing options for differenz screen sizes\ntest implementation of TPE2 handling. switch in settings\nadd datapoints album_artist, track_artist, artistOriginal",
|
|
73
|
-
"de": "jsonConfig Hinzufügen von Größenoptionen für unterschiedliche Bildschirmgrößen\ntestdurchführung des TPE2-Handlings. Schalter in Einstellungen\ndatapoints album_artist, track_artist, artistOriginal",
|
|
74
|
-
"ru": "jsonConfig добавляет варианты калибровки для различных размеров экрана\nтестовая реализация обработки TPE2. выключение в настройках\nдобавить datapoints album_artist, track_artist, ArtistOriginal",
|
|
75
|
-
"pt": "jsonConfig adicionar opções de dimensionamento para diferentes tamanhos de tela\nimplementação de teste de manuseio TPE2. alternar em configurações\nadd datapoints album_artist, track_artist, artistOriginal",
|
|
76
|
-
"nl": "jsonConfig voeg grootte opties toe voor verschillende schermgroottes\ntestimplementatie van TPE2-behandeling. schakelaar in instellingen\ndatapoints album_artist, track_artist, artiestOriginal toevoegen",
|
|
77
|
-
"fr": "jsonConfig ajouter des options de dimensionnement pour différentes tailles d'écran\ntest de mise en œuvre de la manipulation TPE2. commutateur dans les paramètres\najouter datapoints album_artiste, track_artiste, artisteOriginal",
|
|
78
|
-
"it": "jsonConfig aggiungere opzioni di dimensionamento per diverseenz dimensioni dello schermo\nimplementazione del test di gestione TPE2. interruttore nelle impostazioni\naggiungere datapoints album_artist, track_artist, artistaOriginal",
|
|
79
|
-
"es": "jsonConfig añadir opciones de tamaño para diferentes tamaños de pantalla\naplicación de pruebas de manipulación TPE2. conmutar la configuración\nañadir datapoints album_artist, track_artist, artistOriginal",
|
|
80
|
-
"pl": "jsonConfig dodać opcje rozmiaru dla różnej wielkości ekranu\ntestowa realizacja obsługi TPE2. przełączanie w ustawieniach\nadd datapoints album _ artist, track _ artist, artistOriginal",
|
|
81
|
-
"uk": "jsonConfig add sizing options для різних розмірів екрана\nтестування впровадження TPE2 обробки. Перемикач в налаштуваннях\nдодавати альбоми/артист, трек_artist, художникOriginal",
|
|
82
|
-
"zh-cn": "jsonConfig 添加不同屏幕大小的大小选项\n试验实施TPE2处理。 在设置中切换\n添加数据点相册_艺人,音轨_艺人,艺人"
|
|
83
|
-
},
|
|
84
32
|
"1.3.17": {
|
|
85
33
|
"en": "add edit button to the vie index field of favorites widget",
|
|
86
34
|
"de": "fügen sie edit-taste in das vie-index-feld der favoriten widget",
|
package/lib/ioUtil.js
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* class with util function for object, state and log access
|
|
3
|
+
*/
|
|
4
|
+
class ioUtil {
|
|
5
|
+
/**
|
|
6
|
+
* The constructor for the ioUtil class
|
|
7
|
+
*
|
|
8
|
+
* @param adapter - the iobroker adapter
|
|
9
|
+
* @param islogdebug - flag for debug logging
|
|
10
|
+
* @param islogsilly - flag for verbose logging
|
|
11
|
+
*/
|
|
12
|
+
constructor(adapter, islogdebug, islogsilly) {
|
|
13
|
+
this.adapter = adapter;
|
|
14
|
+
this.islogsilly = islogsilly;
|
|
15
|
+
this.islogdebug = islogdebug;
|
|
16
|
+
this.observers = [];
|
|
17
|
+
this.doClose = false;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Asynchronously creates a channel object in the ioBroker system.
|
|
21
|
+
*
|
|
22
|
+
* @param stateTemplate - The template containing the common properties of the channel.
|
|
23
|
+
* @param level1path - The first level path to prepend to the channel name, can be null or empty.
|
|
24
|
+
* @param level2path - The second level path to prepend to the channel name, can be null or empty.
|
|
25
|
+
* @returns A promise that resolves when the channel object is set in the adapter.
|
|
26
|
+
*/
|
|
27
|
+
createObjectChannelAsync(stateTemplate, level1path, level2path) {
|
|
28
|
+
this.logdebug(`createObject ${stateTemplate.name}`);
|
|
29
|
+
const name = (level1path ? `${level1path}.` : '') + (level2path ? `${level2path}.` : '') + stateTemplate.name;
|
|
30
|
+
const newobj = {
|
|
31
|
+
type: 'channel',
|
|
32
|
+
common: stateTemplate,
|
|
33
|
+
native: {},
|
|
34
|
+
};
|
|
35
|
+
return this.adapter.setObjectAsync(name, newobj);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Asynchronously creates a state object in the ioBroker system.
|
|
39
|
+
*
|
|
40
|
+
* @param stateTemplate - The template containing the common properties of the state.
|
|
41
|
+
* @param level1path - The first level path to prepend to the state name, can be null or empty.
|
|
42
|
+
* @param level2path - The second level path to prepend to the state name, can be null or empty.
|
|
43
|
+
* @returns A promise that resolves when the state object is set in the adapter.
|
|
44
|
+
*/
|
|
45
|
+
createObjectAsync(stateTemplate, level1path, level2path) {
|
|
46
|
+
this.logdebug(`createObject ${stateTemplate.name}`);
|
|
47
|
+
const name = (level1path ? `${level1path}.` : '') + (level2path ? `${level2path}.` : '') + stateTemplate.name;
|
|
48
|
+
const newobj = {
|
|
49
|
+
type: 'state',
|
|
50
|
+
common: stateTemplate,
|
|
51
|
+
native: {},
|
|
52
|
+
};
|
|
53
|
+
return this.adapter.setObjectAsync(name, newobj);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Creates a state object in the ioBroker system if it does not already exist.
|
|
57
|
+
*
|
|
58
|
+
* @param stateTemplate - The template containing the common properties of the state.
|
|
59
|
+
* @param level1path - The first level path to prepend to the state name, can be null or empty.
|
|
60
|
+
* @param level2path - The second level path to prepend to the state name, can be null or empty.
|
|
61
|
+
* @param callback - Optional callback function, called when the object is created.
|
|
62
|
+
*/
|
|
63
|
+
createObjectState(stateTemplate, level1path, level2path, callback) {
|
|
64
|
+
this.logdebug(`createObject ${stateTemplate.name}`);
|
|
65
|
+
const name = (level1path ? `${level1path}.` : '') + (level2path ? `${level2path}.` : '') + stateTemplate.name;
|
|
66
|
+
this.adapter.getObject(name, (err, obj) => {
|
|
67
|
+
const newobj = {
|
|
68
|
+
type: 'state',
|
|
69
|
+
common: stateTemplate,
|
|
70
|
+
native: {},
|
|
71
|
+
};
|
|
72
|
+
if (!obj) {
|
|
73
|
+
callback ? this.adapter.setObject(name, newobj, callback) : this.adapter.setObject(name, newobj);
|
|
74
|
+
} else {
|
|
75
|
+
if (callback) {
|
|
76
|
+
callback();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Asynchronously deletes an object in the ioBroker system.
|
|
83
|
+
*
|
|
84
|
+
* @param id - The name of the object to delete.
|
|
85
|
+
* @param level1path - The first level path to prepend to the object name, can be null or empty.
|
|
86
|
+
* @param level2path - The second level path to prepend to the object name, can be null or empty.
|
|
87
|
+
* @returns A promise that resolves when the object is deleted.
|
|
88
|
+
*/
|
|
89
|
+
deleteObjectAsync(id, level1path, level2path) {
|
|
90
|
+
this.logdebug(`deleteObject ${id}`);
|
|
91
|
+
const name = (level1path ? `${level1path}.` : '') + (level2path ? `${level2path}.` : '') + id;
|
|
92
|
+
return this.adapter.delObject(name, { recursive: true });
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Deletes an object in the ioBroker system.
|
|
96
|
+
*
|
|
97
|
+
* @param id - The name of the object to delete.
|
|
98
|
+
* @param level1path - The first level path to prepend to the object name, can be null or empty.
|
|
99
|
+
* @param level2path - The second level path to prepend to the object name, can be null or empty.
|
|
100
|
+
* @param callback - Optional callback function, called when the object is deleted.
|
|
101
|
+
*/
|
|
102
|
+
deleteObject(id, level1path, level2path, callback) {
|
|
103
|
+
this.logdebug(`deleteObject ${id}`);
|
|
104
|
+
const name = (level1path ? `${level1path}.` : '') + (level2path ? `${level2path}.` : '') + id;
|
|
105
|
+
this.adapter.delObject(name, callback);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Asynchronously sets the state of an object in the ioBroker system.
|
|
109
|
+
*
|
|
110
|
+
* @param name - The name of the state to set.
|
|
111
|
+
* @param value - The value to set the state to.
|
|
112
|
+
* @param level1path - The first level path to prepend to the state name, can be null or empty.
|
|
113
|
+
* @param level2path - The second level path to prepend to the state name, can be null or empty.
|
|
114
|
+
* @returns A promise that resolves when the state is set in the adapter.
|
|
115
|
+
*/
|
|
116
|
+
setStateAsync(name, value, level1path, level2path) {
|
|
117
|
+
this.logdebug(`setState ${name}`);
|
|
118
|
+
name = (level1path ? `${level1path}.` : '') + (level2path ? `${level2path}.` : '') + name;
|
|
119
|
+
return this.adapter.setState(name, value, true); // jshint ignore:line
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Sets the state of an object in the ioBroker system, with ack=false.
|
|
123
|
+
*
|
|
124
|
+
* @param name - The name of the state to set.
|
|
125
|
+
* @param value - The value to set the state to.
|
|
126
|
+
* @param level1path - The first level path to prepend to the state name, can be null or empty.
|
|
127
|
+
* @param level2path - The second level path to prepend to the state name, can be null or empty.
|
|
128
|
+
* @param callback - Optional callback function, called when the state is set in the adapter, but without ack.
|
|
129
|
+
*/
|
|
130
|
+
setStateNack(name, value, level1path, level2path, callback) {
|
|
131
|
+
this.logdebug(`setState ${name} ${JSON.stringify(value)}`);
|
|
132
|
+
name = (level1path ? `${level1path}.` : '') + (level2path ? `${level2path}.` : '') + name;
|
|
133
|
+
callback ? this.adapter.setState(name, value, false, callback) : this.adapter.setState(name, value, true);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Gets all objects in the given path.
|
|
137
|
+
*
|
|
138
|
+
* @param path - The path to retrieve objects from.
|
|
139
|
+
* @returns A promise that resolves with an object containing all retrieved objects.
|
|
140
|
+
*/
|
|
141
|
+
async getObjects(path) {
|
|
142
|
+
const key = `${this.adapter.namespace}.${path}`;
|
|
143
|
+
return convertObjects(await this.adapter.getObjectListAsync({ startkey: key, endkey: `${key}\u9999` }));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Gets all states matching the given pattern in the given path.
|
|
148
|
+
*
|
|
149
|
+
* @param pattern - The pattern to match the state names with.
|
|
150
|
+
* @param level1path - The first level path to prepend to the state name, can be null or empty.
|
|
151
|
+
* @param level2path - The second level path to prepend to the state name, can be null or empty.
|
|
152
|
+
* @returns A promise that resolves with an object containing all retrieved states.
|
|
153
|
+
*/
|
|
154
|
+
async getStates(pattern, level1path, level2path) {
|
|
155
|
+
this.logdebug(`getStates ${pattern} ${level1path || ''} ${level2path || ''}`);
|
|
156
|
+
const name = (level1path ? `${level1path}.` : '') + (level2path ? `${level2path}.` : '') + pattern;
|
|
157
|
+
return await this.adapter.getStatesAsync(name);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Retrieves the state of an object in the ioBroker system.
|
|
161
|
+
*
|
|
162
|
+
* @param id - The name of the state to retrieve.
|
|
163
|
+
* @param level1path - The first level path to prepend to the state name, can be null or empty.
|
|
164
|
+
* @param level2path - The second level path to prepend to the state name, can be null or empty.
|
|
165
|
+
* @param callback - The callback function to call when the state is retrieved.
|
|
166
|
+
*/
|
|
167
|
+
getState(id, level1path = false, level2path = false, callback) {
|
|
168
|
+
this.logdebug(`getState ${id}`);
|
|
169
|
+
const name = (level1path ? `${level1path}.` : '') + (level2path ? `${level2path}.` : '') + id;
|
|
170
|
+
this.adapter.getState(name, callback);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Creates a state object in the ioBroker system.
|
|
174
|
+
*
|
|
175
|
+
* @param stateTemplate - The template containing the common properties of the state.
|
|
176
|
+
* @param level1path - The first level path to prepend to the state name, can be null or empty.
|
|
177
|
+
* @param level2path - The second level path to prepend to the state name, can be null or empty.
|
|
178
|
+
* @param callback - Optional callback function, called when the state is created.
|
|
179
|
+
*/
|
|
180
|
+
createState(stateTemplate, level1path = false, level2path = false, callback) {
|
|
181
|
+
this.logdebug(`createState ${stateTemplate.name}`);
|
|
182
|
+
const name = (level1path ? `${level1path}.` : '') + (level2path ? `${level2path}.` : '') + stateTemplate.name;
|
|
183
|
+
this.logdebug(`Create Key ${name}`);
|
|
184
|
+
this.adapter.createState(level1path, level2path, stateTemplate.name, stateTemplate, callback);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Sets the state of an object in the ioBroker system.
|
|
188
|
+
*
|
|
189
|
+
* @param name - The name of the state to set.
|
|
190
|
+
* @param value - The value to set the state to.
|
|
191
|
+
* @param level1path - The first level path to prepend to the state name, can be null or empty.
|
|
192
|
+
* @param level2path - The second level path to prepend to the state name, can be null or empty.
|
|
193
|
+
* @param [callback] - Optional callback function, called when the state is set in the adapter.
|
|
194
|
+
*/
|
|
195
|
+
setState(name, value, level1path, level2path, callback) {
|
|
196
|
+
this.logdebug(`setState ${name}: ${value}`);
|
|
197
|
+
name = (level1path ? `${level1path}.` : '') + (level2path ? `${level2path}.` : '') + name;
|
|
198
|
+
callback ? this.adapter.setState(name, value, true, callback) : this.adapter.setState(name, value, true); // jshint ignore:line
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Sets a timeout for a specified callback function and stores it in the observers object.
|
|
202
|
+
*
|
|
203
|
+
* @param id - Unique identifier for the timeout, used to manage and clear the timeout.
|
|
204
|
+
* @param callback - The function to execute after the specified time delay.
|
|
205
|
+
* @param time - The delay in milliseconds before executing the callback.
|
|
206
|
+
* @param arg1 - Optional first argument to pass to the callback function.
|
|
207
|
+
* @param arg2 - Optional second argument to pass to the callback function.
|
|
208
|
+
*/
|
|
209
|
+
setTimeout(id, callback, time, arg1 = null, arg2 = null) {
|
|
210
|
+
this.logsilly(`setTimeout ${id}`);
|
|
211
|
+
if (this.doClose) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
this.clearTimeout(id);
|
|
215
|
+
this.observers[id] = setTimeout(callback.bind(this), time, arg1, arg2);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Clears a timeout that was previously set using setTimeout.
|
|
219
|
+
*
|
|
220
|
+
* @param id - Unique identifier for the timeout to clear.
|
|
221
|
+
*/
|
|
222
|
+
clearTimeout(id) {
|
|
223
|
+
this.logsilly(`clearTimeout ${id}`);
|
|
224
|
+
if (this.observers[id]) {
|
|
225
|
+
clearTimeout(this.observers[id]);
|
|
226
|
+
}
|
|
227
|
+
delete this.observers[id];
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Clears an interval that was previously set using setInterval.
|
|
231
|
+
*
|
|
232
|
+
* @param id - Unique identifier for the interval to clear.
|
|
233
|
+
*/
|
|
234
|
+
clearInterval(id) {
|
|
235
|
+
this.logsilly(`clearInterval ${id}`);
|
|
236
|
+
if (this.observers[id]) {
|
|
237
|
+
clearInterval(this.observers[id]);
|
|
238
|
+
}
|
|
239
|
+
delete this.observers[id];
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Clears all timeouts and intervals that were previously set using setTimeout and setInterval.
|
|
243
|
+
*
|
|
244
|
+
* This is a convenience method to clear all observers at once.
|
|
245
|
+
*/
|
|
246
|
+
deleteObservers() {
|
|
247
|
+
this.logdebug('deleteObservers');
|
|
248
|
+
Object.keys(this.observers).map(i => this.clearTimeout(i));
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Closes all active connections by logging the action, deleting observers,
|
|
252
|
+
* and setting the doClose flag to true.
|
|
253
|
+
*/
|
|
254
|
+
closeConnections() {
|
|
255
|
+
this.logdebug('closeConnections');
|
|
256
|
+
this.deleteObservers();
|
|
257
|
+
this.doClose = true;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Logs a message at the silly log level if the adapter is configured for it.
|
|
261
|
+
*
|
|
262
|
+
* @param s - The message to log.
|
|
263
|
+
*/
|
|
264
|
+
logsilly(s) {
|
|
265
|
+
if (this.islogsilly) {
|
|
266
|
+
this.adapter.log.silly(s);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Logs a message at the debug log level if the adapter is configured for it.
|
|
271
|
+
*
|
|
272
|
+
* @param s - The message to log.
|
|
273
|
+
*/
|
|
274
|
+
logdebug(s) {
|
|
275
|
+
if (this.islogdebug) {
|
|
276
|
+
this.adapter.log.debug(s);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Logs a message at the error log level.
|
|
281
|
+
*
|
|
282
|
+
* @param s - The message to log.
|
|
283
|
+
*/
|
|
284
|
+
logerror(s) {
|
|
285
|
+
this.adapter.log.error(s);
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Logs a message at the info log level.
|
|
289
|
+
*
|
|
290
|
+
* @param s - The message to log.
|
|
291
|
+
*/
|
|
292
|
+
loginfo(s) {
|
|
293
|
+
this.adapter.log.info(s);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Converts an object list returned by getObjects or getObjectListAsync into a normal object with id as key.
|
|
298
|
+
*
|
|
299
|
+
* @param objects - The object list to convert.
|
|
300
|
+
* @returns The converted object.
|
|
301
|
+
*/
|
|
302
|
+
function convertObjects(objects) {
|
|
303
|
+
return objects.rows.reduce((acc, obj) => {
|
|
304
|
+
acc[obj.id] = obj;
|
|
305
|
+
return acc;
|
|
306
|
+
}, {});
|
|
307
|
+
}
|
|
308
|
+
module.exports = {
|
|
309
|
+
ioUtil,
|
|
310
|
+
};
|