I did not think of that. Maybe you are right. This is inside the ConnectToBridge()
ConnectToHueBridge(MyHue:any): Observable<any>{
if(!(localStorage as any).MyHueBridgeIP){ // No chaced BridgeIP?
console.log("Trying to discover HUE Bridge via Hue Portal")
//Get brdige IP
MyHue.PortalDiscoverLocalBridges().then(function BridgesDiscovered(){
console.log("Bridge IP: " + MyHue.BridgeIP);
//Get bridge Configuration
MyHue.BridgeGetConfig().then(function BridgeConfigReceived(){
console.log("Brdige name: " + MyHue.BridgeName);
//Get Bridge Data
MyHue.BridgeGetData().then(function BridgeDataReceived(){
(localStorage as any).MyHueBridgeIP = MyHue.BridgeIP; // Chaching Bridge IP
console.log("Received data from bridge");
}, function UnableToRetreiveBridgeData(){
console.log ("Unable to receive bridge data, please press the connect button on the hue brdige ");
MyHue.BridgeCreateUser().then(function BridgeUserCreated(){
(localStorage as any).MyHueBridgeIP = MyHue.BridgeIP; //Chache Bridge IP
console.log("Connected to the Bridge: " + MyHue.UserName);
return;
}, function UnableToCreateUseronBridge() {
console.log("Unable to create new User, please press the connect button on the hue bridge ");
return;
});
});
}, function UnableToRetreiveBridgeConfig() {
console.log ("Unable to receive bridge config, please press the connect button on the hue bridge ");
return;
});
}, function UnableToDiscoverLocalBridgesViaPortal(){
console.log("Error discovering bridge IP, please press the connect button on the hue bridge ");
return;
});
}else{// Using chached Bridge IP
console.log("Using chached Bridge IP");
MyHue.BridgeIP = (localStorage as any).MyHueBridgeIP;
console.log("Cached Bridge IP: " + MyHue.BridgeIP);
MyHue.BridgeGetConfig().then(function CachedBridgeConfigReceived(){
console.log("Bridge Name: " + MyHue.BridgeName);
MyHue.BridgeGetData().then(function ChachedBridgeDataReveiced(){
console.log("connected");
}, function UnableToRetreiveCachedBridgeData(){
delete (localStorage as any).MyHueBridgeIP // not Whitelisted anymore
console.log("Unable to Retreive Cached Bridge Data");
return;
});
}, function UnableToRetreiveBridgeConfig(){
delete (localStorage as any).MyHueBridgeIP; //not found anymore
console.log("Unable to receive chached bridge config");
});
}
return Observable.of(true);
}