awtrix_control 0.0.1

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.
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'awtrix_control/app'
4
+ require 'awtrix_control/device'
5
+ require 'awtrix_control/request'
6
+
7
+ module AwtrixControl
8
+ include AwtrixControl::Request
9
+
10
+ COLOR_MAPPINGS = {
11
+ black: '#000000',
12
+ blue: '#0000ff',
13
+ brown: '#804000',
14
+ green: '#00ff00',
15
+ orange: '#ff8000',
16
+ pink: '#ff00ff',
17
+ purple: '#8000ff',
18
+ red: '#ff0000',
19
+ white: '#ffffff',
20
+ yellow: '#ffff00',
21
+ }.freeze
22
+
23
+ def normalize_color(color)
24
+ case color
25
+ when String
26
+ color
27
+ when Symbol
28
+ COLOR_MAPPINGS[color] || color.to_s
29
+ when Array
30
+ format('#%02x%02x%02x', *color)
31
+ else
32
+ raise ArgumentError, "Invalid color format: #{color.inspect}"
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,661 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe AwtrixControl::App do
6
+ before do
7
+ @device = AwtrixControl::Device.new(DEFAULT_HOST)
8
+ @app = AwtrixControl::App.new(:test_app)
9
+ end
10
+
11
+ # describe '.awtrix_key_to_method_name' do
12
+ # it 'converts an awtrix key to a method name' do
13
+ # expect(AwtrixControl::App.awtrix_key_to_method_name('text')).to eq('text')
14
+ # expect(AwtrixControl::App.awtrix_key_to_method_name('push_icon')).to eq('pushIcon')
15
+ # end
16
+ # end
17
+
18
+ describe '#initialize' do
19
+ it 'initializes instance variables' do
20
+ expect(@app.name).to eq(:test_app)
21
+ expect(@app.payload)
22
+ .to eq(
23
+ {
24
+ "autoScale" => true,
25
+ "center" => true,
26
+ "duration" => 5,
27
+ "hold" => false,
28
+ "lifetime" => 0,
29
+ "lifetimeMode" => 0,
30
+ "loopSound" => false,
31
+ "noScroll" => false,
32
+ "progress" => -1,
33
+ "progressBC" => -1,
34
+ "progressC" => -1,
35
+ "pushIcon" => 0,
36
+ "repeat" => -1,
37
+ "scrollSpeed" => 100,
38
+ "stack" => true,
39
+ "textCase" => 0,
40
+ "textOffset" => 0,
41
+ "topText" => false,
42
+ "wakeup" => false,
43
+ }
44
+
45
+ )
46
+ end
47
+
48
+ it 'registers the app on the device if device is present' do
49
+ app = AwtrixControl::App.new(:test_app, device: @device)
50
+ expect(@device.apps[:test_app]).to eq(app)
51
+ end
52
+ end
53
+
54
+ describe '#autoscale=' do
55
+ it 'sets the autoscale value' do
56
+ @app.autoscale = true
57
+ expect(@app.payload['autoScale']).to be true
58
+
59
+ @app.autoscale = false
60
+ expect(@app.payload['autoScale']).to be false
61
+ end
62
+ end
63
+
64
+ describe '#background_effect=' do
65
+ it 'sets the background effect' do
66
+ @app.background_effect = 'BrickBreaker'
67
+ expect(@app.payload['effect']).to eq('BrickBreaker')
68
+ end
69
+ end
70
+
71
+ describe '#background_effect' do
72
+ it 'gets the background effect' do
73
+ @app.payload = { 'effect' => 'BrickBreaker' }
74
+ expect(@app.background_effect).to eq('BrickBreaker')
75
+ end
76
+ end
77
+
78
+ describe '#background_effect_settings=' do
79
+ it 'sets the background effect settings' do
80
+ @app.background_effect_settings = { 'speed' => 5 }
81
+ expect(@app.payload['effectSettings']).to eq({ 'speed' => 5 })
82
+ end
83
+ end
84
+
85
+ describe '#background_effect_settings' do
86
+ it 'gets the background effect settings' do
87
+ @app.payload = { 'effectSettings' => { 'speed' => 5 } }
88
+ expect(@app.background_effect_settings).to eq({ 'speed' => 5 })
89
+ end
90
+ end
91
+
92
+ describe '#bar_chart=' do
93
+ it 'sets the bar chart' do
94
+ @app.bar_chart = [1, 2, 3]
95
+ expect(@app.payload['bar']).to eq([1, 2, 3])
96
+ end
97
+ end
98
+
99
+ describe '#bar_chart' do
100
+ it 'gets the bar chart' do
101
+ @app.payload = { 'bar' => [1, 2, 3] }
102
+ expect(@app.bar_chart).to eq([1, 2, 3])
103
+ end
104
+ end
105
+
106
+ describe '#center_text=' do
107
+ it 'sets whether to center the text' do
108
+ @app.center_text = true
109
+ expect(@app.payload['center']).to be true
110
+
111
+ @app.center_text = false
112
+ expect(@app.payload['center']).to be false
113
+ end
114
+ end
115
+
116
+ describe '#center_text' do
117
+ it 'gets whether to center the text' do
118
+ @app.payload = { 'center' => true }
119
+ expect(@app.center_text).to eq(true)
120
+ end
121
+ end
122
+
123
+ describe '#device=' do
124
+ it 'sets the device' do
125
+ @app.device = @device
126
+ expect(@app.device).to eq(@device)
127
+ expect(@device.apps[:test_app]).to eq(@app)
128
+ end
129
+
130
+ it 'unregisters the app from a device before adding it to another device' do
131
+ device2 = AwtrixControl::Device.new(DEFAULT_HOST)
132
+ @app.device = @device
133
+ expect(@device.apps[:test_app]).to eq(@app)
134
+ @app.device = device2
135
+ expect(@device.apps[:test_app]).to be_nil
136
+ expect(device2.apps[:test_app]).to eq(@app)
137
+ end
138
+
139
+
140
+ end
141
+
142
+ describe '#disable_scroll=' do
143
+ it 'sets whether to disable scrolling' do
144
+ @app.disable_scroll = true
145
+ expect(@app.payload['noScroll']).to be true
146
+
147
+ @app.disable_scroll = false
148
+ expect(@app.payload['noScroll']).to be false
149
+ end
150
+ end
151
+
152
+ describe '#disable_scroll' do
153
+ it 'gets whether to disable scrolling' do
154
+ @app.payload = { 'noScroll' => false }
155
+ expect(@app.disable_scroll).to eq(false)
156
+ end
157
+ end
158
+
159
+ describe '#display_duration=' do
160
+ it 'sets the display duration' do
161
+ @app.display_duration = 5
162
+ expect(@app.payload['duration']).to eq(5)
163
+ end
164
+ end
165
+
166
+ describe '#display_duration' do
167
+ it 'gets the display duration' do
168
+ @app.payload = { 'duration' => 5 }
169
+ expect(@app.display_duration).to eq(5)
170
+ end
171
+ end
172
+
173
+ describe '#draw_commands=' do
174
+ it 'sets the draw commands' do
175
+ @app.draw_commands = [1, 2, 3]
176
+ expect(@app.payload['draw']).to eq([1, 2, 3])
177
+ end
178
+ end
179
+
180
+ describe '#draw_commands' do
181
+ it 'gets the draw commands' do
182
+ @app.payload = { 'draw' => [1, 2, 3] }
183
+ expect(@app.draw_commands).to eq([1, 2, 3])
184
+ end
185
+ end
186
+
187
+ describe '#forward_clients=' do
188
+ it 'sets the forward clients' do
189
+ @app.forward_clients = ['192.168.0.1']
190
+ expect(@app.payload['clients']).to eq(['192.168.0.1'])
191
+ end
192
+ end
193
+
194
+ describe '#forward_clients' do
195
+ it 'gets the forward clients' do
196
+ @app.payload = { 'clients' => ['192.168.0.1'] }
197
+ expect(@app.forward_clients).to eq(['192.168.0.1'])
198
+ end
199
+ end
200
+
201
+ describe '#hold_notification=' do
202
+ it 'sets the hold notification' do
203
+ @app.hold_notification = false
204
+ expect(@app.payload['hold']).to be false
205
+ end
206
+ end
207
+
208
+ describe '#hold_notification' do
209
+ it 'gets the hold notification' do
210
+ @app.payload = { 'hold' => false }
211
+ expect(@app.hold_notification).to eq(false)
212
+ end
213
+ end
214
+
215
+ describe '#lifetime=' do
216
+ it 'sets the lifetime' do
217
+ @app.lifetime = 5
218
+ expect(@app.payload['lifetime']).to eq(5)
219
+ end
220
+ end
221
+
222
+ describe '#lifetime' do
223
+ it 'gets the lifetime' do
224
+ @app.payload = { 'lifetime' => 5 }
225
+ expect(@app.lifetime).to eq(5)
226
+ end
227
+ end
228
+
229
+ describe '#lifetime_mode=' do
230
+ it 'sets the lifetime mode' do
231
+ @app.lifetime_mode = 0
232
+ expect(@app.payload['lifetimeMode']).to eq(0)
233
+
234
+ @app.lifetime_mode = :stale
235
+ expect(@app.payload['lifetimeMode']).to eq(1)
236
+ end
237
+ end
238
+
239
+ describe '#lifetime_mode' do
240
+ it 'gets the lifetime mode' do
241
+ @app.payload = { 'lifetimeMode' => 1 }
242
+ expect(@app.lifetime_mode).to eq(:stale)
243
+ end
244
+ end
245
+
246
+ describe '#line_chart=' do
247
+ it 'sets the line chart' do
248
+ @app.line_chart = [1, 2, 3]
249
+ expect(@app.payload['line']).to eq([1, 2, 3])
250
+ end
251
+ end
252
+
253
+ describe '#line_chart' do
254
+ it 'gets the line chart' do
255
+ @app.payload = { 'line' => [1, 2, 3] }
256
+ expect(@app.line_chart).to eq([1, 2, 3])
257
+ end
258
+ end
259
+
260
+ describe '#loop_sound=' do
261
+ it 'sets the loop sound' do
262
+ @app.loop_sound = true
263
+ expect(@app.payload['loopSound']).to be true
264
+ end
265
+ end
266
+
267
+ describe '#loop_sound' do
268
+ it 'gets the loop sound' do
269
+ @app.payload = { 'loopSound' => true }
270
+ expect(@app.loop_sound).to eq(true)
271
+ end
272
+ end
273
+
274
+ describe '#overlay_effect=' do
275
+ it 'sets the overlay' do
276
+ @app.overlay_effect = 'snow'
277
+ expect(@app.payload['overlay']).to eq('snow')
278
+ end
279
+ end
280
+
281
+ describe '#overlay' do
282
+ it 'gets the overlay' do
283
+ @app.payload = { 'overlay' => 'snow' }
284
+ expect(@app.overlay_effect).to eq('snow')
285
+ end
286
+ end
287
+
288
+ describe '#position=' do
289
+ it 'sets the position' do
290
+ @app.position = 5
291
+ expect(@app.payload['pos']).to eq(5)
292
+ end
293
+ end
294
+
295
+ describe '#position' do
296
+ it 'gets the position' do
297
+ @app.payload = { 'pos' => 5 }
298
+ expect(@app.position).to eq(5)
299
+ end
300
+ end
301
+
302
+ describe '#progress_bar=' do
303
+ it 'sets the progress bar' do
304
+ @app.progress_bar = 50
305
+ expect(@app.payload['progress']).to eq(50)
306
+ end
307
+ end
308
+
309
+ describe '#progress_bar' do
310
+ it 'gets the progress bar' do
311
+ @app.payload = { 'progress' => 50 }
312
+ expect(@app.progress_bar).to eq(50)
313
+ end
314
+ end
315
+
316
+ describe '#progress_bar_color=' do
317
+ it 'sets the progress bar color' do
318
+ @app.progress_bar_color = :red
319
+ expect(@app.payload['progressC']).to eq('#ff0000')
320
+ end
321
+ end
322
+
323
+ describe '#progress_bar_color' do
324
+ it 'gets the progress bar color' do
325
+ @app.payload = { 'progressC' => '#ff0000' }
326
+ expect(@app.progress_bar_color).to eq('#ff0000')
327
+ end
328
+ end
329
+
330
+ describe '#progress_bar_background_color=' do
331
+ it 'sets the progress bar background color' do
332
+ @app.progress_bar_background_color = :red
333
+ expect(@app.payload['progressBC']).to eq('#ff0000')
334
+ end
335
+ end
336
+
337
+ describe '#progress_bar_background_color' do
338
+ it 'gets the progress bar background color' do
339
+ @app.payload = { 'progressBC' => '#ff0000' }
340
+ expect(@app.progress_bar_background_color).to eq('#ff0000')
341
+ end
342
+ end
343
+
344
+ describe '#push_icon=' do
345
+ it 'sets the push icon' do
346
+ @app.push_icon = :scroll_once
347
+ expect(@app.payload['pushIcon']).to eq(1)
348
+
349
+ @app.push_icon = :loop
350
+ expect(@app.payload['pushIcon']).to eq(2)
351
+
352
+ @app.push_icon = :fixed
353
+ expect(@app.payload['pushIcon']).to eq(0)
354
+
355
+ @app.push_icon = 2
356
+ expect(@app.payload['pushIcon']).to eq(2)
357
+ end
358
+ end
359
+
360
+ describe '#push_icon' do
361
+ it 'gets the push icon' do
362
+ @app.payload = { 'pushIcon' => 2 }
363
+ expect(@app.push_icon).to eq(:loop)
364
+ end
365
+ end
366
+
367
+ describe '#repeat_text=' do
368
+ it 'sets the text repetition count' do
369
+ @app.repeat_text = 5
370
+ expect(@app.payload['repeat']).to eq(5)
371
+ end
372
+ end
373
+
374
+ describe '#repeat_text' do
375
+ it 'gets the text repetition count' do
376
+ @app.payload = { 'repeat' => 5 }
377
+ expect(@app.repeat_text).to eq(5)
378
+ end
379
+ end
380
+
381
+ describe '#rtttl_sound=' do
382
+ it 'sets the RTTTL sound' do
383
+ @app.rtttl_sound = 'rtttl_string'
384
+ expect(@app.payload['rtttl']).to eq('rtttl_string')
385
+ end
386
+ end
387
+
388
+ describe '#rtttl_sound' do
389
+ it 'gets the RTTTL sound' do
390
+ @app.payload = { 'rtttl' => 'rtttl_string' }
391
+ expect(@app.rtttl_sound).to eq('rtttl_string')
392
+ end
393
+ end
394
+
395
+ describe '#save_app=' do
396
+ it 'sets the save app' do
397
+ @app.save_app = true
398
+ expect(@app.payload['save']).to be true
399
+ end
400
+ end
401
+
402
+ describe '#save_app' do
403
+ it 'gets the save app' do
404
+ @app.payload = { 'save' => true }
405
+ expect(@app.save_app).to eq(true)
406
+ end
407
+ end
408
+
409
+ describe '#scroll_speed=' do
410
+ it 'sets the scroll speed' do
411
+ @app.scroll_speed = 5
412
+ expect(@app.payload['scrollSpeed']).to eq(5)
413
+ end
414
+ end
415
+
416
+ describe '#scroll_speed' do
417
+ it 'gets the scroll speed' do
418
+ @app.payload = { 'scrollSpeed' => 5 }
419
+ expect(@app.scroll_speed).to eq(5)
420
+ end
421
+ end
422
+
423
+ describe '#sound=' do
424
+ it 'sets the sound' do
425
+ @app.sound = 'sound_name'
426
+ expect(@app.payload['sound']).to eq('sound_name')
427
+ end
428
+ end
429
+
430
+ describe '#sound' do
431
+ it 'gets the sound' do
432
+ @app.payload = { 'sound' => 'sound_name' }
433
+ expect(@app.sound).to eq('sound_name')
434
+ end
435
+ end
436
+
437
+ describe '#stack_notifications=' do
438
+ it 'sets the stack notifications' do
439
+ @app.stack_notifications = true
440
+ expect(@app.payload['stack']).to be true
441
+ end
442
+ end
443
+
444
+ describe '#stack_notifications' do
445
+ it 'gets the stack notifications' do
446
+ @app.payload = { 'stack' => true }
447
+ expect(@app.stack_notifications).to eq(true)
448
+ end
449
+ end
450
+
451
+ describe '#text=' do
452
+ it 'sets the text payload' do
453
+ @app.text = 'Hello, World!'
454
+ expect(@app.payload['text']).to eq('Hello, World!')
455
+ end
456
+ end
457
+
458
+ describe '#text' do
459
+ it 'gets the text payload' do
460
+ @app.payload = { 'text' => 'Hello, World!' }
461
+ expect(@app.text).to eq('Hello, World!')
462
+ end
463
+ end
464
+
465
+ describe '#text_case=' do
466
+ it 'sets the text case via helper values' do
467
+ @app.text_case = :default
468
+ expect(@app.payload['textCase']).to eq(0)
469
+
470
+ @app.text_case = :upcase
471
+ expect(@app.payload['textCase']).to eq(1)
472
+
473
+ @app.text_case = :as_is
474
+ expect(@app.payload['textCase']).to eq(2)
475
+ end
476
+
477
+ it 'sets the text case via integer values' do
478
+ @app.text_case = 2
479
+ expect(@app.payload['textCase']).to eq(2)
480
+ end
481
+ end
482
+
483
+ describe '#text_case' do
484
+ it 'gets the text case payload' do
485
+ @app.payload = { 'textCase' => 1 }
486
+ expect(@app.text_case).to eq(:upcase)
487
+ end
488
+ end
489
+
490
+ describe '#top_text=' do
491
+ it 'sets whether to draw the text on top' do
492
+ @app.top_text = true
493
+ expect(@app.payload['topText']).to be true
494
+
495
+ @app.top_text = false
496
+ expect(@app.payload['topText']).to be false
497
+ end
498
+ end
499
+
500
+ describe '#top_text' do
501
+ it 'gets whether to draw the text on top' do
502
+ @app.payload = { 'topText' => true }
503
+ expect(@app.top_text).to eq(true)
504
+ end
505
+ end
506
+
507
+ describe '#text_offset=' do
508
+ it 'sets the text offset' do
509
+ @app.text_offset = 5
510
+ expect(@app.payload['textOffset']).to eq(5)
511
+ end
512
+ end
513
+
514
+ describe '#text_offset' do
515
+ it 'gets the text offset' do
516
+ @app.payload = { 'textOffset' => 5 }
517
+ expect(@app.text_offset).to eq(5)
518
+ end
519
+ end
520
+
521
+ describe '#text_color=' do
522
+ it 'sets the text color via convenience names' do
523
+ @app.text_color = :red
524
+ expect(@app.payload['color']).to eq('#ff0000')
525
+ end
526
+
527
+ it 'sets the text color via hex values' do
528
+ @app.text_color = '#ff0000'
529
+ expect(@app.payload['color']).to eq('#ff0000')
530
+ end
531
+ end
532
+
533
+ describe '#text_color' do
534
+ it 'gets the text color' do
535
+ @app.payload = { 'color' => '#ff0000' }
536
+ expect(@app.text_color).to eq('#ff0000')
537
+ end
538
+ end
539
+
540
+ describe '#text_gradient=' do
541
+ it 'sets the text gradient' do
542
+ @app.text_gradient = { from: :red, to: :blue }
543
+ expect(@app.payload['gradient']).to eq(%w[#ff0000 #0000ff])
544
+ end
545
+
546
+ it 'sets the text gradient via hex values' do
547
+ @app.text_gradient = { from: '#ff0000', to: '#0000ff' }
548
+ expect(@app.payload['gradient']).to eq(%w[#ff0000 #0000ff])
549
+ end
550
+ end
551
+
552
+ describe '#text_gradient' do
553
+ it 'gets the text gradient' do
554
+ @app.payload = { 'gradient' => %w[#ff0000 #0000ff] }
555
+ expect(@app.text_gradient).to eq({ from: '#ff0000', to: '#0000ff' })
556
+ end
557
+
558
+ it 'returns blank values by default' do
559
+ expect(@app.text_gradient).to eq({ from: nil, to: nil })
560
+ end
561
+ end
562
+
563
+ describe '#background_color=' do
564
+ it 'sets the background color to the given color' do
565
+ @app.background_color = :red
566
+ expect(@app.payload['background']).to eq('#ff0000')
567
+
568
+ @app.background_color = '#00ff00'
569
+ expect(@app.payload['background']).to eq('#00ff00')
570
+ end
571
+ end
572
+
573
+ describe '#background_color' do
574
+ it 'gets the background color' do
575
+ @app.payload = { 'background' => '#00ff00' }
576
+ expect(@app.background_color).to eq('#00ff00')
577
+ end
578
+ end
579
+
580
+ describe '#blink_text=' do
581
+ it 'sets the text to blink at the given frequency' do
582
+ @app.blink_text = 1000
583
+ expect(@app.payload['blinkText']).to eq(1000)
584
+
585
+ @app.blink_text = 500
586
+ expect(@app.payload['blinkText']).to eq(500)
587
+ end
588
+ end
589
+
590
+ describe '#blink_text' do
591
+ it 'gets the blinking frequency' do
592
+ @app.payload = { 'blinkText' => 500 }
593
+ expect(@app.blink_text).to eq(500)
594
+ end
595
+ end
596
+
597
+ describe '#fade_text=' do
598
+ it 'sets the text to fade at the given frequency' do
599
+ @app.fade_text = 1000
600
+ expect(@app.payload['fadeText']).to eq(1000)
601
+
602
+ @app.fade_text = 500
603
+ expect(@app.payload['fadeText']).to eq(500)
604
+ end
605
+ end
606
+
607
+ describe '#fade_text' do
608
+ it 'gets the fading frequency' do
609
+ @app.payload = { 'fadeText' => 500 }
610
+ expect(@app.fade_text).to eq(500)
611
+ end
612
+ end
613
+
614
+ describe '#icon=' do
615
+ it 'sets the icon' do
616
+ @app.icon = 'icon_name'
617
+ expect(@app.payload['icon']).to eq('icon_name')
618
+ end
619
+ end
620
+
621
+ describe '#icon' do
622
+ it 'gets the icon' do
623
+ @app.payload = { 'icon' => 'icon_name' }
624
+ expect(@app.icon).to eq('icon_name')
625
+ end
626
+ end
627
+
628
+ describe '#rainbow_effect=' do
629
+ it 'sets the rainbow effect' do
630
+ @app.rainbow_effect = true
631
+ expect(@app.payload['rainbow']).to be true
632
+
633
+ @app.rainbow_effect = false
634
+ expect(@app.payload['rainbow']).to be false
635
+ end
636
+ end
637
+
638
+ describe '#rainbow_effect' do
639
+ it 'gets the rainbow effect' do
640
+ @app.payload = { 'rainbow' => true }
641
+ expect(@app.rainbow_effect).to eq(true)
642
+ end
643
+ end
644
+
645
+ describe '#wakeup_display=' do
646
+ it 'sets the wakeup display' do
647
+ @app.wakeup_display = true
648
+ expect(@app.payload['wakeup']).to be true
649
+
650
+ @app.wakeup_display = false
651
+ expect(@app.payload['wakeup']).to be false
652
+ end
653
+ end
654
+
655
+ describe '#wakeup_display' do
656
+ it 'gets the wakeup display' do
657
+ @app.payload = { 'wakeup' => true }
658
+ expect(@app.wakeup_display).to eq(true)
659
+ end
660
+ end
661
+ end