@iobroker/adapter-react-v5 7.2.3 → 7.2.6

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.
Files changed (375) hide show
  1. package/README.md +3 -3
  2. package/build/AdminConnection.d.ts +1 -0
  3. package/build/AdminConnection.js +2 -0
  4. package/build/AdminConnection.js.map +1 -0
  5. package/{src/Components/404.tsx → build/Components/404.js} +14 -39
  6. package/build/Components/404.js.map +1 -0
  7. package/{Components → build/Components}/ColorPicker.d.ts +2 -2
  8. package/{Components → build/Components}/ColorPicker.js +50 -65
  9. package/build/Components/ColorPicker.js.map +1 -0
  10. package/{Components → build/Components}/ComplexCron.d.ts +2 -2
  11. package/{Components → build/Components}/ComplexCron.js +43 -71
  12. package/build/Components/ComplexCron.js.map +1 -0
  13. package/{Components → build/Components}/CopyToClipboard.d.ts +1 -2
  14. package/{src/Components/CopyToClipboard.tsx → build/Components/CopyToClipboard.js} +20 -38
  15. package/build/Components/CopyToClipboard.js.map +1 -0
  16. package/{Components → build/Components}/CustomModal.d.ts +3 -3
  17. package/build/Components/CustomModal.js +60 -0
  18. package/build/Components/CustomModal.js.map +1 -0
  19. package/{Components → build/Components}/FileBrowser.d.ts +21 -21
  20. package/{Components → build/Components}/FileBrowser.js +253 -248
  21. package/build/Components/FileBrowser.js.map +1 -0
  22. package/build/Components/FileViewer.d.ts +48 -0
  23. package/build/Components/FileViewer.js +277 -0
  24. package/build/Components/FileViewer.js.map +1 -0
  25. package/{Components → build/Components}/Icon.d.ts +1 -1
  26. package/build/Components/Icon.js +140 -0
  27. package/build/Components/Icon.js.map +1 -0
  28. package/{Components → build/Components}/IconPicker.d.ts +2 -2
  29. package/build/Components/IconPicker.js +73 -0
  30. package/build/Components/IconPicker.js.map +1 -0
  31. package/{Components → build/Components}/IconSelector.d.ts +3 -3
  32. package/{Components → build/Components}/IconSelector.js +29 -57
  33. package/build/Components/IconSelector.js.map +1 -0
  34. package/{Components → build/Components}/Image.d.ts +2 -2
  35. package/{Components → build/Components}/Image.js +16 -22
  36. package/build/Components/Image.js.map +1 -0
  37. package/{Components → build/Components}/Loader.d.ts +2 -2
  38. package/{Components → build/Components}/Loader.js +15 -40
  39. package/build/Components/Loader.js.map +1 -0
  40. package/{Components → build/Components}/Loaders/MV.d.ts +2 -2
  41. package/build/Components/Loaders/MV.js +61 -0
  42. package/build/Components/Loaders/MV.js.map +1 -0
  43. package/{Components → build/Components}/Loaders/PT.d.ts +2 -2
  44. package/{Components → build/Components}/Loaders/PT.js +10 -35
  45. package/build/Components/Loaders/PT.js.map +1 -0
  46. package/{Components → build/Components}/Loaders/Vendor.d.ts +2 -2
  47. package/build/Components/Loaders/Vendor.js +52 -0
  48. package/build/Components/Loaders/Vendor.js.map +1 -0
  49. package/{Components → build/Components}/Logo.d.ts +2 -2
  50. package/build/Components/Logo.js +108 -0
  51. package/build/Components/Logo.js.map +1 -0
  52. package/{Components → build/Components}/MDUtils.d.ts +1 -2
  53. package/{Components → build/Components}/MDUtils.js +4 -9
  54. package/build/Components/MDUtils.js.map +1 -0
  55. package/{Components → build/Components}/ObjectBrowser.d.ts +7 -4
  56. package/{Components → build/Components}/ObjectBrowser.js +1183 -1133
  57. package/build/Components/ObjectBrowser.js.map +1 -0
  58. package/{Components → build/Components}/Router.d.ts +1 -2
  59. package/{Components → build/Components}/Router.js +6 -7
  60. package/build/Components/Router.js.map +1 -0
  61. package/{Components → build/Components}/SaveCloseButtons.d.ts +2 -2
  62. package/build/Components/SaveCloseButtons.js +65 -0
  63. package/build/Components/SaveCloseButtons.js.map +1 -0
  64. package/{Components → build/Components}/Schedule.d.ts +3 -3
  65. package/{Components → build/Components}/Schedule.js +246 -261
  66. package/build/Components/Schedule.js.map +1 -0
  67. package/{Components → build/Components}/SelectWithIcon.d.ts +2 -2
  68. package/build/Components/SelectWithIcon.js +135 -0
  69. package/build/Components/SelectWithIcon.js.map +1 -0
  70. package/build/Components/SimpleCron/cronText.js +15 -0
  71. package/build/Components/SimpleCron/cronText.js.map +1 -0
  72. package/{Components → build/Components}/SimpleCron/index.d.ts +2 -2
  73. package/{Components → build/Components}/SimpleCron/index.js +55 -56
  74. package/build/Components/SimpleCron/index.js.map +1 -0
  75. package/{Components → build/Components}/TabContainer.d.ts +2 -2
  76. package/build/Components/TabContainer.js +23 -0
  77. package/build/Components/TabContainer.js.map +1 -0
  78. package/{Components → build/Components}/TabContent.d.ts +3 -2
  79. package/build/Components/TabContent.js +20 -0
  80. package/build/Components/TabContent.js.map +1 -0
  81. package/build/Components/TabHeader.d.ts +6 -0
  82. package/build/Components/TabHeader.js +6 -0
  83. package/build/Components/TabHeader.js.map +1 -0
  84. package/{Components → build/Components}/TableResize.d.ts +2 -2
  85. package/{src/Components/TableResize.tsx → build/Components/TableResize.js} +64 -134
  86. package/build/Components/TableResize.js.map +1 -0
  87. package/{Components → build/Components}/TextWithIcon.d.ts +2 -2
  88. package/{src/Components/TextWithIcon.tsx → build/Components/TextWithIcon.js} +30 -75
  89. package/build/Components/TextWithIcon.js.map +1 -0
  90. package/{Components → build/Components}/ToggleThemeMenu.d.ts +1 -1
  91. package/build/Components/ToggleThemeMenu.js +13 -0
  92. package/build/Components/ToggleThemeMenu.js.map +1 -0
  93. package/{Components → build/Components}/TreeTable.d.ts +3 -3
  94. package/{Components → build/Components}/TreeTable.js +87 -99
  95. package/build/Components/TreeTable.js.map +1 -0
  96. package/{Components → build/Components}/UploadImage.d.ts +2 -2
  97. package/{Components → build/Components}/UploadImage.js +46 -69
  98. package/build/Components/UploadImage.js.map +1 -0
  99. package/{Components → build/Components}/Utils.d.ts +2 -2
  100. package/{Components → build/Components}/Utils.js +47 -60
  101. package/build/Components/Utils.js.map +1 -0
  102. package/build/Components/withWidth.d.ts +2 -0
  103. package/build/Components/withWidth.js +22 -0
  104. package/build/Components/withWidth.js.map +1 -0
  105. package/build/Connection.d.ts +1 -0
  106. package/build/Connection.js +2 -0
  107. package/build/Connection.js.map +1 -0
  108. package/{Dialogs → build/Dialogs}/ComplexCron.d.ts +2 -2
  109. package/build/Dialogs/ComplexCron.js +85 -0
  110. package/build/Dialogs/ComplexCron.js.map +1 -0
  111. package/{Dialogs → build/Dialogs}/Confirm.d.ts +2 -2
  112. package/build/Dialogs/Confirm.js +83 -0
  113. package/build/Dialogs/Confirm.js.map +1 -0
  114. package/{Dialogs → build/Dialogs}/Cron.d.ts +2 -2
  115. package/build/Dialogs/Cron.js +72 -0
  116. package/build/Dialogs/Cron.js.map +1 -0
  117. package/{Dialogs → build/Dialogs}/Error.d.ts +2 -2
  118. package/build/Dialogs/Error.js +27 -0
  119. package/build/Dialogs/Error.js.map +1 -0
  120. package/{Dialogs → build/Dialogs}/Message.d.ts +2 -2
  121. package/build/Dialogs/Message.js +29 -0
  122. package/build/Dialogs/Message.js.map +1 -0
  123. package/{Dialogs → build/Dialogs}/SelectFile.d.ts +2 -2
  124. package/build/Dialogs/SelectFile.js +116 -0
  125. package/build/Dialogs/SelectFile.js.map +1 -0
  126. package/{Dialogs → build/Dialogs}/SelectID.d.ts +3 -3
  127. package/{Dialogs → build/Dialogs}/SelectID.js +28 -53
  128. package/build/Dialogs/SelectID.js.map +1 -0
  129. package/{Dialogs → build/Dialogs}/SimpleCron.d.ts +2 -2
  130. package/build/Dialogs/SimpleCron.js +46 -0
  131. package/build/Dialogs/SimpleCron.js.map +1 -0
  132. package/build/Dialogs/TextInput.d.ts +2 -0
  133. package/build/Dialogs/TextInput.js +31 -0
  134. package/build/Dialogs/TextInput.js.map +1 -0
  135. package/{GenericApp.d.ts → build/GenericApp.d.ts} +2 -3
  136. package/{GenericApp.js → build/GenericApp.js} +162 -176
  137. package/build/GenericApp.js.map +1 -0
  138. package/{LegacyConnection.d.ts → build/LegacyConnection.d.ts} +69 -4
  139. package/{LegacyConnection.js → build/LegacyConnection.js} +106 -99
  140. package/build/LegacyConnection.js.map +1 -0
  141. package/{Prompt.d.ts → build/Prompt.d.ts} +1 -1
  142. package/{Prompt.js → build/Prompt.js} +3 -4
  143. package/build/Prompt.js.map +1 -0
  144. package/build/Theme.d.ts +5 -0
  145. package/{Theme.js → build/Theme.js} +37 -32
  146. package/build/Theme.js.map +1 -0
  147. package/build/assets/devices/parseNames.d.ts +0 -0
  148. package/build/assets/devices/parseNames.js +35 -0
  149. package/build/assets/devices/parseNames.js.map +1 -0
  150. package/build/assets/rooms/parseNames.d.ts +0 -0
  151. package/build/assets/rooms/parseNames.js +35 -0
  152. package/build/assets/rooms/parseNames.js.map +1 -0
  153. package/build/dictionary.d.ts +1 -0
  154. package/build/dictionary.js +25 -0
  155. package/build/dictionary.js.map +1 -0
  156. package/build/i18n/de.json +449 -0
  157. package/build/i18n/en.json +449 -0
  158. package/build/i18n/es.json +449 -0
  159. package/build/i18n/fr.json +449 -0
  160. package/build/i18n/it.json +449 -0
  161. package/build/i18n/nl.json +449 -0
  162. package/build/i18n/pl.json +449 -0
  163. package/build/i18n/pt.json +449 -0
  164. package/build/i18n/ru.json +449 -0
  165. package/build/i18n/uk.json +449 -0
  166. package/build/i18n/zh-cn.json +449 -0
  167. package/{i18n.d.ts → build/i18n.d.ts} +2 -2
  168. package/{i18n.js → build/i18n.js} +9 -11
  169. package/build/i18n.js.map +1 -0
  170. package/build/icons/IconAdapter.d.ts +3 -0
  171. package/build/icons/IconAdapter.js +6 -0
  172. package/build/icons/IconAdapter.js.map +1 -0
  173. package/build/icons/IconAlias.d.ts +3 -0
  174. package/build/icons/IconAlias.js +6 -0
  175. package/build/icons/IconAlias.js.map +1 -0
  176. package/build/icons/IconChannel.d.ts +3 -0
  177. package/build/icons/IconChannel.js +9 -0
  178. package/build/icons/IconChannel.js.map +1 -0
  179. package/build/icons/IconClearFilter.d.ts +3 -0
  180. package/build/icons/IconClearFilter.js +7 -0
  181. package/build/icons/IconClearFilter.js.map +1 -0
  182. package/build/icons/IconClosed.d.ts +3 -0
  183. package/build/icons/IconClosed.js +6 -0
  184. package/build/icons/IconClosed.js.map +1 -0
  185. package/build/icons/IconCopy.d.ts +3 -0
  186. package/build/icons/IconCopy.js +5 -0
  187. package/build/icons/IconCopy.js.map +1 -0
  188. package/build/icons/IconDevice.d.ts +3 -0
  189. package/build/icons/IconDevice.js +15 -0
  190. package/build/icons/IconDevice.js.map +1 -0
  191. package/build/icons/IconDocument.d.ts +3 -0
  192. package/build/icons/IconDocument.js +6 -0
  193. package/build/icons/IconDocument.js.map +1 -0
  194. package/build/icons/IconDocumentReadOnly.d.ts +3 -0
  195. package/build/icons/IconDocumentReadOnly.js +7 -0
  196. package/build/icons/IconDocumentReadOnly.js.map +1 -0
  197. package/build/icons/IconExpert.d.ts +3 -0
  198. package/build/icons/IconExpert.js +6 -0
  199. package/build/icons/IconExpert.js.map +1 -0
  200. package/build/icons/IconFx.d.ts +3 -0
  201. package/build/icons/IconFx.js +5 -0
  202. package/build/icons/IconFx.js.map +1 -0
  203. package/build/icons/IconInstance.d.ts +3 -0
  204. package/build/icons/IconInstance.js +6 -0
  205. package/build/icons/IconInstance.js.map +1 -0
  206. package/build/icons/IconLogout.d.ts +3 -0
  207. package/build/icons/IconLogout.js +6 -0
  208. package/build/icons/IconLogout.js.map +1 -0
  209. package/build/icons/IconNoIcon.d.ts +3 -0
  210. package/build/icons/IconNoIcon.js +5 -0
  211. package/build/icons/IconNoIcon.js.map +1 -0
  212. package/build/icons/IconOpen.d.ts +3 -0
  213. package/build/icons/IconOpen.js +6 -0
  214. package/build/icons/IconOpen.js.map +1 -0
  215. package/{icons → build/icons}/IconProps.d.ts +1 -1
  216. package/build/icons/IconProps.js +2 -0
  217. package/build/icons/IconProps.js.map +1 -0
  218. package/build/icons/IconState.d.ts +3 -0
  219. package/build/icons/IconState.js +6 -0
  220. package/build/icons/IconState.js.map +1 -0
  221. package/build/index.d.ts +67 -0
  222. package/build/index.js +67 -0
  223. package/build/index.js.map +1 -0
  224. package/{types.d.ts → build/types.d.ts} +1 -1
  225. package/package.json +84 -47
  226. package/AdminConnection.d.ts +0 -2
  227. package/AdminConnection.js +0 -4
  228. package/Components/404.js +0 -101
  229. package/Components/CopyToClipboard.js +0 -163
  230. package/Components/CustomModal.js +0 -88
  231. package/Components/FileViewer.d.ts +0 -10
  232. package/Components/FileViewer.js +0 -305
  233. package/Components/Icon.js +0 -148
  234. package/Components/IconPicker.js +0 -98
  235. package/Components/Loaders/MV.js +0 -66
  236. package/Components/Loaders/Vendor.js +0 -77
  237. package/Components/Logo.js +0 -117
  238. package/Components/SaveCloseButtons.js +0 -69
  239. package/Components/SelectWithIcon.js +0 -168
  240. package/Components/SimpleCron/cronText.js +0 -19
  241. package/Components/TabContainer.js +0 -25
  242. package/Components/TabContent.js +0 -21
  243. package/Components/TabHeader.d.ts +0 -6
  244. package/Components/TabHeader.js +0 -11
  245. package/Components/TableResize.js +0 -226
  246. package/Components/TextWithIcon.js +0 -119
  247. package/Components/ToggleThemeMenu.js +0 -18
  248. package/Components/withWidth.d.ts +0 -3
  249. package/Components/withWidth.js +0 -27
  250. package/Connection.d.ts +0 -3
  251. package/Connection.js +0 -8
  252. package/Dialogs/ComplexCron.js +0 -90
  253. package/Dialogs/Confirm.js +0 -111
  254. package/Dialogs/Cron.js +0 -100
  255. package/Dialogs/Error.js +0 -55
  256. package/Dialogs/Message.js +0 -57
  257. package/Dialogs/SelectFile.js +0 -119
  258. package/Dialogs/SimpleCron.js +0 -51
  259. package/Dialogs/TextInput.d.ts +0 -3
  260. package/Dialogs/TextInput.js +0 -35
  261. package/Theme.d.ts +0 -6
  262. package/i18n/de.json +0 -449
  263. package/i18n/en.json +0 -449
  264. package/i18n/es.json +0 -449
  265. package/i18n/fr.json +0 -449
  266. package/i18n/it.json +0 -449
  267. package/i18n/nl.json +0 -449
  268. package/i18n/pl.json +0 -449
  269. package/i18n/pt.json +0 -449
  270. package/i18n/ru.json +0 -449
  271. package/i18n/uk.json +0 -449
  272. package/i18n/zh-cn.json +0 -449
  273. package/icons/IconAdapter.d.ts +0 -4
  274. package/icons/IconAdapter.js +0 -10
  275. package/icons/IconAlias.d.ts +0 -4
  276. package/icons/IconAlias.js +0 -10
  277. package/icons/IconChannel.d.ts +0 -4
  278. package/icons/IconChannel.js +0 -13
  279. package/icons/IconClearFilter.d.ts +0 -4
  280. package/icons/IconClearFilter.js +0 -11
  281. package/icons/IconClosed.d.ts +0 -4
  282. package/icons/IconClosed.js +0 -10
  283. package/icons/IconCopy.d.ts +0 -4
  284. package/icons/IconCopy.js +0 -9
  285. package/icons/IconDevice.d.ts +0 -4
  286. package/icons/IconDevice.js +0 -19
  287. package/icons/IconDocument.d.ts +0 -4
  288. package/icons/IconDocument.js +0 -10
  289. package/icons/IconDocumentReadOnly.d.ts +0 -4
  290. package/icons/IconDocumentReadOnly.js +0 -11
  291. package/icons/IconExpert.d.ts +0 -4
  292. package/icons/IconExpert.js +0 -10
  293. package/icons/IconFx.d.ts +0 -4
  294. package/icons/IconFx.js +0 -9
  295. package/icons/IconInstance.d.ts +0 -4
  296. package/icons/IconInstance.js +0 -10
  297. package/icons/IconLogout.d.ts +0 -4
  298. package/icons/IconLogout.js +0 -10
  299. package/icons/IconNoIcon.d.ts +0 -4
  300. package/icons/IconNoIcon.js +0 -9
  301. package/icons/IconOpen.d.ts +0 -4
  302. package/icons/IconOpen.js +0 -10
  303. package/icons/IconProps.js +0 -2
  304. package/icons/IconState.d.ts +0 -4
  305. package/icons/IconState.js +0 -10
  306. package/index.d.ts +0 -128
  307. package/index.js +0 -215
  308. package/src/AdminConnection.tsx +0 -3
  309. package/src/Components/ColorPicker.tsx +0 -343
  310. package/src/Components/ComplexCron.tsx +0 -561
  311. package/src/Components/CustomModal.tsx +0 -170
  312. package/src/Components/FileBrowser.tsx +0 -2550
  313. package/src/Components/FileViewer.tsx +0 -412
  314. package/src/Components/Icon.tsx +0 -238
  315. package/src/Components/IconPicker.tsx +0 -165
  316. package/src/Components/IconSelector.tsx +0 -2220
  317. package/src/Components/Image.tsx +0 -193
  318. package/src/Components/Loader.tsx +0 -328
  319. package/src/Components/Logo.tsx +0 -176
  320. package/src/Components/MDUtils.tsx +0 -104
  321. package/src/Components/ObjectBrowser.tsx +0 -8935
  322. package/src/Components/Router.tsx +0 -90
  323. package/src/Components/SaveCloseButtons.tsx +0 -117
  324. package/src/Components/Schedule.tsx +0 -1995
  325. package/src/Components/SelectWithIcon.tsx +0 -239
  326. package/src/Components/TabContainer.tsx +0 -57
  327. package/src/Components/TabContent.tsx +0 -38
  328. package/src/Components/TabHeader.tsx +0 -20
  329. package/src/Components/ToggleThemeMenu.tsx +0 -52
  330. package/src/Components/TreeTable.tsx +0 -1002
  331. package/src/Components/UploadImage.tsx +0 -643
  332. package/src/Components/Utils.tsx +0 -1802
  333. package/src/Components/loader.css +0 -231
  334. package/src/Components/withWidth.tsx +0 -32
  335. package/src/Connection.tsx +0 -5
  336. package/src/Dialogs/ComplexCron.tsx +0 -163
  337. package/src/Dialogs/Confirm.tsx +0 -185
  338. package/src/Dialogs/Cron.tsx +0 -192
  339. package/src/Dialogs/Error.tsx +0 -67
  340. package/src/Dialogs/Message.tsx +0 -73
  341. package/src/Dialogs/SelectFile.tsx +0 -280
  342. package/src/Dialogs/SelectID.tsx +0 -310
  343. package/src/Dialogs/SimpleCron.tsx +0 -101
  344. package/src/Dialogs/TextInput.tsx +0 -99
  345. package/src/GenericApp.tsx +0 -1076
  346. package/src/LegacyConnection.tsx +0 -3720
  347. package/src/Prompt.tsx +0 -22
  348. package/src/Theme.tsx +0 -472
  349. package/src/icons/IconAdapter.tsx +0 -22
  350. package/src/icons/IconAlias.tsx +0 -22
  351. package/src/icons/IconChannel.tsx +0 -60
  352. package/src/icons/IconClearFilter.tsx +0 -24
  353. package/src/icons/IconClosed.tsx +0 -22
  354. package/src/icons/IconCopy.tsx +0 -21
  355. package/src/icons/IconDevice.tsx +0 -126
  356. package/src/icons/IconDocument.tsx +0 -22
  357. package/src/icons/IconDocumentReadOnly.tsx +0 -27
  358. package/src/icons/IconExpert.tsx +0 -26
  359. package/src/icons/IconFx.tsx +0 -38
  360. package/src/icons/IconInstance.tsx +0 -22
  361. package/src/icons/IconLogout.tsx +0 -32
  362. package/src/icons/IconNoIcon.tsx +0 -21
  363. package/src/icons/IconOpen.tsx +0 -22
  364. package/src/icons/IconProps.tsx +0 -16
  365. package/src/icons/IconState.tsx +0 -38
  366. package/src/index.css +0 -56
  367. /package/{Components → build/Components}/404.d.ts +0 -0
  368. /package/{Components → build/Components}/SimpleCron/cronText.d.ts +0 -0
  369. /package/{assets → build/assets}/devices.json +0 -0
  370. /package/{assets → build/assets}/lamp_ceiling.svg +0 -0
  371. /package/{assets → build/assets}/lamp_table.svg +0 -0
  372. /package/{assets → build/assets}/no_icon.svg +0 -0
  373. /package/{assets → build/assets}/rooms.json +0 -0
  374. /package/{index.css → build/index.css} +0 -0
  375. /package/{tasks.js → tasksExample.js} +0 -0
@@ -1,1802 +0,0 @@
1
- /**
2
- * Copyright 2018-2024 Denis Haev <dogafox@gmail.com>
3
- *
4
- * MIT License
5
- *
6
- */
7
- import React from 'react';
8
- import copy from './CopyToClipboard';
9
- import I18n from '../i18n';
10
- import type { IobTheme, ThemeName, ThemeType } from '../types';
11
-
12
- const NAMESPACE = 'material';
13
- const days = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'];
14
- const months = ['Jan', 'Feb', 'Mar', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
15
- const QUALITY_BITS: Record<ioBroker.STATE_QUALITY[keyof ioBroker.STATE_QUALITY], string> = {
16
- 0x00: '0x00 - good',
17
-
18
- 0x01: '0x01 - general problem',
19
- 0x02: '0x02 - no connection problem',
20
-
21
- 0x10: '0x10 - substitute value from controller',
22
- 0x20: '0x20 - substitute initial value',
23
- 0x40: '0x40 - substitute value from device or instance',
24
- 0x80: '0x80 - substitute value from sensor',
25
-
26
- 0x11: '0x11 - general problem by instance',
27
- 0x41: '0x41 - general problem by device',
28
- 0x81: '0x81 - general problem by sensor',
29
-
30
- 0x12: '0x12 - instance not connected',
31
- 0x42: '0x42 - device not connected',
32
- 0x82: '0x82 - sensor not connected',
33
-
34
- 0x44: '0x44 - device reports error',
35
- 0x84: '0x84 - sensor reports error',
36
- };
37
- const SIGNATURES: Record<string, string> = {
38
- JVBERi0: 'pdf',
39
- R0lGODdh: 'gif',
40
- R0lGODlh: 'gif',
41
- iVBORw0KGgo: 'png',
42
- '/9j/': 'jpg',
43
- PHN2Zw: 'svg',
44
- Qk1: 'bmp',
45
- AAABAA: 'ico', // 00 00 01 00 according to https://en.wikipedia.org/wiki/List_of_file_signatures
46
- };
47
-
48
- type SmartName =
49
- | null
50
- | false
51
- | string
52
- | ({ [lang in ioBroker.Languages]?: string } & {
53
- /** Which kind of device it is */
54
- smartType?: string | null;
55
- /** Which value to set when the ON command is issued */
56
- byON?: string | null;
57
- });
58
-
59
- type ClassDictionary = Record<string, any>;
60
- type ClassValue = ClassArray | ClassDictionary | string | number | null | boolean | undefined;
61
- type ClassArray = ClassValue[];
62
-
63
- class Utils {
64
- static namespace = NAMESPACE;
65
-
66
- static INSTANCES = 'instances';
67
-
68
- static dateFormat = ['DD', 'MM'];
69
-
70
- static FORBIDDEN_CHARS = /[^._\-/ :!#$%&()+=@^{}|~\p{Ll}\p{Lu}\p{Nd}]+/gu;
71
-
72
- /**
73
- * Capitalize words.
74
- */
75
- static CapitalWords(name: string | null | undefined): string {
76
- return (name || '')
77
- .split(/[\s_]/)
78
- .filter(item => item)
79
- .map(word => (word ? word[0].toUpperCase() + word.substring(1).toLowerCase() : ''))
80
- .join(' ');
81
- }
82
-
83
- static formatSeconds(seconds: number): string {
84
- const days_ = Math.floor(seconds / (3600 * 24));
85
- seconds %= 3600 * 24;
86
-
87
- const hours = Math.floor(seconds / 3600)
88
- .toString()
89
- .padStart(2, '0');
90
- seconds %= 3600;
91
-
92
- const minutes = Math.floor(seconds / 60)
93
- .toString()
94
- .padStart(2, '0');
95
- seconds %= 60;
96
-
97
- const secondsStr = Math.floor(seconds).toString().padStart(2, '0');
98
-
99
- let text = '';
100
- if (days_) {
101
- text += `${days_} ${I18n.t('ra_daysShortText')} `;
102
- }
103
- text += `${hours}:${minutes}:${secondsStr}`;
104
-
105
- return text;
106
- }
107
-
108
- /**
109
- * Get the name of the object by id from the name or description.
110
- */
111
- static getObjectName(
112
- objects: Record<string, ioBroker.Object>,
113
- id: string,
114
- settings?: { name: ioBroker.StringOrTranslated } | ioBroker.Languages | null,
115
- options?: { language?: ioBroker.Languages },
116
- /** Set to true to get the description. */
117
- isDesc?: boolean,
118
- ): string {
119
- const item = objects[id];
120
- let text: string | undefined;
121
-
122
- if (typeof settings === 'string' && !options) {
123
- options = { language: settings };
124
- settings = null;
125
- }
126
-
127
- options = options || {};
128
- if (!options.language) {
129
- options.language =
130
- (objects['system.config'] &&
131
- objects['system.config'].common &&
132
- objects['system.config'].common.language) ||
133
- window.sysLang ||
134
- 'en';
135
- }
136
- if ((settings as { name: ioBroker.StringOrTranslated })?.name) {
137
- const textObj = (settings as { name: ioBroker.StringOrTranslated }).name;
138
- if (typeof textObj === 'object') {
139
- text = (options.language && textObj[options.language]) || textObj.en;
140
- } else {
141
- text = textObj;
142
- }
143
- } else if (isDesc && item?.common?.desc) {
144
- const textObj = item.common.desc;
145
- if (typeof textObj === 'object') {
146
- text = (options.language && textObj[options.language]) || textObj.en || textObj.de || textObj.ru || '';
147
- } else {
148
- text = textObj;
149
- }
150
- text = (text || '').toString().replace(/[_.]/g, ' ');
151
-
152
- if (text === text.toUpperCase()) {
153
- text = text[0] + text.substring(1).toLowerCase();
154
- }
155
- } else if (!isDesc && item?.common) {
156
- const textObj = item.common.name || item.common.desc;
157
- if (textObj && typeof textObj === 'object') {
158
- text = (options.language && textObj[options.language]) || textObj.en || textObj.de || textObj.ru || '';
159
- } else {
160
- text = textObj as string;
161
- }
162
- text = (text || '').toString().replace(/[_.]/g, ' ');
163
-
164
- if (text === text.toUpperCase()) {
165
- text = text[0] + text.substring(1).toLowerCase();
166
- }
167
- } else {
168
- const pos = id.lastIndexOf('.');
169
- text = id.substring(pos + 1).replace(/[_.]/g, ' ');
170
- text = Utils.CapitalWords(text);
171
- }
172
-
173
- return text?.trim() || '';
174
- }
175
-
176
- /**
177
- * Get the name of the object from the name or description.
178
- */
179
- static getObjectNameFromObj(
180
- obj: ioBroker.PartialObject,
181
- /** settings or language */
182
- settings: { name: ioBroker.StringOrTranslated } | ioBroker.Languages | null,
183
- options?: { language?: ioBroker.Languages },
184
- /** Set to true to get the description. */
185
- isDesc?: boolean,
186
- /** Allow using spaces in name (by edit) */
187
- noTrim?: boolean,
188
- ): string {
189
- const item = obj;
190
- let text = (obj && obj._id) || '';
191
-
192
- if (typeof settings === 'string' && !options) {
193
- options = { language: settings };
194
- settings = null;
195
- }
196
-
197
- options = options || {};
198
-
199
- if ((settings as { name: ioBroker.StringOrTranslated })?.name) {
200
- const name = (settings as { name: ioBroker.StringOrTranslated }).name;
201
- if (typeof name === 'object') {
202
- text = (options.language && name[options.language]) || name.en;
203
- } else {
204
- text = name;
205
- }
206
- } else if (isDesc && item?.common?.desc) {
207
- const desc: ioBroker.StringOrTranslated = item.common.desc;
208
- if (typeof desc === 'object') {
209
- text = (options.language && desc[options.language]) || desc.en;
210
- } else {
211
- text = desc;
212
- }
213
- text = (text || '').toString().replace(/[_.]/g, ' ');
214
-
215
- if (text === text.toUpperCase()) {
216
- text = text[0] + text.substring(1).toLowerCase();
217
- }
218
- } else if (!isDesc && item?.common?.name) {
219
- let name = item.common.name;
220
- if (!name && item.common.desc) {
221
- name = item.common.desc;
222
- }
223
- if (typeof name === 'object') {
224
- text = (options.language && name[options.language]) || name.en;
225
- } else {
226
- text = name;
227
- }
228
- text = (text || '').toString().replace(/[_.]/g, ' ');
229
-
230
- if (text === text.toUpperCase()) {
231
- text = text[0] + text.substring(1).toLowerCase();
232
- }
233
- }
234
- return noTrim ? text : text.trim();
235
- }
236
-
237
- /**
238
- * Extracts from the object material settings, depends on username
239
- */
240
- static getSettingsOrder(
241
- obj: ioBroker.StateObject | ioBroker.StateCommon,
242
- forEnumId: string,
243
- options: { user?: string },
244
- ): string | null {
245
- let common: ioBroker.StateCommon | undefined;
246
- if (obj && Object.prototype.hasOwnProperty.call(obj, 'common')) {
247
- common = (obj as ioBroker.StateObject).common;
248
- } else {
249
- common = obj as any as ioBroker.StateCommon;
250
- }
251
- let settings;
252
- if (common?.custom) {
253
- settings = common.custom[NAMESPACE];
254
- const user = options.user || 'admin';
255
- if (settings && settings[user]) {
256
- if (forEnumId) {
257
- if (settings[user].subOrder && settings[user].subOrder[forEnumId]) {
258
- return JSON.parse(JSON.stringify(settings[user].subOrder[forEnumId]));
259
- }
260
- } else if (settings[user].order) {
261
- return JSON.parse(JSON.stringify(settings[user].order));
262
- }
263
- }
264
- }
265
- return null;
266
- }
267
-
268
- /**
269
- Used in material
270
- */
271
- static getSettingsCustomURLs(
272
- obj: ioBroker.StateObject | ioBroker.StateCommon,
273
- forEnumId: string,
274
- options: { user?: string },
275
- ): string | null {
276
- let common: ioBroker.StateCommon | undefined;
277
- if (obj && Object.prototype.hasOwnProperty.call(obj, 'common')) {
278
- common = (obj as ioBroker.StateObject).common;
279
- } else {
280
- common = obj as any as ioBroker.StateCommon;
281
- }
282
- let settings;
283
- if (common?.custom) {
284
- settings = common.custom[NAMESPACE];
285
- const user = options.user || 'admin';
286
- if (settings && settings[user]) {
287
- if (forEnumId) {
288
- if (settings[user].subURLs && settings[user].subURLs[forEnumId]) {
289
- return JSON.parse(JSON.stringify(settings[user].subURLs[forEnumId]));
290
- }
291
- } else if (settings[user].URLs) {
292
- return JSON.parse(JSON.stringify(settings[user].URLs));
293
- }
294
- }
295
- }
296
- return null;
297
- }
298
-
299
- /**
300
- * Reorder the array items in list between source and dest.
301
- */
302
- static reorder(list: Iterable<any> | ArrayLike<any>, source: number, dest: number): Iterable<any> | ArrayLike<any> {
303
- const result = Array.from(list);
304
- const [removed] = result.splice(source, 1);
305
- result.splice(dest, 0, removed);
306
- return result;
307
- }
308
-
309
- /**
310
- Get smart name settings for the given object.
311
- */
312
- static getSettings(
313
- obj: ioBroker.StateObject | ioBroker.StateCommon,
314
- options: {
315
- id?: string;
316
- user?: string;
317
- name?: ioBroker.StringOrTranslated;
318
- icon?: string;
319
- color?: string;
320
- language?: ioBroker.Languages;
321
- },
322
- defaultEnabling?: boolean,
323
- ): {
324
- name: string;
325
- enabled?: boolean;
326
- useCustom?: boolean;
327
- icon?: string;
328
- color?: string;
329
- } {
330
- let settings;
331
- const id = (obj as ioBroker.StateObject)?._id || options?.id;
332
- let common: ioBroker.StateCommon | undefined;
333
- if (obj && Object.prototype.hasOwnProperty.call(obj, 'common')) {
334
- common = (obj as ioBroker.StateObject).common;
335
- } else {
336
- common = obj as ioBroker.StateCommon;
337
- }
338
- if (common?.custom) {
339
- settings = common.custom;
340
- settings =
341
- settings[NAMESPACE] && settings[NAMESPACE][options.user || 'admin']
342
- ? JSON.parse(JSON.stringify(settings[NAMESPACE][options.user || 'admin']))
343
- : { enabled: true };
344
- } else {
345
- settings = { enabled: defaultEnabling === undefined ? true : defaultEnabling, useCustom: false };
346
- }
347
-
348
- if (!Object.prototype.hasOwnProperty.call(settings, 'enabled')) {
349
- settings.enabled = defaultEnabling === undefined ? true : defaultEnabling;
350
- }
351
-
352
- if (options) {
353
- if (!settings.name && options.name) {
354
- settings.name = options.name;
355
- }
356
- if (!settings.icon && options.icon) {
357
- settings.icon = options.icon;
358
- }
359
- if (!settings.color && options.color) {
360
- settings.color = options.color;
361
- }
362
- }
363
-
364
- if (common) {
365
- if (!settings.color && common.color) {
366
- settings.color = common.color;
367
- }
368
- if (!settings.icon && common.icon) {
369
- settings.icon = common.icon;
370
- }
371
- if (!settings.name && common.name) {
372
- settings.name = common.name;
373
- }
374
- }
375
-
376
- if (typeof settings.name === 'object') {
377
- settings.name = (options.language && settings.name[options.language]) || settings.name.en;
378
-
379
- settings.name = (settings.name || '').toString().replace(/_/g, ' ');
380
-
381
- if (settings.name === settings.name.toUpperCase()) {
382
- settings.name = settings.name[0] + settings.name.substring(1).toLowerCase();
383
- }
384
- }
385
- if (!settings.name && id) {
386
- const pos = id.lastIndexOf('.');
387
- settings.name = id.substring(pos + 1).replace(/[_.]/g, ' ');
388
- settings.name = (settings.name || '').toString().replace(/_/g, ' ');
389
- settings.name = Utils.CapitalWords(settings.name);
390
- }
391
-
392
- return settings;
393
- }
394
-
395
- /**
396
- Sets smartName settings for the given object.
397
- */
398
- static setSettings(
399
- obj: Partial<ioBroker.Object>,
400
- settings: Record<string, any>,
401
- options: { user?: string; language?: ioBroker.Languages },
402
- ): boolean {
403
- if (obj) {
404
- obj.common = obj.common || ({} as ioBroker.StateCommon);
405
- obj.common.custom = obj.common.custom || {};
406
- obj.common.custom[NAMESPACE] = obj.common.custom[NAMESPACE] || {};
407
- obj.common.custom[NAMESPACE][options.user || 'admin'] = settings;
408
- const s = obj.common.custom[NAMESPACE][options.user || 'admin'];
409
- if (s.useCommon) {
410
- if (s.color !== undefined) {
411
- obj.common.color = s.color;
412
- delete s.color;
413
- }
414
- if (s.icon !== undefined) {
415
- obj.common.icon = s.icon;
416
- delete s.icon;
417
- }
418
- if (s.name !== undefined) {
419
- if (typeof obj.common.name !== 'object' && options.language) {
420
- obj.common.name = { [options.language]: s.name } as ioBroker.StringOrTranslated;
421
- } else if (typeof obj.common.name === 'object' && options.language) {
422
- obj.common.name[options.language] = s.name;
423
- }
424
- delete s.name;
425
- }
426
- }
427
-
428
- return true;
429
- }
430
-
431
- return false;
432
- }
433
-
434
- /**
435
- * Get the icon for the given settings.
436
- */
437
- static getIcon(
438
- settings: { icon?: string; name?: string; prefix?: string },
439
- style?: React.CSSProperties,
440
- ): React.JSX.Element | null {
441
- if (settings?.icon) {
442
- // If UTF-8 icon
443
- if (settings.icon.length <= 2) {
444
- return <span style={style || {}}>{settings.icon}</span>;
445
- }
446
- if (settings.icon.startsWith('data:image')) {
447
- return (
448
- <img
449
- alt={settings.name}
450
- src={settings.icon}
451
- style={style || {}}
452
- />
453
- );
454
- }
455
- // maybe later some changes for a second type
456
- return (
457
- <img
458
- alt={settings.name}
459
- src={(settings.prefix || '') + settings.icon}
460
- style={style}
461
- />
462
- );
463
- }
464
- return null;
465
- }
466
-
467
- /**
468
- * Get the icon for the given object.
469
- */
470
- static getObjectIcon(id: string | ioBroker.PartialObject, obj?: ioBroker.PartialObject): string | null {
471
- // If id is Object
472
- if (typeof id === 'object') {
473
- obj = id;
474
- id = obj?._id as string;
475
- }
476
-
477
- if (obj?.common?.icon) {
478
- let icon = obj.common.icon;
479
- // If UTF-8 icon
480
- if (typeof icon === 'string' && icon.length <= 2) {
481
- return icon;
482
- }
483
- if (icon.startsWith('data:image')) {
484
- return icon;
485
- }
486
-
487
- const parts = id.split('.');
488
- if (parts[0] === 'system') {
489
- icon = `adapter/${parts[2]}${icon.startsWith('/') ? '' : '/'}${icon}`;
490
- } else {
491
- icon = `adapter/${parts[0]}${icon.startsWith('/') ? '' : '/'}${icon}`;
492
- }
493
-
494
- if (window.location.pathname.match(/adapter\/[^/]+\/[^/]+\.html/)) {
495
- icon = `../../${icon}`;
496
- } else if (window.location.pathname.match(/material\/[.\d]+/)) {
497
- icon = `../../${icon}`;
498
- } else if (window.location.pathname.match(/material\//)) {
499
- icon = `../${icon}`;
500
- }
501
- return icon;
502
- }
503
-
504
- return null;
505
- }
506
-
507
- /**
508
- * Converts word1_word2 to word1Word2.
509
- */
510
- static splitCamelCase(text: string | null | undefined): string {
511
- // if (false && text !== text.toUpperCase()) {
512
- // const words = text.split(/\s+/);
513
- // for (let i = 0; i < words.length; i++) {
514
- // const word = words[i];
515
- // if (word.toLowerCase() !== word && word.toUpperCase() !== word) {
516
- // let z = 0;
517
- // const ww = [];
518
- // let start = 0;
519
- // while (z < word.length) {
520
- // if (word[z].match(/[A-ZÜÄÖА-Я]/)) {
521
- // ww.push(word.substring(start, z));
522
- // start = z;
523
- // }
524
- // z++;
525
- // }
526
- // if (start !== z) {
527
- // ww.push(word.substring(start, z));
528
- // }
529
- // for (let k = 0; k < ww.length; k++) {
530
- // words.splice(i + k, 0, ww[k]);
531
- // }
532
- // i += ww.length;
533
- // }
534
- // }
535
- //
536
- // return words.map(w => {
537
- // w = w.trim();
538
- // if (w) {
539
- // return w[0].toUpperCase() + w.substring(1).toLowerCase();
540
- // }
541
- // return '';
542
- // }).join(' ');
543
- // }
544
- return text ? Utils.CapitalWords(text) : '';
545
- }
546
-
547
- /**
548
- * Check if the given color is bright.
549
- * https://stackoverflow.com/questions/35969656/how-can-i-generate-the-opposite-color-according-to-current-color
550
- */
551
- static isUseBright(color: string | null | undefined, defaultValue?: boolean): boolean {
552
- if (!color) {
553
- return defaultValue === undefined ? true : defaultValue;
554
- }
555
- color = color.toString();
556
- if (color.startsWith('#')) {
557
- color = color.slice(1);
558
- }
559
- let r;
560
- let g;
561
- let b;
562
-
563
- const rgb = color.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
564
- if (rgb && rgb.length === 4) {
565
- r = parseInt(rgb[1], 10);
566
- g = parseInt(rgb[2], 10);
567
- b = parseInt(rgb[3], 10);
568
- } else {
569
- // convert 3-digit hex to 6-digits.
570
- if (color.length === 3) {
571
- color = color[0] + color[0] + color[1] + color[1] + color[2] + color[2];
572
- }
573
- // remove alfa channel
574
- if (color.length === 8) {
575
- color = color.substring(0, 6);
576
- } else if (color.length !== 6) {
577
- return false;
578
- }
579
-
580
- r = parseInt(color.slice(0, 2), 16);
581
- g = parseInt(color.slice(2, 4), 16);
582
- b = parseInt(color.slice(4, 6), 16);
583
- }
584
-
585
- // http://stackoverflow.com/a/3943023/112731
586
- return r * 0.299 + g * 0.587 + b * 0.114 <= 186;
587
- }
588
-
589
- /**
590
- * Get the time string in the format 00:00.
591
- */
592
- static getTimeString(seconds: string | number): string {
593
- seconds = parseFloat(seconds as string);
594
- if (Number.isNaN(seconds)) {
595
- return '--:--';
596
- }
597
- const hours = Math.floor(seconds / 3600);
598
- const minutes = Math.floor((seconds % 3600) / 60)
599
- .toString()
600
- .padStart(2, '0');
601
- const secs = (seconds % 60).toString().padStart(2, '0');
602
- if (hours) {
603
- return `${hours}:${minutes}:${secs}`;
604
- }
605
-
606
- return `${minutes}:${secs}`;
607
- }
608
-
609
- /**
610
- * Gets the wind direction with the given angle (degrees).
611
- */
612
- static getWindDirection(
613
- /** angle in degrees from 0° to 360° */
614
- angle: number,
615
- ): string {
616
- if (angle >= 0 && angle < 11.25) {
617
- return 'N';
618
- }
619
- if (angle >= 11.25 && angle < 33.75) {
620
- return 'NNE';
621
- }
622
- if (angle >= 33.75 && angle < 56.25) {
623
- return 'NE';
624
- }
625
- if (angle >= 56.25 && angle < 78.75) {
626
- return 'ENE';
627
- }
628
- if (angle >= 78.75 && angle < 101.25) {
629
- return 'E';
630
- }
631
- if (angle >= 101.25 && angle < 123.75) {
632
- return 'ESE';
633
- }
634
- if (angle >= 123.75 && angle < 146.25) {
635
- return 'SE';
636
- }
637
- if (angle >= 146.25 && angle < 168.75) {
638
- return 'SSE';
639
- }
640
- if (angle >= 168.75 && angle < 191.25) {
641
- return 'S';
642
- }
643
- if (angle >= 191.25 && angle < 213.75) {
644
- return 'SSW';
645
- }
646
- if (angle >= 213.75 && angle < 236.25) {
647
- return 'SW';
648
- }
649
- if (angle >= 236.25 && angle < 258.75) {
650
- return 'WSW';
651
- }
652
- if (angle >= 258.75 && angle < 281.25) {
653
- return 'W';
654
- }
655
- if (angle >= 281.25 && angle < 303.75) {
656
- return 'WNW';
657
- }
658
- if (angle >= 303.75 && angle < 326.25) {
659
- return 'NW';
660
- }
661
- if (angle >= 326.25 && angle < 348.75) {
662
- return 'NNW';
663
- }
664
- // if (angle >= 348.75) {
665
- return 'N';
666
- }
667
-
668
- /**
669
- * Pad the given number with a zero if it's not two digits long.
670
- */
671
- static padding(num: string | number): string {
672
- if (typeof num === 'string') {
673
- if (num.length < 2) {
674
- return `0${num}`;
675
- }
676
- return num;
677
- }
678
- if (num < 10) {
679
- return `0${num}`;
680
- }
681
- return num.toString();
682
- }
683
-
684
- /**
685
- * Sets the date format.
686
- */
687
- static setDataFormat(format: string): void {
688
- if (format) {
689
- Utils.dateFormat = format.toUpperCase().split(/[.-/]/);
690
- Utils.dateFormat.splice(Utils.dateFormat.indexOf('YYYY'), 1);
691
- }
692
- }
693
-
694
- /**
695
- * Converts the date to a string.
696
- */
697
- static date2string(now: string | number | Date): string {
698
- if (typeof now === 'string') {
699
- now = now.trim();
700
- if (!now) {
701
- return '';
702
- }
703
- // only letters
704
- if (now.match(/^[\w\s]+$/)) {
705
- // Day of the week
706
- return now;
707
- }
708
- const m = now.match(/(\d{1,4})[-./](\d{1,2})[-./](\d{1,4})/);
709
- if (m) {
710
- const a = [parseInt(m[1], 10), parseInt(m[2], 10), parseInt(m[3], 10)];
711
- // We now have 3 numbers. Let's try to detect where is year, where is day and where is month
712
- const year = a.find(y => y > 31);
713
- if (year !== undefined) {
714
- a.splice(a.indexOf(year), 1);
715
-
716
- const day = a.find(mm => mm > 12);
717
- if (day) {
718
- a.splice(a.indexOf(day), 1);
719
- now = new Date(year, a[0] - 1, day);
720
- } else if (Utils.dateFormat[0][0] === 'M' && Utils.dateFormat[1][0] === 'D') {
721
- // MM DD
722
- now = new Date(year, a[0] - 1, a[1]);
723
- if (Math.abs(now.getTime() - Date.now()) > 3600000 * 24 * 10) {
724
- now = new Date(year, a[1] - 1, a[0]);
725
- }
726
- } else if (Utils.dateFormat[0][0] === 'D' && Utils.dateFormat[1][0] === 'M') {
727
- // DD MM
728
- now = new Date(year, a[1] - 1, a[0]);
729
- if (Math.abs(now.getTime() - Date.now()) > 3600000 * 24 * 10) {
730
- now = new Date(year, a[0] - 1, a[1]);
731
- }
732
- } else {
733
- now = new Date(now);
734
- }
735
- } else {
736
- now = new Date(now);
737
- }
738
- } else {
739
- now = new Date(now);
740
- }
741
- } else {
742
- now = new Date(now);
743
- }
744
-
745
- let date = I18n.t(`ra_dow_${days[now.getDay()]}`).replace('ra_dow_', '');
746
- date += `. ${now.getDate()} ${I18n.t(`ra_month_${months[now.getMonth()]}`).replace('ra_month_', '')}`;
747
- return date;
748
- }
749
-
750
- /**
751
- * Render a text as a link.
752
- */
753
- static renderTextWithA(text: string): React.JSX.Element[] | string {
754
- let m: RegExpMatchArray | null = text.match(/<a [^<]+<\/a>|<br\s?\/?>|<b>[^<]+<\/b>|<i>[^<]+<\/i>/);
755
- if (m) {
756
- const result: React.JSX.Element[] = [];
757
- let key = 1;
758
- do {
759
- const start = text.substring(0, m.index);
760
- text = text.substring((m.index || 0) + m[0].length);
761
- start && result.push(<span key={`a${key++}`}>{start}</span>);
762
-
763
- if (m[0].startsWith('<b>')) {
764
- result.push(<b key={`a${key++}`}>{m[0].substring(3, m[0].length - 4)}</b>);
765
- } else if (m[0].startsWith('<i>')) {
766
- result.push(<i key={`a${key++}`}>{m[0].substring(3, m[0].length - 4)}</i>);
767
- } else if (m[0].startsWith('<br')) {
768
- result.push(<br key={`a${key++}`} />);
769
- } else {
770
- const href = m[0].match(/href="([^"]+)"/) || m[0].match(/href='([^']+)'/);
771
- const target = m[0].match(/target="([^"]+)"/) || m[0].match(/target='([^']+)'/);
772
- const rel = m[0].match(/rel="([^"]+)"/) || m[0].match(/rel='([^']+)'/);
773
- const title = m[0].match(/>([^<]*)</);
774
-
775
- result.push(
776
- // eslint-disable-next-line react/jsx-no-target-blank
777
- <a
778
- key={`a${key++}`}
779
- href={href ? href[1] : ''}
780
- target={target ? target[1] : '_blank'}
781
- rel={rel ? rel[1] : 'noreferrer'}
782
- style={{ color: 'inherit' }}
783
- >
784
- {title ? title[1] : ''}
785
- </a>,
786
- );
787
- }
788
-
789
- m = text ? text.match(/<a [^<]+<\/a>|<br\/?>|<b>[^<]+<\/b>|<i>[^<]+<\/i>/) : null;
790
- if (!m) {
791
- text && result.push(<span key={`a${key++}`}>{text}</span>);
792
- }
793
- } while (m);
794
-
795
- return result;
796
- }
797
-
798
- return text;
799
- }
800
-
801
- /**
802
- * Get the smart name of the given state.
803
- */
804
- static getSmartName(
805
- states: Record<string, ioBroker.StateObject> | ioBroker.StateObject | ioBroker.StateCommon,
806
- id: string,
807
- instanceId: string,
808
- noCommon?: boolean,
809
- ): SmartName | undefined {
810
- if (!id) {
811
- if (!noCommon) {
812
- if (!(states as ioBroker.StateObject).common) {
813
- return (states as ioBroker.StateCommon).smartName;
814
- }
815
- if (states && !(states as ioBroker.StateObject).common) {
816
- return (states as ioBroker.StateCommon).smartName;
817
- }
818
- return (states as ioBroker.StateObject).common.smartName;
819
- }
820
- if (states && !(states as ioBroker.StateObject).common) {
821
- return (states as ioBroker.StateCommon).smartName;
822
- }
823
- const obj = states as ioBroker.StateObject;
824
- return obj?.common?.custom && obj.common.custom[instanceId]
825
- ? obj.common.custom[instanceId].smartName
826
- : undefined;
827
- }
828
- if (!noCommon) {
829
- return (states as Record<string, ioBroker.StateObject>)[id].common.smartName;
830
- }
831
- const obj = (states as Record<string, ioBroker.StateObject>)[id];
832
-
833
- return obj?.common?.custom && obj.common.custom[instanceId]
834
- ? obj.common.custom[instanceId].smartName || null
835
- : null;
836
- }
837
-
838
- /**
839
- * Get the smart name from a state.
840
- */
841
- static getSmartNameFromObj(
842
- obj: ioBroker.StateObject | ioBroker.StateCommon,
843
- instanceId: string,
844
- noCommon?: boolean,
845
- ): SmartName | undefined {
846
- if (!noCommon) {
847
- if (!(obj as ioBroker.StateObject).common) {
848
- return (obj as ioBroker.StateCommon).smartName;
849
- }
850
- if (obj && !(obj as ioBroker.StateObject).common) {
851
- return (obj as ioBroker.StateCommon).smartName;
852
- }
853
-
854
- return (obj as ioBroker.StateObject).common.smartName;
855
- }
856
- if (obj && !(obj as ioBroker.StateObject).common) {
857
- return (obj as ioBroker.StateCommon).smartName;
858
- }
859
-
860
- const custom: Record<string, string> | undefined | null = (obj as ioBroker.StateObject)?.common?.custom?.[
861
- instanceId
862
- ];
863
-
864
- return custom ? custom.smartName : undefined;
865
- }
866
-
867
- /**
868
- * Enable smart name for a state.
869
- */
870
- static enableSmartName(obj: ioBroker.StateObject, instanceId: string, noCommon?: boolean): void {
871
- if (noCommon) {
872
- obj.common.custom = obj.common.custom || {};
873
- obj.common.custom[instanceId] = obj.common.custom[instanceId] || {};
874
- obj.common.custom[instanceId].smartName = {};
875
- } else {
876
- obj.common.smartName = {};
877
- }
878
- }
879
-
880
- /**
881
- * Completely remove smart name from a state.
882
- */
883
- static removeSmartName(obj: ioBroker.StateObject, instanceId: string, noCommon?: boolean): void {
884
- if (noCommon) {
885
- if (obj.common && obj.common.custom && obj.common.custom[instanceId]) {
886
- obj.common.custom[instanceId] = null;
887
- }
888
- } else {
889
- obj.common.smartName = null;
890
- }
891
- }
892
-
893
- /**
894
- * Update the smart name of a state.
895
- */
896
- static updateSmartName(
897
- obj: ioBroker.StateObject,
898
- newSmartName: ioBroker.StringOrTranslated,
899
- byON: string | null,
900
- smartType: string | null,
901
- instanceId: string,
902
- noCommon?: boolean,
903
- ): void {
904
- const language = I18n.getLanguage();
905
-
906
- // convert the old format
907
- if (typeof obj.common.smartName === 'string') {
908
- const nnn = obj.common.smartName;
909
- obj.common.smartName = {};
910
- obj.common.smartName[language] = nnn;
911
- }
912
-
913
- // convert the old settings
914
- if (obj.native && obj.native.byON) {
915
- delete obj.native.byON;
916
- let _smartName: SmartName = obj.common.smartName as SmartName;
917
-
918
- if (_smartName && typeof _smartName !== 'object') {
919
- _smartName = {
920
- en: _smartName,
921
- [language]: _smartName,
922
- };
923
- }
924
- obj.common.smartName = _smartName;
925
- }
926
- if (smartType !== undefined) {
927
- if (noCommon) {
928
- obj.common.custom = obj.common.custom || {};
929
- obj.common.custom[instanceId] = obj.common.custom[instanceId] || {};
930
- obj.common.custom[instanceId].smartName = obj.common.custom[instanceId].smartName || {};
931
- if (!smartType) {
932
- delete obj.common.custom[instanceId].smartName.smartType;
933
- } else {
934
- obj.common.custom[instanceId].smartName.smartType = smartType;
935
- }
936
- } else {
937
- obj.common.smartName = obj.common.smartName || {};
938
- if (!smartType) {
939
- // @ts-expect-error fixed in js-controller
940
- delete obj.common.smartName.smartType;
941
- } else {
942
- // @ts-expect-error fixed in js-controller
943
- obj.common.smartName.smartType = smartType;
944
- }
945
- }
946
- }
947
-
948
- if (byON !== undefined) {
949
- if (noCommon) {
950
- obj.common.custom = obj.common.custom || {};
951
- obj.common.custom[instanceId] = obj.common.custom[instanceId] || {};
952
- obj.common.custom[instanceId].smartName = obj.common.custom[instanceId].smartName || {};
953
- obj.common.custom[instanceId].smartName.byON = byON;
954
- } else {
955
- obj.common.smartName = obj.common.smartName || {};
956
- // @ts-expect-error fixed in js-controller
957
- obj.common.smartName.byON = byON;
958
- }
959
- }
960
-
961
- if (newSmartName !== undefined) {
962
- let smartName;
963
- if (noCommon) {
964
- obj.common.custom = obj.common.custom || {};
965
- obj.common.custom[instanceId] = obj.common.custom[instanceId] || {};
966
- obj.common.custom[instanceId].smartName = obj.common.custom[instanceId].smartName || {};
967
- smartName = obj.common.custom[instanceId].smartName;
968
- } else {
969
- obj.common.smartName = obj.common.smartName || {};
970
- smartName = obj.common.smartName;
971
- }
972
- smartName[language] = newSmartName;
973
-
974
- // If smart name deleted
975
- if (
976
- smartName &&
977
- (!smartName[language] ||
978
- (smartName[language] === obj.common.name &&
979
- (!obj.common.role || obj.common.role.includes('button'))))
980
- ) {
981
- delete smartName[language];
982
- let empty = true;
983
- // Check if the structure has any definitions
984
- for (const key in smartName) {
985
- if (Object.prototype.hasOwnProperty.call(smartName, key)) {
986
- empty = false;
987
- break;
988
- }
989
- }
990
- // If empty => delete smartName completely
991
- if (empty) {
992
- if (noCommon && obj.common.custom && obj.common.custom[instanceId]) {
993
- if (obj.common.custom[instanceId].smartName.byON === undefined) {
994
- delete obj.common.custom[instanceId];
995
- } else {
996
- delete obj.common.custom[instanceId].en;
997
- delete obj.common.custom[instanceId].de;
998
- delete obj.common.custom[instanceId].ru;
999
- delete obj.common.custom[instanceId].nl;
1000
- delete obj.common.custom[instanceId].pl;
1001
- delete obj.common.custom[instanceId].it;
1002
- delete obj.common.custom[instanceId].fr;
1003
- delete obj.common.custom[instanceId].pt;
1004
- delete obj.common.custom[instanceId].es;
1005
- delete obj.common.custom[instanceId].uk;
1006
- delete obj.common.custom[instanceId]['zh-cn'];
1007
- }
1008
- // @ts-expect-error fixed in js-controller
1009
- } else if (obj.common.smartName && (obj.common.smartName as SmartName).byON !== undefined) {
1010
- const _smartName: { [lang in ioBroker.Languages]?: string } = obj.common.smartName as {
1011
- [lang in ioBroker.Languages]?: string;
1012
- };
1013
- delete _smartName.en;
1014
- delete _smartName.de;
1015
- delete _smartName.ru;
1016
- delete _smartName.nl;
1017
- delete _smartName.pl;
1018
- delete _smartName.it;
1019
- delete _smartName.fr;
1020
- delete _smartName.pt;
1021
- delete _smartName.es;
1022
- delete _smartName.uk;
1023
- delete _smartName['zh-cn'];
1024
- } else {
1025
- obj.common.smartName = null;
1026
- }
1027
- }
1028
- }
1029
- }
1030
- }
1031
-
1032
- /**
1033
- * Disable the smart name of a state.
1034
- */
1035
- static disableSmartName(obj: ioBroker.StateObject, instanceId: string, noCommon?: boolean): void {
1036
- if (noCommon) {
1037
- obj.common.custom = obj.common.custom || {};
1038
- obj.common.custom[instanceId] = obj.common.custom[instanceId] || {};
1039
- obj.common.custom[instanceId].smartName = false;
1040
- } else {
1041
- obj.common.smartName = false;
1042
- }
1043
- }
1044
-
1045
- /**
1046
- * Copy text to the clipboard.
1047
- */
1048
- static copyToClipboard(text: string, e?: Event): boolean {
1049
- if (e) {
1050
- e.stopPropagation();
1051
- e.preventDefault();
1052
- }
1053
- return copy(text);
1054
- }
1055
-
1056
- /**
1057
- * Gets the extension of a file name.
1058
- *
1059
- * @param fileName the file name.
1060
- * @returns The extension in lower case.
1061
- */
1062
- static getFileExtension(fileName: string): string | null {
1063
- const pos = (fileName || '').lastIndexOf('.');
1064
- if (pos !== -1) {
1065
- return fileName.substring(pos + 1).toLowerCase();
1066
- }
1067
- return null;
1068
- }
1069
-
1070
- /**
1071
- * Format number of bytes as a string with B, KB, MB or GB.
1072
- * The base for all calculations is 1024.
1073
- *
1074
- * @param bytes The number of bytes.
1075
- * @returns The formatted string (e.g. '723.5 KB')
1076
- */
1077
- static formatBytes(bytes: number): string {
1078
- if (Math.abs(bytes) < 1024) {
1079
- return `${bytes} B`;
1080
- }
1081
-
1082
- const units = ['KB', 'MB', 'GB'];
1083
- // const units = ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB'];
1084
- let u = -1;
1085
-
1086
- do {
1087
- bytes /= 1024;
1088
- ++u;
1089
- } while (Math.abs(bytes) >= 1024 && u < units.length - 1);
1090
-
1091
- return `${bytes.toFixed(1)} ${units[u]}`;
1092
- }
1093
-
1094
- /**
1095
- * Invert the given color according to a theme type to get the inverted text color for background
1096
- *
1097
- * @param color Color in the format '#rrggbb' or '#rgb' (or without a hash)
1098
- * @param themeType 'light' or 'dark'
1099
- * @param invert If true, the dark theme has a light color in the control, or the dark theme has a light color in the control
1100
- */
1101
- static getInvertedColor(color: string, themeType: ThemeType, invert?: boolean): string | undefined {
1102
- if (!color) {
1103
- return undefined;
1104
- }
1105
- const invertedColor = Utils.invertColor(color, true);
1106
- if (invertedColor === '#FFFFFF' && (themeType === 'dark' || (invert && themeType === 'light'))) {
1107
- return '#DDD';
1108
- }
1109
- if (invertedColor === '#000000' && (themeType === 'light' || (invert && themeType === 'dark'))) {
1110
- return '#222';
1111
- }
1112
-
1113
- return undefined;
1114
- }
1115
-
1116
- // Big thanks to: https://stackoverflow.com/questions/35969656/how-can-i-generate-the-opposite-color-according-to-current-color
1117
- /**
1118
- * Invert the given color
1119
- *
1120
- * @param hex Color in the format '#rrggbb' or '#rgb' (or without a hash)
1121
- * @param bw Set to black or white.
1122
- */
1123
- static invertColor(hex: string, bw?: boolean): string {
1124
- if (hex === undefined || hex === null || hex === '' || typeof hex !== 'string') {
1125
- return '';
1126
- }
1127
- if (hex.startsWith('rgba')) {
1128
- const m = hex.match(/rgba?\((\d+),\s*(\d+),\s*(\d+),\s*([.\d]+)\)/);
1129
- if (m) {
1130
- hex =
1131
- parseInt(m[1], 10).toString(16).padStart(2, '0') +
1132
- parseInt(m[2], 10).toString(16).padStart(2, '0') +
1133
- parseInt(m[2], 10).toString(16).padStart(2, '0');
1134
- }
1135
- } else if (hex.startsWith('rgb')) {
1136
- const m = hex.match(/rgb?\((\d+),\s*(\d+),\s*(\d+)\)/);
1137
- if (m) {
1138
- hex =
1139
- parseInt(m[1], 10).toString(16).padStart(2, '0') +
1140
- parseInt(m[2], 10).toString(16).padStart(2, '0') +
1141
- parseInt(m[2], 10).toString(16).padStart(2, '0');
1142
- }
1143
- } else if (hex.startsWith('#')) {
1144
- hex = hex.slice(1);
1145
- }
1146
- // convert 3-digit hex to 6-digits.
1147
- if (hex.length === 3) {
1148
- hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
1149
- }
1150
- let alfa = null;
1151
- if (hex.length === 8) {
1152
- alfa = hex.substring(6, 8);
1153
- hex = hex.substring(0, 6);
1154
- } else if (hex.length !== 6) {
1155
- console.warn(`Cannot invert color: ${hex}`);
1156
- return hex;
1157
- }
1158
- const r = parseInt(hex.slice(0, 2), 16);
1159
- const g = parseInt(hex.slice(2, 4), 16);
1160
- const b = parseInt(hex.slice(4, 6), 16);
1161
-
1162
- if (bw) {
1163
- // http://stackoverflow.com/a/3943023/112731
1164
- return r * 0.299 + g * 0.587 + b * 0.114 > 186 ? `#000000${alfa || ''}` : `#FFFFFF${alfa || ''}`;
1165
- }
1166
- // invert color components
1167
- const rs = (255 - r).toString(16);
1168
- const gs = (255 - g).toString(16);
1169
- const bd = (255 - b).toString(16);
1170
- // pad each with zeros and return
1171
- return `#${rs.padStart(2, '0')}${gs.padStart(2, '0')}${bd.padStart(2, '0')}${alfa || ''}`;
1172
- }
1173
-
1174
- /**
1175
- * Convert RGB to array [r, g, b]
1176
- *
1177
- * @param hex Color in the format '#rrggbb' or '#rgb' (or without hash) or rgb(r,g,b) or rgba(r,g,b,a)
1178
- * @returns Array with 3 elements [r, g, b]
1179
- */
1180
- static color2rgb(hex: string): false | [number, number, number] | '' {
1181
- if (hex === undefined || hex === null || hex === '' || typeof hex !== 'string') {
1182
- return false;
1183
- }
1184
- if (hex.startsWith('rgba')) {
1185
- const m = hex.match(/rgba?\((\d+),\s*(\d+),\s*(\d+),\s*([.\d]+)\)/);
1186
- if (m) {
1187
- hex =
1188
- parseInt(m[1], 10).toString(16).padStart(2, '0') +
1189
- parseInt(m[2], 10).toString(16).padStart(2, '0') +
1190
- parseInt(m[2], 10).toString(16).padStart(2, '0');
1191
- }
1192
- } else if (hex.startsWith('rgb')) {
1193
- const m = hex.match(/rgb?\((\d+),\s*(\d+),\s*(\d+)\)/);
1194
- if (m) {
1195
- hex =
1196
- parseInt(m[1], 10).toString(16).padStart(2, '0') +
1197
- parseInt(m[2], 10).toString(16).padStart(2, '0') +
1198
- parseInt(m[2], 10).toString(16).padStart(2, '0');
1199
- }
1200
- } else if (hex.startsWith('#')) {
1201
- hex = hex.slice(1);
1202
- }
1203
- // convert 3-digit hex to 6-digits.
1204
- if (hex.length === 3) {
1205
- hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
1206
- }
1207
- if (hex.length !== 6 && hex.length !== 8) {
1208
- console.warn(`Cannot invert color: ${hex}`);
1209
- return false;
1210
- }
1211
-
1212
- return [parseInt(hex.slice(0, 2), 16), parseInt(hex.slice(2, 4), 16), parseInt(hex.slice(4, 6), 16)];
1213
- }
1214
-
1215
- // Big thanks to: https://github.com/antimatter15/rgb-lab
1216
- /**
1217
- * Convert RGB to LAB
1218
- *
1219
- * @param rgb color in format [r,g,b]
1220
- * @returns lab color in format [l,a,b]
1221
- */
1222
- static rgb2lab(rgb: [number, number, number]): [number, number, number] {
1223
- let r = rgb[0] / 255;
1224
- let g = rgb[1] / 255;
1225
- let b = rgb[2] / 255;
1226
-
1227
- r = r > 0.04045 ? ((r + 0.055) / 1.055) ** 2.4 : r / 12.92;
1228
- g = g > 0.04045 ? ((g + 0.055) / 1.055) ** 2.4 : g / 12.92;
1229
- b = b > 0.04045 ? ((b + 0.055) / 1.055) ** 2.4 : b / 12.92;
1230
-
1231
- let x = (r * 0.4124 + g * 0.3576 + b * 0.1805) / 0.95047;
1232
- let y = r * 0.2126 + g * 0.7152 + b * 0.0722; /* / 1.00000; */
1233
- let z = (r * 0.0193 + g * 0.1192 + b * 0.9505) / 1.08883;
1234
-
1235
- x = x > 0.008856 ? x ** 0.33333333 : 7.787 * x + 0.137931; // 16 / 116;
1236
- y = y > 0.008856 ? y ** 0.33333333 : 7.787 * y + 0.137931; // 16 / 116;
1237
- z = z > 0.008856 ? z ** 0.33333333 : 7.787 * z + 0.137931; // 16 / 116;
1238
-
1239
- return [116 * y - 16, 500 * (x - y), 200 * (y - z)];
1240
- }
1241
-
1242
- /**
1243
- * Calculate the distance between two colors in LAB color space in the range 0-100^2
1244
- * If the distance is less than 1000, the colors are similar
1245
- *
1246
- * @param color1 Color in the format '#rrggbb' or '#rgb' (or without hash) or rgb(r,g,b) or rgba(r,g,b,a)
1247
- * @param color2 Color in the format '#rrggbb' or '#rgb' (or without hash) or rgb(r,g,b) or rgba(r,g,b,a)
1248
- * @returns distance in the range 0-100^2
1249
- */
1250
- static colorDistance(color1: string, color2: string): number {
1251
- const rgb1 = Utils.color2rgb(color1);
1252
- const rgb2 = Utils.color2rgb(color2);
1253
- if (!rgb1 || !rgb2) {
1254
- return 0;
1255
- }
1256
-
1257
- const lab1 = Utils.rgb2lab(rgb1);
1258
- const lab2 = Utils.rgb2lab(rgb2);
1259
- const dltL = lab1[0] - lab2[0];
1260
- const dltA = lab1[1] - lab2[1];
1261
- const dltB = lab1[2] - lab2[2];
1262
- const c1 = Math.sqrt(lab1[1] * lab1[1] + lab1[2] * lab1[2]);
1263
- const c2 = Math.sqrt(lab2[1] * lab2[1] + lab2[2] * lab2[2]);
1264
- const dltC = c1 - c2;
1265
- let dltH = dltA * dltA + dltB * dltB - dltC * dltC;
1266
- dltH = dltH < 0 ? 0 : Math.sqrt(dltH);
1267
- const sc = 1.0 + 0.045 * c1;
1268
- const sh = 1.0 + 0.015 * c1;
1269
- const dltLKlsl = dltL;
1270
- const dltCkcsc = dltC / sc;
1271
- const dltHkhsh = dltH / sh;
1272
- const i = dltLKlsl * dltLKlsl + dltCkcsc * dltCkcsc + dltHkhsh * dltHkhsh;
1273
- return i < 0 ? 0 : i;
1274
- }
1275
-
1276
- // https://github.com/lukeed/clsx/blob/master/src/index.js
1277
- // License
1278
- // MIT © Luke Edwards
1279
- private static _toVal(mix: ClassValue): string {
1280
- let y;
1281
- let str = '';
1282
-
1283
- if (typeof mix === 'string' || typeof mix === 'number') {
1284
- str += mix;
1285
- } else if (typeof mix === 'object') {
1286
- if (Array.isArray(mix)) {
1287
- for (let k = 0; k < mix.length; k++) {
1288
- if (mix[k]) {
1289
- y = Utils._toVal(mix[k]);
1290
- if (y) {
1291
- str && (str += ' ');
1292
- str += y;
1293
- }
1294
- }
1295
- }
1296
- } else {
1297
- for (const k in mix) {
1298
- if (mix[k]) {
1299
- str && (str += ' ');
1300
- str += k;
1301
- }
1302
- }
1303
- }
1304
- }
1305
-
1306
- return str;
1307
- }
1308
-
1309
- // https://github.com/lukeed/clsx/blob/master/src/index.js
1310
- // License
1311
- // MIT © Luke Edwards
1312
- /**
1313
- * Convert any object to a string with its values.
1314
- */
1315
- static clsx(...inputs: ClassValue[]): string {
1316
- let i = 0;
1317
- let tmp;
1318
- let x;
1319
- let str = '';
1320
- while (i < inputs.length) {
1321
- tmp = inputs[i++];
1322
- if (tmp) {
1323
- x = Utils._toVal(tmp);
1324
- if (x) {
1325
- str && (str += ' ');
1326
- str += x;
1327
- }
1328
- }
1329
- }
1330
- return str;
1331
- }
1332
-
1333
- /**
1334
- * Get the current theme name (either from local storage or the browser settings).
1335
- */
1336
- static getThemeName(themeName?: ThemeName | null): ThemeName {
1337
- if (
1338
- (window as any).vendorPrefix &&
1339
- (window as any).vendorPrefix !== '@@vendorPrefix@@' &&
1340
- (window as any).vendorPrefix !== 'MV'
1341
- ) {
1342
- return (window as any).vendorPrefix;
1343
- }
1344
-
1345
- themeName = ((window as any)._localStorage || window.localStorage).getItem('App.themeName');
1346
- if (themeName) {
1347
- return themeName;
1348
- }
1349
- return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'colored';
1350
- }
1351
-
1352
- /**
1353
- * Get the type of theme.
1354
- */
1355
- static getThemeType(themeName?: ThemeName): ThemeType {
1356
- if ((window as any).vendorPrefix && (window as any).vendorPrefix !== '@@vendorPrefix@@') {
1357
- return 'light';
1358
- }
1359
-
1360
- themeName = themeName || Utils.getThemeName();
1361
- return themeName === 'dark' || themeName === 'blue' ? 'dark' : 'light';
1362
- }
1363
-
1364
- /**
1365
- * Set the theme name and theme type.
1366
- */
1367
- static setThemeName(themeName: ThemeName): void {
1368
- const vendorPrefix = (window as any).vendorPrefix;
1369
- if (vendorPrefix && vendorPrefix !== '@@vendorPrefix@@' && vendorPrefix !== 'MV') {
1370
- return; // ignore
1371
- }
1372
- ((window as any)._localStorage || window.localStorage).setItem('App.themeName', themeName);
1373
- ((window as any)._localStorage || window.localStorage).setItem(
1374
- 'App.theme',
1375
- themeName === 'dark' || themeName === 'blue' ? 'dark' : 'light',
1376
- );
1377
- }
1378
-
1379
- /**
1380
- * Toggle the theme name between 'dark' and 'colored'.
1381
- *
1382
- * @returns the new theme name.
1383
- */
1384
- static toggleTheme(themeName?: ThemeName | null): ThemeName {
1385
- if (
1386
- (window as any).vendorPrefix &&
1387
- (window as any).vendorPrefix !== '@@vendorPrefix@@' &&
1388
- (window as any).vendorPrefix !== 'MV'
1389
- ) {
1390
- return (window as any).vendorPrefix as ThemeName;
1391
- }
1392
- themeName =
1393
- themeName || ((window as any)._localStorage || window.localStorage).getItem('App.themeName') || 'light';
1394
-
1395
- // dark => blue => colored => light => dark
1396
- const themes = Utils.getThemeNames();
1397
- const pos = themeName ? themes.indexOf(themeName) : -1;
1398
- let newTheme: ThemeName;
1399
- if (pos !== -1) {
1400
- newTheme = themes[(pos + 1) % themes.length];
1401
- } else {
1402
- newTheme = themes[0];
1403
- }
1404
- Utils.setThemeName(newTheme);
1405
-
1406
- return newTheme;
1407
- }
1408
-
1409
- /**
1410
- * Get the list of themes
1411
- *
1412
- * @returns list of possible themes
1413
- */
1414
- static getThemeNames(): ThemeName[] {
1415
- if (
1416
- (window as any).vendorPrefix &&
1417
- (window as any).vendorPrefix !== '@@vendorPrefix@@' &&
1418
- (window as any).vendorPrefix !== 'MV'
1419
- ) {
1420
- return [(window as any).vendorPrefix as ThemeName];
1421
- }
1422
-
1423
- return ['light', 'dark'];
1424
- }
1425
-
1426
- /**
1427
- * Parse a query string into its parts.
1428
- */
1429
- static parseQuery(query: string): Record<string, string | number | boolean> {
1430
- query = (query || '').toString().replace(/^\?/, '');
1431
- const result: Record<string, string | number | boolean> = {};
1432
- query.split('&').forEach(part => {
1433
- part = part.trim();
1434
- if (part) {
1435
- const parts = part.split('=');
1436
- const attr = decodeURIComponent(parts[0]).trim();
1437
- if (parts.length > 1) {
1438
- const value = decodeURIComponent(parts[1]);
1439
- if (value === 'true') {
1440
- result[attr] = true;
1441
- } else if (value === 'false') {
1442
- result[attr] = false;
1443
- } else {
1444
- const f = parseFloat(value);
1445
- if (f.toString() === value) {
1446
- result[attr] = f;
1447
- } else {
1448
- result[attr] = value;
1449
- }
1450
- }
1451
- } else {
1452
- result[attr] = true;
1453
- }
1454
- }
1455
- });
1456
- return result;
1457
- }
1458
-
1459
- /**
1460
- * Returns parent ID.
1461
- *
1462
- * @returns parent ID or null if no parent
1463
- */
1464
- static getParentId(id: string): string | null {
1465
- const p = (id || '').toString().split('.');
1466
- if (p.length > 1) {
1467
- p.pop();
1468
- return p.join('.');
1469
- }
1470
-
1471
- return null;
1472
- }
1473
-
1474
- static formatDate(dateObj: Date, dateFormat: string): string {
1475
- // format could be DD.MM.YYYY, YYYY.MM.DD or MM/DD/YYYY
1476
-
1477
- if (!dateObj) {
1478
- return '';
1479
- }
1480
-
1481
- let text;
1482
- const mm = (dateObj.getMonth() + 1).toString().padStart(2, '0');
1483
- const dd = dateObj.getDate().toString().padStart(2, '0');
1484
-
1485
- if (dateFormat === 'MM/DD/YYYY') {
1486
- text = `${mm}/${dd}/${dateObj.getFullYear()}`;
1487
- } else {
1488
- text = `${dateObj.getFullYear()}-${mm}-${dd}`;
1489
- }
1490
-
1491
- // time
1492
- text += ` ${dateObj.getHours().toString().padStart(2, '0')}:${dateObj.getMinutes().toString().padStart(2, '0')}:${dateObj.getSeconds().toString().padStart(2, '0')}.${dateObj.getMilliseconds().toString().padStart(3, '0')}`;
1493
-
1494
- return text;
1495
- }
1496
-
1497
- /**
1498
- * Format seconds to string like 'h:mm:ss' or 'd.hh:mm:ss'
1499
- */
1500
- static formatTime(seconds: number): string {
1501
- if (seconds) {
1502
- seconds = Math.round(seconds);
1503
- const d = Math.floor(seconds / (3600 * 24));
1504
- const h = Math.floor((seconds % (3600 * 24)) / 3600);
1505
- const m = Math.floor((seconds % 3600) / 60);
1506
- const s = seconds % 60;
1507
- if (d) {
1508
- return `${d}.${h.toString().padStart(2, '0')}:${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`;
1509
- }
1510
- if (h) {
1511
- return `${h}:${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`;
1512
- }
1513
-
1514
- return `0:${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`;
1515
- }
1516
- return '0:00:00';
1517
- }
1518
-
1519
- static MDtext2link(text: string): string {
1520
- const m = text.match(/\d+\.\)\s/);
1521
- if (m) {
1522
- text = text.replace(m[0], m[0].replace(/\s/, '&nbsp;'));
1523
- }
1524
-
1525
- return text
1526
- .replace(/[^a-zA-Zа-яА-Я0-9]/g, '')
1527
- .trim()
1528
- .replace(/\s/g, '')
1529
- .toLowerCase();
1530
- }
1531
-
1532
- /**
1533
- * Open url link in the new target window
1534
- */
1535
- static openLink(url: string, target?: string): void {
1536
- // replace IPv6 Address with [ipv6]:port
1537
- url = url.replace(/\/\/([0-9a-f]*:[0-9a-f]*:[0-9a-f]*:[0-9a-f]*:[0-9a-f]*:[0-9a-f]*)(:\d+)?\//i, '//[$1]$2/');
1538
-
1539
- if (target === 'this') {
1540
- window.location.href = url;
1541
- } else {
1542
- window.open(url, target || '_blank');
1543
- }
1544
- }
1545
-
1546
- static MDgetTitle(text: string): string {
1547
- const result = Utils.MDextractHeader(text);
1548
- const header = result.header;
1549
- let body = result.body;
1550
- if (!header.title) {
1551
- // remove {docsify-bla}
1552
- body = body.replace(/{[^}]*}/g, '');
1553
- body = body.trim();
1554
- const lines = body.replace(/\r/g, '').split('\n');
1555
- for (let i = 0; i < lines.length; i++) {
1556
- if (lines[i].startsWith('# ')) {
1557
- return lines[i].substring(2).trim();
1558
- }
1559
- }
1560
- return '';
1561
- }
1562
-
1563
- return header.title?.toString() || '';
1564
- }
1565
-
1566
- static MDextractHeader(text: string): { header: Record<string, string | boolean | number>; body: string } {
1567
- const attrs: Record<string, string | boolean | number> = {};
1568
- if (text.substring(0, 3) === '---') {
1569
- const pos = text.substring(3).indexOf('\n---');
1570
- if (pos !== -1) {
1571
- const _header = text.substring(3, pos + 3);
1572
- const lines = _header.replace(/\r/g, '').split('\n');
1573
- lines.forEach(line => {
1574
- if (!line.trim()) {
1575
- return;
1576
- }
1577
- const pos_ = line.indexOf(':');
1578
- if (pos_ !== -1) {
1579
- const attr = line.substring(0, pos_).trim();
1580
- let value = line.substring(pos_ + 1).trim();
1581
- value = value.replace(/^['"]|['"]$/g, '');
1582
- if (value === 'true') {
1583
- attrs[attr] = true;
1584
- } else if (value === 'false') {
1585
- attrs[attr] = false;
1586
- } else if (parseFloat(value).toString() === attrs[attr]) {
1587
- attrs[attr] = parseFloat(value);
1588
- } else {
1589
- attrs[attr] = value;
1590
- }
1591
- } else {
1592
- attrs[line.trim()] = true;
1593
- }
1594
- });
1595
- text = text.substring(pos + 7);
1596
- }
1597
- }
1598
- return { header: attrs, body: text };
1599
- }
1600
-
1601
- static MDremoveDocsify(text: string): string {
1602
- const m = text.match(/{docsify-[^}]*}/g);
1603
- if (m) {
1604
- m.forEach(doc => (text = text.replace(doc, '')));
1605
- }
1606
- return text;
1607
- }
1608
-
1609
- /**
1610
- * Generate the file for download from JSON object.
1611
- */
1612
- static generateFile(
1613
- fileName: string,
1614
- /** json file data */
1615
- json: Record<string, any>,
1616
- ): void {
1617
- const el = document.createElement('a');
1618
- el.setAttribute(
1619
- 'href',
1620
- `data:application/json;charset=utf-8,${encodeURIComponent(JSON.stringify(json, null, 2))}`,
1621
- );
1622
- el.setAttribute('download', fileName);
1623
-
1624
- el.style.display = 'none';
1625
- document.body.appendChild(el);
1626
-
1627
- el.click();
1628
-
1629
- document.body.removeChild(el);
1630
- }
1631
-
1632
- /**
1633
- * Convert quality code into text
1634
- *
1635
- * @returns lines that decode quality
1636
- */
1637
- static quality2text(quality: ioBroker.STATE_QUALITY[keyof ioBroker.STATE_QUALITY]): string[] {
1638
- const custom = quality & 0xffff0000;
1639
- const text: string = QUALITY_BITS[quality];
1640
- let result;
1641
- if (text) {
1642
- result = [text];
1643
- } else if (quality & 0x01) {
1644
- result = [QUALITY_BITS[0x01], `0x${(quality & (0xffff & ~1)).toString(16)}`];
1645
- } else if (quality & 0x02) {
1646
- result = [QUALITY_BITS[0x02], `0x${(quality & (0xffff & ~2)).toString(16)}`];
1647
- } else {
1648
- result = [`0x${quality.toString(16)}`];
1649
- }
1650
- if (custom) {
1651
- result.push(`0x${(custom >> 16).toString(16).toUpperCase()}`);
1652
- }
1653
- return result;
1654
- }
1655
-
1656
- /**
1657
- * Deep copy object
1658
- */
1659
- static clone(object: Record<string, any>): Record<string, any> {
1660
- return JSON.parse(JSON.stringify(object));
1661
- }
1662
-
1663
- /**
1664
- * Get states of object
1665
- *
1666
- * @returns states as an object in form {"value1": "label1", "value2": "label2"} or null
1667
- */
1668
- static getStates(obj: ioBroker.StateObject | null | undefined): Record<string, string> | null {
1669
- const states: Record<string, string> | string[] | string | undefined | null = obj?.common?.states;
1670
- let result: Record<string, string> | null | undefined;
1671
- if (states) {
1672
- if (typeof states === 'string' && states[0] === '{') {
1673
- try {
1674
- result = JSON.parse(states) as Record<string, string>;
1675
- } catch {
1676
- console.error(`Cannot parse states: ${states}`);
1677
- result = null;
1678
- }
1679
- } else if (typeof states === 'string') {
1680
- // if old format val1:text1;val2:text2
1681
- const parts = states.split(';');
1682
- result = {};
1683
- for (let p = 0; p < parts.length; p++) {
1684
- const s = parts[p].split(':');
1685
- result[s[0]] = s[1];
1686
- }
1687
- } else if (Array.isArray(states)) {
1688
- result = {};
1689
- if (obj?.common.type === 'number') {
1690
- states.forEach((value, key) => ((result as Record<string, string>)[key] = value));
1691
- } else if (obj?.common.type === 'string') {
1692
- states.forEach(value => ((result as Record<string, string>)[value] = value));
1693
- } else if (obj?.common.type === 'boolean') {
1694
- result.false = states[0];
1695
- result.true = states[1];
1696
- }
1697
- } else if (typeof states === 'object') {
1698
- result = states;
1699
- }
1700
- }
1701
-
1702
- return result || null;
1703
- }
1704
-
1705
- /**
1706
- * Get svg file as text
1707
- *
1708
- * @param url URL of SVG file
1709
- * @returns Promise with "data:image..."
1710
- */
1711
- static async getSvg(url: string): Promise<string> {
1712
- const response = await fetch(url);
1713
- const blob = await response.blob();
1714
- return new Promise(resolve => {
1715
- const reader = new FileReader();
1716
- reader.onload = function () {
1717
- resolve(this.result?.toString() || '');
1718
- };
1719
- reader.readAsDataURL(blob);
1720
- });
1721
- }
1722
-
1723
- /**
1724
- * Detect a file extension by its content
1725
- *
1726
- * @returns The detected extension, like 'jpg'
1727
- */
1728
- static detectMimeType(
1729
- /** Base64 encoded binary file */
1730
- base64: string,
1731
- ): string | null {
1732
- const signature = Object.keys(SIGNATURES).find(s => base64.startsWith(s));
1733
- return signature ? SIGNATURES[signature] : null;
1734
- }
1735
-
1736
- /**
1737
- * Check if configured repository is the stable repository
1738
- */
1739
- static isStableRepository(
1740
- /** current configured repository or multi repository */
1741
- activeRepo: string | string[],
1742
- ): boolean {
1743
- return !!(
1744
- (typeof activeRepo === 'string' && activeRepo.toLowerCase().startsWith('stable')) ||
1745
- (activeRepo && typeof activeRepo !== 'string' && activeRepo.find(r => r.toLowerCase().startsWith('stable')))
1746
- );
1747
- }
1748
-
1749
- /**
1750
- * Check if a given string is an integer
1751
- */
1752
- static isStringInteger(str: string | number): boolean {
1753
- if (typeof str === 'number') {
1754
- return Math.round(str) === str;
1755
- }
1756
- return parseInt(str, 10).toString() === str;
1757
- }
1758
-
1759
- /**
1760
- * Check if the date is valid
1761
- */
1762
- static isValidDate(date: any): boolean {
1763
- return date instanceof Date && !isNaN(date as any as number);
1764
- }
1765
-
1766
- static getStyle(
1767
- theme: IobTheme,
1768
- ...args: (((_theme: IobTheme) => Record<string, any>) | undefined | Record<string, any>)[]
1769
- ): Record<string, any> {
1770
- const result: Record<string, any> = {};
1771
-
1772
- for (let a = 0; a < args.length; a++) {
1773
- if (typeof args[a] === 'function') {
1774
- Object.assign(result, (args[a] as (_theme: IobTheme) => Record<string, any>)(theme));
1775
- } else if (args[a] && typeof args[a] === 'object') {
1776
- Object.keys(args[a] as Record<string, any>).forEach((attr: string) => {
1777
- if (typeof (args[a] as Record<string, any>)[attr] === 'function') {
1778
- result[attr] = (
1779
- (args[a] as Record<string, any>)[attr] as (_theme: IobTheme) => Record<string, any>
1780
- )(theme);
1781
- } else if (typeof (args[a] as Record<string, any>)[attr] === 'object') {
1782
- const obj = (args[a] as Record<string, any>)[attr];
1783
- result[attr] = {};
1784
- Object.keys(obj).forEach((attr1: string) => {
1785
- if (typeof obj[attr1] === 'function') {
1786
- result[attr][attr1] = obj(theme);
1787
- } else if (obj[attr1] || obj[attr1] === 0) {
1788
- result[attr][attr1] = obj[attr1];
1789
- }
1790
- });
1791
- } else if ((args[a] as Record<string, any>)[attr] || (args[a] as Record<string, any>)[attr] === 0) {
1792
- result[attr] = (args[a] as Record<string, any>)[attr];
1793
- }
1794
- });
1795
- }
1796
- }
1797
-
1798
- return result;
1799
- }
1800
- }
1801
-
1802
- export default Utils;