LegacyLoader.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. class LegacyLoader {
  2. offsetX = 20;
  3. offsetY = 2;
  4. jsonData = {};
  5. updateHandlers = [];
  6. withBackgroundAtAOD = false;
  7. constructor(path, jsonData) {
  8. this.path = path;
  9. this.jsonData = jsonData;
  10. }
  11. createWidget() {
  12. if(typeof Tk !== "undefined")
  13. return Tk.createWidget(...arguments);
  14. return hmUI.createWidget(...arguments);
  15. }
  16. createTimer() {
  17. if(typeof Tk !== "undefined")
  18. return Tk.createTimer(...arguments);
  19. return timer.createTimer(...arguments);
  20. }
  21. createTextImg(config) {
  22. if(!config.v_space)
  23. return this.createWidget(hmUI.widget.TEXT_IMG, config);
  24. const imgs = [];
  25. // Prebuild
  26. for(let i = 0; i < 5; i++) {
  27. imgs[i] = this.createWidget(hmUI.widget.IMG, {
  28. x: config.x + (config.h_space + config.img_w) * i,
  29. y: config.y + (config.v_space) * i,
  30. show_level: config.show_level,
  31. src: ""
  32. })
  33. }
  34. const setText = (val) => {
  35. for(let i = 0; i < 5; i++) {
  36. let liter = ""
  37. if(i < val.length) {
  38. liter = config.font_array[val[i]];
  39. if(val[i] == ".") liter = config.dot_image;
  40. }
  41. imgs[i].setProperty(hmUI.prop.MORE, {src: liter});
  42. }
  43. };
  44. setText(config.text);
  45. return {
  46. setProperty(_, text) {
  47. setText(text);
  48. }
  49. }
  50. }
  51. getObject(path, callback) {
  52. const levels = path.split(".");
  53. let position = this.jsonData;
  54. for(let i = 0; i < levels.length; i++) {
  55. if(position[levels[i]] === undefined) return null;
  56. position = position[levels[i]];
  57. }
  58. if(callback) callback(position);
  59. return position;
  60. }
  61. getFileFromID(id) {
  62. if(typeof id !== "number") return undefined;
  63. return this.path + id.toString().padStart(4, "0") + ".png";
  64. }
  65. mkFontArrayFrom(id, length) {
  66. const out = [];
  67. for(let i = id; i < id + length; i++)
  68. out.push(this.getFileFromID(i));
  69. return out;
  70. }
  71. convertAlignProps(obj) {
  72. let alignY;
  73. if(obj.Alignment.indexOf("Bottom") > -1)
  74. alignY = hmUI.align.BOTTOM;
  75. else if(obj.Alignment.indexOf("Center") == 0)
  76. alignY = hmUI.align.CENTER_V;
  77. else
  78. alignY = hmUI.align.TOP;
  79. let alignX;
  80. if(obj.Alignment.indexOf("Right") > -1)
  81. alignX = hmUI.align.RIGHT;
  82. else if(obj.Alignment.lastIndexOf("Center") > 0 || obj.Alignment == "Center")
  83. alignX = hmUI.align.CENTER_H;
  84. else
  85. alignX = hmUI.align.LEFT
  86. const w = obj.BottomRightX - obj.TopLeftX;
  87. const h = obj.BottomRightY - obj.TopLeftY;
  88. return {
  89. x: this.offsetX + obj.TopLeftX,
  90. y: this.offsetY + obj.TopLeftY,
  91. w: w > 3 ? w : undefined,
  92. h: h > 3 ? h : undefined,
  93. align_h: alignX,
  94. align_v: alignY,
  95. img_w: obj.ImageWidth,
  96. img_h: obj.ImageHeight
  97. }
  98. }
  99. getWeatherIcons(index) {
  100. const out = [];
  101. for(let i = 0; i < 23; i++) {
  102. out.push(this.getFileFromID(index + i + 1));
  103. }
  104. while(out.length < 29) {
  105. out.push(this.getFileFromID(index));
  106. }
  107. return out;
  108. }
  109. render() {
  110. const time = hmSensor.createSensor(hmSensor.id.TIME);
  111. const weather = hmSensor.createSensor(hmSensor.id.WEATHER);
  112. const updateHandlers = [];
  113. // BG
  114. this.getObject("Background.BackgroundColor", (val) => {
  115. this.createWidget(hmUI.widget.FILL_RECT, {
  116. x: 0, y: 0, w: 192, h : 490,
  117. color: eval(val),
  118. show_level: hmUI.show_level.ONLY_NORMAL
  119. })
  120. })
  121. this.getObject("Background.Image", (image) => {
  122. this.createWidget(hmUI.widget.IMG, {
  123. x: this.offsetX + image.X,
  124. y: this.offsetY + image.Y,
  125. src: this.getFileFromID(image.ImageIndex),
  126. show_level: this.withBackgroundAtAOD ? undefined : hmUI.show_level.ONLY_NORMAL
  127. })
  128. })
  129. // Time
  130. this.getObject("Time.Hours", (hours) => {
  131. const tensFont = this.mkFontArrayFrom(hours.Tens.ImageIndex, hours.Tens.ImagesCount);
  132. const onesFont = this.mkFontArrayFrom(hours.Ones.ImageIndex, hours.Ones.ImagesCount);
  133. const tens = this.createWidget(hmUI.widget.IMG, {
  134. x: this.offsetX + hours.Tens.X,
  135. y: this.offsetY + hours.Tens.Y,
  136. src: ""
  137. });
  138. const ones = this.createWidget(hmUI.widget.IMG, {
  139. x: this.offsetX + hours.Ones.X,
  140. y: this.offsetY + hours.Ones.Y,
  141. src: ""
  142. });
  143. updateHandlers.push(() => {
  144. tens.setProperty(hmUI.prop.MORE, {
  145. src: tensFont[Math.floor(time.hour / 10)]
  146. });
  147. ones.setProperty(hmUI.prop.MORE, {
  148. src: onesFont[time.hour % 10]
  149. });
  150. });
  151. });
  152. this.getObject("Time.Minutes", (minutes) => {
  153. const tensFont = this.mkFontArrayFrom(minutes.Tens.ImageIndex, minutes.Tens.ImagesCount);
  154. const onesFont = this.mkFontArrayFrom(minutes.Ones.ImageIndex, minutes.Ones.ImagesCount);
  155. const tens = this.createWidget(hmUI.widget.IMG, {
  156. x: this.offsetX + minutes.Tens.X,
  157. y: this.offsetY + minutes.Tens.Y,
  158. src: ""
  159. });
  160. const ones = this.createWidget(hmUI.widget.IMG, {
  161. x: this.offsetX + minutes.Ones.X,
  162. y: this.offsetY + minutes.Ones.Y,
  163. src: ""
  164. });
  165. updateHandlers.push(() => {
  166. tens.setProperty(hmUI.prop.MORE, {
  167. src: tensFont[Math.floor(time.minute / 10)]
  168. });
  169. ones.setProperty(hmUI.prop.MORE, {
  170. src: onesFont[time.minute % 10]
  171. });
  172. });
  173. });
  174. this.getObject("Time.Seconds", (seconds) => {
  175. const tensFont = this.mkFontArrayFrom(seconds.Tens.ImageIndex, seconds.Tens.ImagesCount);
  176. const onesFont = this.mkFontArrayFrom(seconds.Ones.ImageIndex, seconds.Ones.ImagesCount);
  177. const tens = this.createWidget(hmUI.widget.IMG, {
  178. x: this.offsetX + seconds.Tens.X,
  179. y: this.offsetY + seconds.Tens.Y,
  180. src: ""
  181. });
  182. const ones = this.createWidget(hmUI.widget.IMG, {
  183. x: this.offsetX + seconds.Ones.X,
  184. y: this.offsetY + seconds.Ones.Y,
  185. src: ""
  186. });
  187. updateHandlers.push(() => {
  188. tens.setProperty(hmUI.prop.MORE, {
  189. src: tensFont[Math.floor(time.second / 10)]
  190. });
  191. ones.setProperty(hmUI.prop.MORE, {
  192. src: onesFont[time.second % 10]
  193. });
  194. });
  195. });
  196. this.getObject("Time.DelimiterImage", (img) => {
  197. this.createWidget(hmUI.widget.IMG, {
  198. x: this.offsetX + img.X,
  199. y: this.offsetY + img.Y,
  200. src: this.getFileFromID(img.ImageIndex)
  201. })
  202. });
  203. this.getObject("Time.TimeZone2", (obj) => {
  204. const view = hmUI.createWidget(hmUI.widget.TEXT_IMG, {
  205. type: hmUI.data_type.SUN_RISE,
  206. font_array: this.mkFontArrayFrom(obj.ImageIndex, obj.ImagesCount),
  207. h_space: obj.SpacingX,
  208. show_level: hmUI.show_level.ONLY_NORMAL,
  209. dot_image: this.getFileFromID(this.getObject("Time.TimeZone1DelimiterImage")),
  210. ...this.convertAlignProps(obj)
  211. });
  212. })
  213. this.getObject("Time.TimeZone1", (obj) => {
  214. const view = hmUI.createWidget(hmUI.widget.TEXT_IMG, {
  215. type: hmUI.data_type.SUN_SET,
  216. font_array: this.mkFontArrayFrom(obj.ImageIndex, obj.ImagesCount),
  217. h_space: obj.SpacingX,
  218. show_level: hmUI.show_level.ONLY_NORMAL,
  219. dot_image: this.getFileFromID(this.getObject("Time.TimeZone1DelimiterImage")),
  220. ...this.convertAlignProps(obj)
  221. });
  222. })
  223. // Activity
  224. this.getObject("Activity.Steps.Number", (obj) => {
  225. this.createWidget(hmUI.widget.TEXT_IMG, {
  226. type: hmUI.data_type.STEP,
  227. font_array: this.mkFontArrayFrom(obj.ImageIndex, obj.ImagesCount),
  228. h_space: obj.SpacingX,
  229. show_level: hmUI.show_level.ONLY_NORMAL,
  230. icon: this.getFileFromID(this.getObject("Activity.Steps.PrefixImageIndex")),
  231. ...this.convertAlignProps(obj)
  232. })
  233. });
  234. this.getObject("Activity.PAI.Number", (obj) => {
  235. this.createWidget(hmUI.widget.TEXT_IMG, {
  236. type: hmUI.data_type.PAI_DAILY,
  237. font_array: this.mkFontArrayFrom(obj.ImageIndex, obj.ImagesCount),
  238. h_space: obj.SpacingX,
  239. show_level: hmUI.show_level.ONLY_NORMAL,
  240. icon: this.getFileFromID(this.getObject("Activity.PAI.PrefixImageIndex")),
  241. ...this.convertAlignProps(obj)
  242. })
  243. });
  244. this.getObject("Activity.Calories.Text", (obj) => {
  245. this.createWidget(hmUI.widget.TEXT_IMG, {
  246. type: hmUI.data_type.CAL,
  247. font_array: this.mkFontArrayFrom(obj.ImageIndex, obj.ImagesCount),
  248. h_space: obj.SpacingX,
  249. show_level: hmUI.show_level.ONLY_NORMAL,
  250. unit_en: this.getFileFromID(this.getObject("Activity.Calories.SuffixImageIndex")),
  251. icon: this.getFileFromID(this.getObject("Activity.Calories.PrefixImageIndex")),
  252. ...this.convertAlignProps(obj)
  253. })
  254. });
  255. this.getObject("Activity.Pulse.Number", (obj) => {
  256. this.createWidget(hmUI.widget.TEXT_IMG, {
  257. type: hmUI.data_type.HEART,
  258. font_array: this.mkFontArrayFrom(obj.ImageIndex, obj.ImagesCount),
  259. h_space: obj.SpacingX,
  260. show_level: hmUI.show_level.ONLY_NORMAL,
  261. icon: this.getFileFromID(this.getObject("Activity.Pulse.PrefixImageIndex")),
  262. invalid_img: this.getFileFromID(this.getObject("Activity.Pulse.NoDataImageIndex")),
  263. ...this.convertAlignProps(obj)
  264. })
  265. });
  266. this.getObject("Activity.Distance.Number", (obj) => {
  267. this.createWidget(hmUI.widget.TEXT_IMG, {
  268. type: hmUI.data_type.DISTANCE,
  269. font_array: this.mkFontArrayFrom(obj.ImageIndex, obj.ImagesCount),
  270. h_space: obj.SpacingX,
  271. show_level: hmUI.show_level.ONLY_NORMAL,
  272. unit_en: this.getFileFromID(this.getObject("Activity.Distance.KmSuffixImageIndex")),
  273. dot_image: this.getFileFromID(this.getObject("Activity.Distance.DecimalPointImageIndex")),
  274. ...this.convertAlignProps(obj)
  275. })
  276. });
  277. // Date
  278. this.getObject("Date.MonthAndDayAndYear.OneLine", (date) => {
  279. const twoDigitsMonth = this.getObject("Date.MonthAndDayAndYear.TwoDigitsMonth");
  280. const twoDigitsDay = this.getObject("Date.MonthAndDayAndYear.TwoDigitsDay");
  281. const view = this.createWidget(hmUI.widget.TEXT_IMG, {
  282. text: "0",
  283. h_space: date.Number.SpacingX,
  284. dot_image: this.getFileFromID(date.DelimiterImageIndex),
  285. font_array: this.mkFontArrayFrom(date.Number.ImageIndex, date.Number.ImagesCount),
  286. ...this.convertAlignProps(date.Number),
  287. });
  288. updateHandlers.push(() => {
  289. let day = time.day.toString();
  290. if(twoDigitsDay) day = day.padStart(2, "0");
  291. let month = time.month.toString();
  292. if(twoDigitsMonth) month = month.padStart(2, "0");
  293. view.setProperty(hmUI.prop.TEXT, day + "." + month);
  294. })
  295. })
  296. this.getObject("Date.MonthAndDayAndYear.Separate.MonthsEN", (month) => {
  297. hmUI.createWidget(hmUI.widget.IMG_DATE, {
  298. month_en_array: this.mkFontArrayFrom(month.ImageIndex, month.ImagesCount),
  299. month_is_character: true,
  300. month_startX: this.offsetX + month.X,
  301. month_startY: this.offsetY + month.Y
  302. })
  303. });
  304. this.getObject("Date.MonthAndDayAndYear.Separate.Month", (date) => {
  305. const twoDigits = this.getObject("Date.MonthAndDayAndYear.TwoDigitsMonth");
  306. const view = this.createTextImg({
  307. text: "0",
  308. h_space: date.SpacingX,
  309. v_space: date.SpacingY,
  310. font_array: this.mkFontArrayFrom(date.ImageIndex, date.ImagesCount),
  311. ...this.convertAlignProps(date)
  312. });
  313. updateHandlers.push(() => {
  314. let val = time.month.toString();
  315. if(twoDigits) val = val.padStart(2, "0");
  316. view.setProperty(hmUI.prop.TEXT, val);
  317. })
  318. })
  319. this.getObject("Date.MonthAndDayAndYear.Separate.Day", (date) => {
  320. const twoDigits = this.getObject("Date.MonthAndDayAndYear.TwoDigitsDay");
  321. const view = this.createTextImg({
  322. text: "0",
  323. h_space: date.SpacingX,
  324. v_space: date.SpacingY,
  325. font_array: this.mkFontArrayFrom(date.ImageIndex, date.ImagesCount),
  326. ...this.convertAlignProps(date),
  327. });
  328. updateHandlers.push(() => {
  329. let val = time.day.toString();
  330. if(twoDigits) val = val.padStart(2, "0");
  331. view.setProperty(hmUI.prop.TEXT, val);
  332. })
  333. });
  334. // Weekday
  335. this.getObject("Date.ENWeekDays", (wd) => {
  336. this.createWidget(hmUI.widget.IMG_WEEK, {
  337. x: this.offsetX + wd.X,
  338. y: this.offsetY + wd.Y,
  339. week_en: this.mkFontArrayFrom(wd.ImageIndex, wd.ImagesCount)
  340. })
  341. })
  342. // Steps progress
  343. this.getObject("StepsProgress.LineScale", (scale) => {
  344. this.createWidget(hmUI.widget.IMG_LEVEL, {
  345. x: this.offsetX + scale.X,
  346. y: this.offsetY + scale.Y,
  347. type: hmUI.data_type.STEP,
  348. image_array: this.mkFontArrayFrom(scale.ImageIndex, scale.ImagesCount),
  349. image_length: scale.ImagesCount,
  350. show_level: hmUI.show_level.ONLY_NORMAL
  351. })
  352. });
  353. this.getObject("HeartProgress.LineScale", (scale) => {
  354. this.createWidget(hmUI.widget.IMG_LEVEL, {
  355. x: this.offsetX + scale.X,
  356. y: this.offsetY + scale.Y,
  357. type: hmUI.data_type.HEART,
  358. image_array: this.mkFontArrayFrom(scale.ImageIndex, scale.ImagesCount),
  359. image_length: scale.ImagesCount,
  360. show_level: hmUI.show_level.ONLY_NORMAL
  361. })
  362. });
  363. this.getObject("HeartProgress.Linear", (obj) => {
  364. const x = [], y = [], image_array = [];
  365. const startID = obj.StartImageIndex;
  366. for(let i = 0; i < obj.Segments.length; i++) {
  367. x.push(obj.Segments[i].X + this.offsetX);
  368. y.push(obj.Segments[i].Y + this.offsetY);
  369. image_array.push(this.getFileFromID(startID + i));
  370. }
  371. this.createWidget(hmUI.widget.IMG_PROGRESS, {
  372. x, y, image_array,
  373. image_length: image_array.length,
  374. type: hmUI.data_type.HEART,
  375. show_level: hmUI.show_level.ONLY_NORMAL
  376. })
  377. })
  378. this.getObject("HeartProgress.CircleScale", (data) => {
  379. this.createWidget(hmUI.widget.ARC_PROGRESS, {
  380. type: hmUI.data_type.HEART,
  381. center_x: this.offsetX + data.CenterX,
  382. center_y: this.offsetY + data.CenterY,
  383. radius: data.RadiusX,
  384. start_angle: data.StartAngle,
  385. end_angle: data.EndAngle,
  386. line_width: data.Width,
  387. color: eval(data.Color),
  388. show_level: hmUI.show_level.ONLY_NORMAL
  389. })
  390. })
  391. this.getObject("CaloriesProgress.LineScale", (scale) => {
  392. this.createWidget(hmUI.widget.IMG_LEVEL, {
  393. x: this.offsetX + scale.X,
  394. y: this.offsetY + scale.Y,
  395. type: hmUI.data_type.HEART,
  396. image_array: this.mkFontArrayFrom(scale.ImageIndex, scale.ImagesCount),
  397. image_length: scale.ImagesCount,
  398. show_level: hmUI.show_level.ONLY_NORMAL
  399. })
  400. });
  401. this.getObject("CaloriesProgress.CircleScale", (data) => {
  402. this.createWidget(hmUI.widget.ARC_PROGRESS, {
  403. type: hmUI.data_type.CAL,
  404. center_x: this.offsetX + data.CenterX,
  405. center_y: this.offsetY + data.CenterY,
  406. radius: data.RadiusX,
  407. start_angle: data.StartAngle,
  408. end_angle: data.EndAngle,
  409. line_width: data.Width,
  410. color: eval(data.Color),
  411. show_level: hmUI.show_level.ONLY_NORMAL
  412. })
  413. })
  414. // Weather
  415. this.getObject("Weather.Icon.CustomIcon", (obj) => {
  416. this.createWidget(hmUI.widget.IMG_LEVEL, {
  417. x: this.offsetX + obj.X,
  418. y: this.offsetY + obj.Y,
  419. type: hmUI.data_type.WEATHER_CURRENT,
  420. image_array: this.getWeatherIcons(obj.ImageIndex),
  421. image_length: 29,
  422. show_level: hmUI.show_level.ONLY_NORMAL
  423. })
  424. })
  425. this.getObject("Weather.Temperature.Current", (obj) => {
  426. this.createWidget(hmUI.widget.TEXT_IMG, {
  427. type: hmUI.data_type.WEATHER_CURRENT,
  428. h_space: obj.Number.SpacingX,
  429. font_array: this.mkFontArrayFrom(obj.Number.ImageIndex, obj.Number.ImagesCount),
  430. negative_image: this.getFileFromID(obj.MinusImageIndex),
  431. unit_en: this.getFileFromID(obj.DegreesImageIndex),
  432. show_level: hmUI.show_level.ONLY_NORMAL,
  433. ...this.convertAlignProps(obj.Number)
  434. });
  435. });
  436. this.getObject("Weather.Temperature.Today.Separate.Day", (obj) => {
  437. this.createWidget(hmUI.widget.TEXT_IMG, {
  438. type: hmUI.data_type.WEATHER_HIGH,
  439. h_space: obj.Number.SpacingX,
  440. font_array: this.mkFontArrayFrom(obj.Number.ImageIndex, obj.Number.ImagesCount),
  441. negative_image: this.getFileFromID(obj.MinusImageIndex),
  442. unit_en: this.getFileFromID(obj.DegreesImageIndex),
  443. show_level: hmUI.show_level.ONLY_NORMAL,
  444. ...this.convertAlignProps(obj.Number)
  445. });
  446. });
  447. this.getObject("Weather.Temperature.Today.Separate.Night", (obj) => {
  448. this.createWidget(hmUI.widget.TEXT_IMG, {
  449. type: hmUI.data_type.WEATHER_LOW,
  450. h_space: obj.Number.SpacingX,
  451. font_array: this.mkFontArrayFrom(obj.Number.ImageIndex, obj.Number.ImagesCount),
  452. negative_image: this.getFileFromID(obj.MinusImageIndex),
  453. unit_en: this.getFileFromID(obj.DegreesImageIndex),
  454. show_level: hmUI.show_level.ONLY_NORMAL,
  455. ...this.convertAlignProps(obj.Number)
  456. });
  457. });
  458. this.getObject("Weather.Temperature.Today.OneLine", (obj) => {
  459. const view = this.createWidget(hmUI.widget.TEXT_IMG, {
  460. text: "",
  461. h_space: obj.Number.SpacingX,
  462. font_array: this.mkFontArrayFrom(obj.Number.ImageIndex, obj.Number.ImagesCount),
  463. negative_image: this.getFileFromID(obj.MinusSignImageIndex),
  464. dot_image: this.getFileFromID(obj.DelimiterImageIndex),
  465. unit_en: this.getFileFromID(obj.DegreesImageIndex),
  466. show_level: hmUI.show_level.ONLY_NORMAL,
  467. ...this.convertAlignProps(obj.Number)
  468. });
  469. updateHandlers.push(() => {
  470. let result = "";
  471. const forecast = weather.getForecastWeather();
  472. if(forecast.forecastData.count > 0) {
  473. const row = forecast.forecastData.data[0];
  474. result = String(row.high) + "." + String(row.low);
  475. if(obj.DegreesImageIndex) result += "u";
  476. }
  477. console.log(result);
  478. view.setProperty(hmUI.prop.TEXT, result);
  479. })
  480. });
  481. this.getObject("Weather.Humidity", (obj) => {
  482. this.createWidget(hmUI.widget.TEXT_IMG, {
  483. type: hmUI.data_type.HUMIDITY,
  484. font_array: this.mkFontArrayFrom(obj.Text.ImageIndex, obj.Text.ImagesCount),
  485. h_space: obj.Text.SpacingX,
  486. unit_en: this.getFileFromID(obj.SuffixImageIndex),
  487. show_level: hmUI.show_level.ONLY_NORMAL,
  488. ...this.convertAlignProps(obj.Text)
  489. })
  490. });
  491. this.getObject("Weather.AirPollution.Index", (obj) => {
  492. this.createWidget(hmUI.widget.TEXT_IMG, {
  493. type: hmUI.data_type.AQI,
  494. font_array: this.mkFontArrayFrom(obj.ImageIndex, obj.ImagesCount),
  495. h_space: obj.SpacingX,
  496. show_level: hmUI.show_level.ONLY_NORMAL,
  497. ...this.convertAlignProps(obj)
  498. })
  499. });
  500. this.getObject("Weather.Wind", (obj) => {
  501. this.createWidget(hmUI.widget.TEXT_IMG, {
  502. type: hmUI.data_type.WIND,
  503. font_array: this.mkFontArrayFrom(obj.Text.ImageIndex, obj.Text.ImagesCount),
  504. h_space: obj.Text.SpacingX,
  505. unit_en: this.getFileFromID(obj.ImageSuffixEN),
  506. show_level: hmUI.show_level.ONLY_NORMAL,
  507. ...this.convertAlignProps(obj.Text)
  508. })
  509. })
  510. // Status
  511. this.getObject("Status.DoNotDisturb", (status) => {
  512. this.createWidget(hmUI.widget.IMG_STATUS, {
  513. x: this.offsetX + status.Coordinates.X,
  514. y: this.offsetY + status.Coordinates.Y,
  515. src: this.getFileFromID(status.ImageIndexOn),
  516. type: hmUI.system_status.DISTURB,
  517. show_level: hmUI.show_level.ONLY_NORMAL
  518. });
  519. })
  520. this.getObject("Status.Bluetooth", (status) => {
  521. this.createWidget(hmUI.widget.IMG_STATUS, {
  522. x: this.offsetX + status.Coordinates.X,
  523. y: this.offsetY + status.Coordinates.Y,
  524. src: this.getFileFromID(status.ImageIndexOff),
  525. type: hmUI.system_status.DISCONNECT,
  526. show_level: hmUI.show_level.ONLY_NORMAL
  527. });
  528. })
  529. this.getObject("Status.Lock", (status) => {
  530. this.createWidget(hmUI.widget.IMG_STATUS, {
  531. x: this.offsetX + status.Coordinates.X,
  532. y: this.offsetY + status.Coordinates.Y,
  533. src: this.getFileFromID(status.ImageIndexOff),
  534. type: hmUI.system_status.LOCK,
  535. show_level: hmUI.show_level.ONLY_NORMAL
  536. });
  537. })
  538. this.getObject("Alarm.Text", (obj) => {
  539. this.createWidget(hmUI.widget.TEXT_IMG, {
  540. type: hmUI.data_type.ALARM_CLOCK,
  541. font_array: this.mkFontArrayFrom(obj.ImageIndex, obj.ImagesCount),
  542. h_space: obj.SpacingX,
  543. dot_image: this.getFileFromID(this.getObject("Alarm.DelimiterImageIndex")),
  544. show_level: hmUI.show_level.ONLY_NORMAL,
  545. align_h: hmUI.align.CENTER_H,
  546. ...this.convertAlignProps(obj)
  547. });
  548. });
  549. this.getObject("Alarm.ImageOff", (obj) => {
  550. this.createWidget(hmUI.widget.IMG, {
  551. x: this.offsetX + obj.X,
  552. y: this.offsetY + obj.Y,
  553. show_level: hmUI.show_level.ONLY_NORMAL,
  554. src: this.getFileFromID(obj.ImageIndex)
  555. })
  556. })
  557. this.getObject("Alarm.ImageOn", (obj) => {
  558. this.createWidget(hmUI.widget.IMG_STATUS, {
  559. x: this.offsetX + obj.X,
  560. y: this.offsetY + obj.Y,
  561. type: hmUI.system_status.CLOCK,
  562. show_level: hmUI.show_level.ONLY_NORMAL,
  563. src: this.getFileFromID(obj.ImageIndex)
  564. })
  565. })
  566. // Battety
  567. this.getObject("Battery.BatteryText", (battery) => {
  568. this.createWidget(hmUI.widget.TEXT_IMG, {
  569. type: hmUI.data_type.BATTERY,
  570. unit_en: this.getFileFromID(battery.SuffixImageIndex),
  571. font_array: this.mkFontArrayFrom(battery.Coordinates.ImageIndex, 10),
  572. h_space: battery.Coordinates.SpacingX,
  573. show_level: hmUI.show_level.ONLY_NORMAL,
  574. ...this.convertAlignProps(battery.Coordinates)
  575. })
  576. });
  577. this.getObject("Battery.BatteryIcon", (icon) => {
  578. this.createWidget(hmUI.widget.IMG_LEVEL, {
  579. x: this.offsetX + icon.X,
  580. y: this.offsetY + icon.Y,
  581. type: hmUI.data_type.BATTERY,
  582. image_array: this.mkFontArrayFrom(icon.ImageIndex, icon.ImagesCount),
  583. image_length: icon.ImagesCount,
  584. show_level: hmUI.show_level.ONLY_NORMAL
  585. })
  586. });
  587. this.getObject("Battery.Linear", (obj) => {
  588. const x = [], y = [], image_array = [];
  589. const startID = obj.StartImageIndex;
  590. for(let i = 0; i < obj.Segments.length; i++) {
  591. x.push(obj.Segments[i].X + this.offsetX);
  592. y.push(obj.Segments[i].Y + this.offsetY);
  593. image_array.push(this.getFileFromID(startID + i));
  594. }
  595. this.createWidget(hmUI.widget.IMG_PROGRESS, {
  596. x, y, image_array,
  597. image_length: image_array.length,
  598. type: hmUI.data_type.BATTERY,
  599. show_level: hmUI.show_level.ONLY_NORMAL
  600. })
  601. })
  602. // Animation
  603. this.getObject("Other.Animation", (gifs) => gifs.forEach((obj, i) => {
  604. this.createWidget(hmUI.widget.IMG_ANIM, {
  605. x: this.offsetX + obj.AnimationImages.X,
  606. y: this.offsetY + obj.AnimationImages.Y,
  607. anim_prefix: i.toString(),
  608. anim_path: this.path + "gif",
  609. anim_ext: "png",
  610. anim_fps: obj.Speed,
  611. repeat_count: obj.RepeatCount > 1 ? 0 : 1,
  612. anim_size: obj.AnimationImages.ImagesCount,
  613. anim_status: hmUI.anim_status.START,
  614. show_level: hmUI.show_level.ONLY_NORMAL
  615. })
  616. }))
  617. // Update all
  618. for(let i in updateHandlers) updateHandlers[i]();
  619. this.updateHandlers = updateHandlers
  620. }
  621. update() {
  622. let updateHandlers = this.updateHandlers;
  623. for(let i in updateHandlers) updateHandlers[i]();
  624. }
  625. initAutoUpdate() {
  626. this.createTimer(0, 5000, () => {
  627. this.update();
  628. });
  629. this.createWidget(hmUI.widget.WIDGET_DELEGATE, {
  630. resume_call: () => {
  631. this.update();
  632. },
  633. });
  634. }
  635. }