Skip to content

Commit

Permalink
Tested jointeam and now working
Browse files Browse the repository at this point in the history
  • Loading branch information
retrodaredevil committed Aug 8, 2020
1 parent c63554c commit 5f63005
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import me.retrodaredevil.solarthing.util.JacksonUtil;
import net.bis5.mattermost.model.Team;
import okhttp3.OkHttpClient;
import okhttp3.ResponseBody;
import okhttp3.logging.HttpLoggingInterceptor;
import org.ektorp.CouchDbInstance;
import org.ektorp.http.HttpClient;
Expand Down Expand Up @@ -236,7 +237,7 @@ private static int startRealTimeProgram(
) {
if (options.isJoinTeams()) {
LOGGER.info("Going to join SolarThing team...");
Call<String> call = service.joinTeam(new TeamParameters(PVOutputConstants.SOLARTHING_TEAM_ID));
Call<String> call = service.joinTeam(PVOutputConstants.SOLARTHING_TEAM_ID);
LOGGER.debug("Executing call");
Response<String> response = null;
try {
Expand All @@ -246,19 +247,30 @@ private static int startRealTimeProgram(
}
if (response != null) {
int code = response.code();
String message = response.message();
String errorBody;
try {
ResponseBody responseBody = response.errorBody();
if (responseBody != null) {
errorBody = responseBody.string();
} else {
errorBody = "null";
}
} catch (IOException e) {
e.printStackTrace();
errorBody = "exception occurred";
}
if (code == 200) {
LOGGER.info("Joined the SolarThing team! Response: " + message);
LOGGER.info("Joined the SolarThing team! Response: " + response.body());
} else if (code == 400) {
if (message.contains("already")) {
LOGGER.info("Already joined SolarThing team. Response: " + message);
} else if (message.contains("must have at least")) {
LOGGER.info("We will try joining SolarThing team later once we have more outputs. Response: " + message);
if (errorBody.contains("already")) {
LOGGER.info("Already joined SolarThing team. Response: " + errorBody);
} else if (errorBody.contains("must have at least")) {
LOGGER.info("We will try joining SolarThing team later once we have more outputs. Response: " + errorBody);
} else {
LOGGER.error("Error joining SolarThing team! Response: " + message);
LOGGER.error("Error joining SolarThing team! Response: " + errorBody);
}
} else {
LOGGER.error("Unknown error joining SolarThing team! Response: " + message);
LOGGER.error("Unknown error joining SolarThing team! Response: " + errorBody);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonProperty;

@Deprecated
public final class TeamParameters {
private final int teamId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import me.retrodaredevil.solarthing.pvoutput.data.AddBatchOutputParameters;
import me.retrodaredevil.solarthing.pvoutput.data.AddOutputParameters;
import me.retrodaredevil.solarthing.pvoutput.data.AddStatusParameters;
import me.retrodaredevil.solarthing.pvoutput.data.TeamParameters;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Query;

public interface PVOutputService {
// Start Service API // https://pvoutput.org/help.html#api-spec
Expand All @@ -19,5 +19,5 @@ public interface PVOutputService {
Call<String> addBatchOutput(@Body AddBatchOutputParameters parameters);

@GET("jointeam.jsp")
Call<String> joinTeam(@Body TeamParameters teamParameters);
Call<String> joinTeam(@Query("tid") int teamId);
}

0 comments on commit 5f63005

Please sign in to comment.