Fixed some thing
* api -> www * fixed test lights (for some reason it was sent back in time)
This commit is contained in:
@@ -24,8 +24,13 @@ import java.util.Arrays;
|
|||||||
public class AuthFITBIT {
|
public class AuthFITBIT {
|
||||||
|
|
||||||
/** Directory to store user credentials. */
|
/** Directory to store user credentials. */
|
||||||
|
/* Throw a Warning when change permission: they said it's a google bug 'cause is meant to run in linux/unix
|
||||||
|
*
|
||||||
|
* https://stackoverflow.com/questions/30634827/warning-unable-to-change-permissions-for-everybody
|
||||||
|
* https://github.com/google/google-http-java-client/issues/315
|
||||||
|
*/
|
||||||
private static final java.io.File DATA_STORE_DIR =
|
private static final java.io.File DATA_STORE_DIR =
|
||||||
new java.io.File(System.getProperty("user.home"), ".store/dailymotion_sample");
|
new java.io.File(System.getProperty("user.home"), ".store/seniorAssistant");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Global instance of the {@link DataStoreFactory}. The best practice is to make it a single
|
* Global instance of the {@link DataStoreFactory}. The best practice is to make it a single
|
||||||
@@ -34,17 +39,20 @@ public class AuthFITBIT {
|
|||||||
private static FileDataStoreFactory DATA_STORE_FACTORY;
|
private static FileDataStoreFactory DATA_STORE_FACTORY;
|
||||||
|
|
||||||
/** OAuth 2 scope. */
|
/** OAuth 2 scope. */
|
||||||
private static final String SCOPE = "activity";
|
private static final String SCOPE[] = new String[]{"activity","heartrate","location","sleep"};
|
||||||
//private static final String SCOPE[] = new String[]{"activity","heartrate","location","sleep"};
|
|
||||||
/** Global instance of the HTTP transport. */
|
/** Global instance of the HTTP transport. */
|
||||||
private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
|
private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
|
||||||
|
|
||||||
/** Global instance of the JSON factory. */
|
/** Global instance of the JSON factory. */
|
||||||
static final JsonFactory JSON_FACTORY = new JacksonFactory();
|
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
|
||||||
|
|
||||||
|
/* When i try to accept the request it'll send a 401 Unauthorized
|
||||||
|
* on internet i found that this message appears when the client put a wrong
|
||||||
|
* header, client_id or client_secret
|
||||||
|
* https://dev.fitbit.com/build/reference/web-api/oauth2/ -> ALT+F "401 Unauthorized"
|
||||||
|
*/
|
||||||
private static final String TOKEN_SERVER_URL = " https://api.fitbit.com/oauth2/token";
|
private static final String TOKEN_SERVER_URL = " https://api.fitbit.com/oauth2/token";
|
||||||
private static final String AUTHORIZATION_SERVER_URL =
|
private static final String AUTHORIZATION_SERVER_URL = "https://www.fitbit.com/oauth2/authorize";
|
||||||
"https://api.fitbit.com/oauth2/authorize";
|
|
||||||
|
|
||||||
/** Authorizes the installed application to access user's protected data. */
|
/** Authorizes the installed application to access user's protected data. */
|
||||||
private static Credential authorize() throws Exception {
|
private static Credential authorize() throws Exception {
|
||||||
@@ -104,10 +112,11 @@ public class AuthFITBIT {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
run(requestFactory);
|
run(requestFactory);
|
||||||
|
System.err.print("DONE");
|
||||||
// Success!
|
// Success!
|
||||||
return;
|
return;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println(e.getMessage());
|
System.err.println(e.getClass().getSimpleName()+" "+e.getMessage());
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,20 @@
|
|||||||
import device.Hue;
|
import device.Hue;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class TestLights {
|
public class TestLights {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
synchronized public void firstTestLights() throws InterruptedException {
|
synchronized public void firstTestLights() throws InterruptedException {
|
||||||
Hue lights = new Hue("http://localhost/api/newdeveloper/");
|
Hue lights = new Hue();
|
||||||
|
|
||||||
|
Set<String> toRemove = new HashSet<>();
|
||||||
|
for(String str: lights.getNameLights())
|
||||||
|
if(!str.equals("4"))
|
||||||
|
toRemove.add(str);
|
||||||
|
lights.removeLights(toRemove);
|
||||||
|
|
||||||
for(int i=0; i<10; i++) {
|
for(int i=0; i<10; i++) {
|
||||||
lights.turnOn();
|
lights.turnOn();
|
||||||
@@ -15,16 +24,19 @@ public class TestLights {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lights.turnOn();
|
lights.turnOn();
|
||||||
for(int i=0; i<256; i++) {
|
|
||||||
lights.setBrightness(i);
|
|
||||||
this.wait(50);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i=256; i>=0; i--) {
|
for(int i=256; i>=0; i--) {
|
||||||
lights.setBrightness(i);
|
lights.setBrightness(i);
|
||||||
this.wait(50);
|
this.wait(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(int i=0; i<256; i++) {
|
||||||
|
lights.setBrightness(i);
|
||||||
|
this.wait(50);
|
||||||
|
}
|
||||||
|
|
||||||
|
lights.colorLoop();
|
||||||
|
this.wait(10000); // 10 sec
|
||||||
|
lights.turnOff();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user