Skip to content

Commit aaa4235

Browse files
authored
refactor: Align Phillips Hue to reworked device handling (#712)
* Align PhilipsHue (Classic) * Minor Device corrections * Have code working with Qt < 5.10 * Fixes on Hue Wizzard * Fixes on Hue Wizzard * Calculate Latchtime only for lights updated by hyperion * Allow to disable restoring original light's state * Fix - LightIDs / LightMap vectors were not cleared when reopening the device * Reduce API Calls for state updates by consolidation
1 parent 2739aec commit aaa4235

File tree

11 files changed

+1065
-391
lines changed

11 files changed

+1065
-391
lines changed

assets/webconfig/i18n/de.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@
426426
"edt_dev_spec_transistionTime_title": "Übergangszeit",
427427
"edt_dev_spec_switchOffOnBlack_title": "Aus bei schwarz",
428428
"edt_dev_spec_brightnessFactor_title": "Helligkeitsfaktor",
429+
"edt_dev_spec_restoreOriginalState_title" : "Lampen Originalzustand wiederhestellen",
429430
"edt_dev_spec_ledType_title": "LED typ",
430431
"edt_dev_spec_uid_title": "UID",
431432
"edt_dev_spec_intervall_title": "Intervall",

assets/webconfig/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@
425425
"edt_dev_spec_transistionTime_title" : "Transition time",
426426
"edt_dev_spec_switchOffOnBlack_title" : "Switch off on black",
427427
"edt_dev_spec_brightnessFactor_title" : "Brightness factor",
428+
"edt_dev_spec_restoreOriginalState_title" : "Restore lights' original state",
428429
"edt_dev_spec_ledType_title" : "LED Type",
429430
"edt_dev_spec_uid_title" : "UID",
430431
"edt_dev_spec_intervall_title" : "Interval",

assets/webconfig/js/wizard.js

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -567,23 +567,35 @@ function checkHueBridge(cb,hueUser){
567567
timeout: 2000
568568
})
569569
.done( function( data, textStatus, jqXHR ) {
570-
if(Array.isArray(data) && data[0].error && data[0].error.type == 4)
571-
cb(true);
572-
else if(Array.isArray(data) && data[0].error)
573-
cb(false);
570+
if( Array.isArray(data) && data[0].error)
571+
{
572+
if ( data[0].error.type == 3 || data[0].error.type == 4)
573+
{
574+
cb(true, usr);
575+
}
576+
else
577+
{
578+
cb(false);
579+
}
580+
}
574581
else
575-
cb(true);
582+
{
583+
cb(true, usr);
584+
}
585+
576586
})
577587
.fail( function( jqXHR, textStatus ) {
578588
cb(false);
579589
});
580590
}
581591

582-
function checkUserResult(reply){
592+
function checkUserResult(reply, usr){
593+
583594
if(reply)
584595
{
585596
$('#wiz_hue_usrstate').html("");
586597
$('#wiz_hue_create_user').toggle(false);
598+
$('#user').val(usr);
587599
get_hue_lights();
588600
}
589601
else
@@ -640,17 +652,22 @@ function checkBridgeResult(reply){
640652

641653
function identHueId(id, off)
642654
{
643-
var on = true;
644655
if(off !== true)
656+
{
645657
setTimeout(identHueId,1500,id,true);
658+
var put_data = '{"on":true,"bri":254,"hue":47000,"sat":254}';
659+
}
646660
else
647-
on = false;
661+
{
662+
var put_data = '{"on":false}';
663+
}
648664

649665
$.ajax({
650666
url: 'http://'+$('#ip').val()+'/api/'+$('#user').val()+'/lights/'+id+'/state',
651667
type: 'PUT',
652668
timeout: 2000,
653-
data: ' {"on":'+on+', "sat":254, "bri":254,"hue":47000}'
669+
670+
data: put_data
654671
})
655672
}
656673

@@ -686,7 +703,9 @@ function beginWizardHue()
686703

687704
//check if ip is empty/reachable/search for bridge
688705
if(conf_editor.getEditor("root.specificOptions.output").getValue() == "")
706+
{
689707
getHueIPs();
708+
}
690709
else
691710
{
692711
var ip = conf_editor.getEditor("root.specificOptions.output").getValue();
@@ -719,6 +738,7 @@ function beginWizardHue()
719738
}
720739
}
721740

741+
var ledCount= Object.keys(lightIDs).length;
722742

723743
window.serverConfig.leds = hueLedConfig;
724744

@@ -736,6 +756,7 @@ function beginWizardHue()
736756
d.lightIds = finalLightIds;
737757
d.username = $('#user').val();
738758
d.type = "philipshue";
759+
d.hardwareLedCount = ledCount;
739760
d.transitiontime = 1;
740761
d.switchOffOnBlack = true;
741762

@@ -814,6 +835,7 @@ function get_hue_lights(){
814835

815836
for(var lightid in r)
816837
{
838+
817839
$('.lidsb').append(createTableRow([lightid+' ('+r[lightid].name+')', '<select id="hue_'+lightid+'" class="hue_sel_watch form-control"><option value="disabled">'+$.i18n('wiz_hue_ids_disabled')+'</option><option value="top">'+$.i18n('conf_leds_layout_cl_top')+'</option><option value="bottom">'+$.i18n('conf_leds_layout_cl_bottom')+'</option><option value="left">'+$.i18n('conf_leds_layout_cl_left')+'</option><option value="right">'+$.i18n('conf_leds_layout_cl_right')+'</option><option value="entire">'+$.i18n('wiz_hue_ids_entire')+'</option></select>','<button class="btn btn-sm btn-primary" onClick=identHueId('+lightid+')>'+$.i18n('wiz_hue_blinkblue',lightid)+'</button>']));
818840
}
819841

include/leddevice/LedDevice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ class LedDevice : public QObject
5959
unsigned int getLedCount() const { return _ledCount; }
6060

6161
bool enabled() const { return _enabled; }
62+
6263
int getLatchTime() const { return _latchTime_ms; }
64+
void setLatchTime( int latchTime_ms );
6365

6466
///
6567
/// Check, if device is ready to be used

libsrc/leddevice/LedDevice.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ void LedDevice::setLedCount(unsigned int ledCount)
231231
_ledRGBWCount = _ledCount * sizeof(ColorRgbw);
232232
}
233233

234+
void LedDevice::setLatchTime( int latchTime_ms )
235+
{
236+
_latchTime_ms = latchTime_ms;
237+
Debug(_log, "LatchTime updated to %dms", this->getLatchTime());
238+
}
239+
234240
int LedDevice::rewriteLeds()
235241
{
236242
int retval = -1;

libsrc/leddevice/dev_net/LedDeviceNanoleaf.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ static const char STATE_ONOFF_VALUE[] = "value";
3737
static const char STATE_VALUE_TRUE[] = "true";
3838
static const char STATE_VALUE_FALSE[] = "false";
3939

40-
//Device Data elements
40+
// Device Data elements
4141
static const char DEV_DATA_NAME[] = "name";
4242
static const char DEV_DATA_MODEL[] = "model";
4343
static const char DEV_DATA_MANUFACTURER[] = "manufacturer";
4444
static const char DEV_DATA_FIRMWAREVERSION[] = "firmwareVersion";
4545

46-
//Nanoleaf Stream Control elements
46+
// Nanoleaf Stream Control elements
4747
//static const char STREAM_CONTROL_IP[] = "streamControlIpAddr";
4848
static const char STREAM_CONTROL_PORT[] = "streamControlPort";
4949
//static const char STREAM_CONTROL_PROTOCOL[] = "streamControlProtocol";
@@ -59,7 +59,7 @@ static const char API_STATE[] ="state";
5959
static const char API_PANELLAYOUT[] = "panelLayout";
6060
static const char API_EFFECT[] = "effects";
6161

62-
//Nanoleaf ssdp services
62+
// Nanoleaf ssdp services
6363
static const char SSDP_CANVAS[] = "nanoleaf:nl29";
6464
static const char SSDP_LIGHTPANELS[] = "nanoleaf_aurora:light";
6565
const int SSDP_TIMEOUT = 5000; // timout in ms
@@ -132,7 +132,7 @@ bool LedDeviceNanoleaf::init(const QJsonObject &deviceConfig)
132132
if ( _hostname.isEmpty() )
133133
{
134134
//Discover Nanoleaf device
135-
if ( !discoverNanoleafDevice() )
135+
if ( !discoverDevice() )
136136
{
137137
this->setInError("No target IP defined nor Nanoleaf device was discovered");
138138
return false;
@@ -256,24 +256,17 @@ int LedDeviceNanoleaf::open()
256256

257257
if ( init(_devConfig) )
258258
{
259-
if ( !initNetwork() )
259+
if ( initLeds() )
260260
{
261-
this->setInError( "UDP Network error!" );
262-
}
263-
else
264-
{
265-
if ( initLeds() )
266-
{
267-
_deviceReady = true;
268-
setEnable(true);
269-
retval = 0;
270-
}
261+
_deviceReady = true;
262+
setEnable(true);
263+
retval = 0;
271264
}
272265
}
273266
return retval;
274267
}
275268

276-
bool LedDeviceNanoleaf::discoverNanoleafDevice()
269+
bool LedDeviceNanoleaf::discoverDevice()
277270
{
278271

279272
bool isDeviceFound (false);

libsrc/leddevice/dev_net/LedDeviceNanoleaf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class LedDeviceNanoleaf : public ProviderUdp
103103
///
104104
/// @return True, if Nanoleaf device was found
105105
///
106-
bool discoverNanoleafDevice();
106+
bool discoverDevice();
107107

108108
///
109109
/// Change Nanoleaf device to External Control (UDP) mode

0 commit comments

Comments
 (0)