From 4695b9ddfc801144791d29ce17734cf25f7d5e38 Mon Sep 17 00:00:00 2001 From: Giacomo Date: Fri, 1 Jun 2018 23:10:15 +0200 Subject: [PATCH] Fixed some thing * api -> www * fixed test lights (for some reason it was sent back in time) --- src/main/java/manage/AuthFITBIT.java | 23 ++++++++++++++++------- src/test/java/TestLights.java | 24 ++++++++++++++++++------ 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/main/java/manage/AuthFITBIT.java b/src/main/java/manage/AuthFITBIT.java index e4b223a..30739df 100644 --- a/src/main/java/manage/AuthFITBIT.java +++ b/src/main/java/manage/AuthFITBIT.java @@ -24,8 +24,13 @@ import java.util.Arrays; public class AuthFITBIT { /** 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 = - 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 @@ -34,17 +39,20 @@ public class AuthFITBIT { private static FileDataStoreFactory DATA_STORE_FACTORY; /** 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. */ private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport(); /** 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 AUTHORIZATION_SERVER_URL = - "https://api.fitbit.com/oauth2/authorize"; + private static final String AUTHORIZATION_SERVER_URL = "https://www.fitbit.com/oauth2/authorize"; /** Authorizes the installed application to access user's protected data. */ private static Credential authorize() throws Exception { @@ -104,10 +112,11 @@ public class AuthFITBIT { } }); run(requestFactory); + System.err.print("DONE"); // Success! return; } catch (IOException e) { - System.err.println(e.getMessage()); + System.err.println(e.getClass().getSimpleName()+" "+e.getMessage()); } catch (Throwable t) { t.printStackTrace(); } diff --git a/src/test/java/TestLights.java b/src/test/java/TestLights.java index 7f0cb51..3878584 100644 --- a/src/test/java/TestLights.java +++ b/src/test/java/TestLights.java @@ -1,11 +1,20 @@ import device.Hue; import org.junit.Test; +import java.util.HashSet; +import java.util.Set; + public class TestLights { @Test synchronized public void firstTestLights() throws InterruptedException { - Hue lights = new Hue("http://localhost/api/newdeveloper/"); + Hue lights = new Hue(); + + Set 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++) { lights.turnOn(); @@ -15,16 +24,19 @@ public class TestLights { } lights.turnOn(); - for(int i=0; i<256; i++) { - lights.setBrightness(i); - this.wait(50); - } - for(int i=256; i>=0; i--) { lights.setBrightness(i); 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(); } }