@@ -381,12 +381,32 @@ HttpPushRgb.prototype = {
381381
382382 level = parseInt ( 100 / this . brightness . max * level ) ;
383383
384- this . log ( 'brightness is currently at %s %' , level ) ;
384+ this . log ( 'brightness is currently at %s%' , level ) ;
385385 callback ( null , level ) ;
386386 }
387387 } . bind ( this ) ) ;
388388 } 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+ }
390410 }
391411 } ,
392412
@@ -401,6 +421,8 @@ HttpPushRgb.prototype = {
401421 callback ( new Error ( "No 'brightness' defined in configuration" ) ) ;
402422 return ;
403423 }
424+
425+ this . log ( 'Caching Brightness as %s ...' , level ) ;
404426 this . cache . brightness = level ;
405427
406428 // If achromatic or color.brightness is false, update brightness, otherwise, update HSL as RGB
@@ -412,11 +434,12 @@ HttpPushRgb.prototype = {
412434
413435 this . _httpRequest ( url , body , this . brightness . http_method , function ( error , response , responseBody ) {
414436 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 ) ;
416438 callback ( ) ;
417439 }
418440 } . bind ( this ) ) ;
419441 } else {
442+ this . log ( "Setting brightness via RGB." ) ;
420443 this . _setRGB ( callback ) ;
421444 }
422445 } ,
@@ -445,7 +468,7 @@ HttpPushRgb.prototype = {
445468
446469 var hue = levels [ 0 ] ;
447470
448- this . log ( '... hue is currently %s' , hue ) ;
471+ this . log ( '... hue is currently %s. RGB: %s ' , hue , rgb ) ;
449472 this . cache . hue = hue ;
450473 callback ( null , hue ) ;
451474 }
@@ -497,7 +520,7 @@ HttpPushRgb.prototype = {
497520
498521 var saturation = levels [ 1 ] ;
499522
500- this . log ( '... saturation is currently %s' , saturation ) ;
523+ this . log ( '... saturation is currently %s. RGB: %s ' , saturation , rgb ) ;
501524 this . cache . saturation = saturation ;
502525 callback ( null , saturation ) ;
503526 }
@@ -548,12 +571,11 @@ HttpPushRgb.prototype = {
548571 var xyz = convert . rgb . xyz ( rgb ) ;
549572 var hex = convert . rgb . hex ( rgb ) ;
550573
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 ) ;
553576 return { url : '' , body : '' } ;
554577 }
555578
556-
557579 var xy = {
558580 x : ( xyz [ 0 ] / 100 / ( xyz [ 0 ] / 100 + xyz [ 1 ] / 100 + xyz [ 2 ] / 100 ) ) . toFixed ( 4 ) ,
559581 y : ( xyz [ 1 ] / 100 / ( xyz [ 0 ] / 100 + xyz [ 1 ] / 100 + xyz [ 2 ] / 100 ) ) . toFixed ( 4 )
0 commit comments