@@ -381,12 +381,32 @@ HttpPushRgb.prototype = {
381
381
382
382
level = parseInt ( 100 / this . brightness . max * level ) ;
383
383
384
- this . log ( 'brightness is currently at %s %' , level ) ;
384
+ this . log ( 'brightness is currently at %s%' , level ) ;
385
385
callback ( null , level ) ;
386
386
}
387
387
} . bind ( this ) ) ;
388
388
} else {
389
- callback ( null , this . cache . brightness ) ;
389
+ if ( this . color . brightness ) {
390
+ var url = this . color . get_url . url ;
391
+ this . _httpRequest ( url , '' , 'GET' , function ( error , response , responseBody ) {
392
+ if ( ! this . _handleHttpErrorResponse ( 'getBrightness()' , error , response , responseBody , callback ) ) {
393
+ var rgb = responseBody ;
394
+ var levels = this . _rgbToHsl (
395
+ parseInt ( rgb . substr ( 0 , 2 ) , 16 ) ,
396
+ parseInt ( rgb . substr ( 2 , 2 ) , 16 ) ,
397
+ parseInt ( rgb . substr ( 4 , 2 ) , 16 )
398
+ ) ;
399
+
400
+ var brightness = levels [ 2 ] ;
401
+
402
+ this . log ( '... brightness is currently %s. RGB: %s' , brightness , rgb ) ;
403
+ this . cache . brightness = brightness ;
404
+ callback ( null , brightness ) ;
405
+ }
406
+ } . bind ( this ) ) ;
407
+ } else {
408
+ callback ( null , this . cache . brightness ) ;
409
+ }
390
410
}
391
411
} ,
392
412
@@ -401,6 +421,8 @@ HttpPushRgb.prototype = {
401
421
callback ( new Error ( "No 'brightness' defined in configuration" ) ) ;
402
422
return ;
403
423
}
424
+
425
+ this . log ( 'Caching Brightness as %s ...' , level ) ;
404
426
this . cache . brightness = level ;
405
427
406
428
// If achromatic or color.brightness is false, update brightness, otherwise, update HSL as RGB
@@ -412,11 +434,12 @@ HttpPushRgb.prototype = {
412
434
413
435
this . _httpRequest ( url , body , this . brightness . http_method , function ( error , response , responseBody ) {
414
436
if ( ! this . _handleHttpErrorResponse ( 'setBrightness()' , error , response , responseBody , callback ) ) {
415
- this . log ( 'setBrightness() successfully set to %s %' , level ) ;
437
+ this . log ( 'setBrightness() successfully set to %s%' , level ) ;
416
438
callback ( ) ;
417
439
}
418
440
} . bind ( this ) ) ;
419
441
} else {
442
+ this . log ( "Setting brightness via RGB." ) ;
420
443
this . _setRGB ( callback ) ;
421
444
}
422
445
} ,
@@ -445,7 +468,7 @@ HttpPushRgb.prototype = {
445
468
446
469
var hue = levels [ 0 ] ;
447
470
448
- this . log ( '... hue is currently %s' , hue ) ;
471
+ this . log ( '... hue is currently %s. RGB: %s ' , hue , rgb ) ;
449
472
this . cache . hue = hue ;
450
473
callback ( null , hue ) ;
451
474
}
@@ -497,7 +520,7 @@ HttpPushRgb.prototype = {
497
520
498
521
var saturation = levels [ 1 ] ;
499
522
500
- this . log ( '... saturation is currently %s' , saturation ) ;
523
+ this . log ( '... saturation is currently %s. RGB: %s ' , saturation , rgb ) ;
501
524
this . cache . saturation = saturation ;
502
525
callback ( null , saturation ) ;
503
526
}
@@ -548,12 +571,11 @@ HttpPushRgb.prototype = {
548
571
var xyz = convert . rgb . xyz ( rgb ) ;
549
572
var hex = convert . rgb . hex ( rgb ) ;
550
573
551
- if ( xyz == null || xyz . size == 0 ) {
552
- this . log . warn ( "Can't read the brightness property! Ignoring the request" ) ;
574
+ if ( xyz == null || xyz . size == 0 ) {
575
+ this . log . error ( "Failed to convert HSB to xyz values. Cached values: H:%s S:%s B:%s" , this . cache . hue , this . cache . saturation , this . cache . brightness ) ;
553
576
return { url : '' , body : '' } ;
554
577
}
555
578
556
-
557
579
var xy = {
558
580
x : ( xyz [ 0 ] / 100 / ( xyz [ 0 ] / 100 + xyz [ 1 ] / 100 + xyz [ 2 ] / 100 ) ) . toFixed ( 4 ) ,
559
581
y : ( xyz [ 1 ] / 100 / ( xyz [ 0 ] / 100 + xyz [ 1 ] / 100 + xyz [ 2 ] / 100 ) ) . toFixed ( 4 )
0 commit comments