mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-13 11:17:33 +01:00
Amazfit GTS 3: Fix battery drain due to unanswered weather requests
- Reply with HTTP 404 to unknown weather endpoints - Add some missing fields to weather responses The official Zepp app itself gets a 404 when calling a /weather/tide endpoint, so we don't know what the watch is supposed to receive. Weather also seems to still not work correctly on the GTS 3, but this at least fixes the request spam that was coming from the watch on the tide endpoint.
This commit is contained in:
parent
cdc60cec51
commit
a6cb73e843
@ -2237,9 +2237,16 @@ public abstract class Huami2021Support extends HuamiSupport {
|
|||||||
final Huami2021Weather.Response response = Huami2021Weather.handleHttpRequest(path, query);
|
final Huami2021Weather.Response response = Huami2021Weather.handleHttpRequest(path, query);
|
||||||
|
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
replyHttpSuccess(requestId, response.toJson());
|
replyHttpSuccess(requestId, 200, response.toJson());
|
||||||
return;
|
} else {
|
||||||
|
final Huami2021Weather.Response notFoundResponse = new Huami2021Weather.ErrorResponse(
|
||||||
|
-2001,
|
||||||
|
"Not found"
|
||||||
|
);
|
||||||
|
replyHttpSuccess(requestId, 404, notFoundResponse.toJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.error("Unhandled URL {}", url);
|
LOG.error("Unhandled URL {}", url);
|
||||||
@ -2273,8 +2280,8 @@ public abstract class Huami2021Support extends HuamiSupport {
|
|||||||
writeToChunked2021("http reply no internet", Huami2021Service.CHUNKED2021_ENDPOINT_HTTP, cmd, true);
|
writeToChunked2021("http reply no internet", Huami2021Service.CHUNKED2021_ENDPOINT_HTTP, cmd, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void replyHttpSuccess(final byte requestId, final String content) {
|
private void replyHttpSuccess(final byte requestId, final int status, final String content) {
|
||||||
LOG.debug("Replying with success to http request {} with {}", requestId, content);
|
LOG.debug("Replying with http {} request {} with {}", status, requestId, content);
|
||||||
|
|
||||||
final byte[] contentBytes = content.getBytes(StandardCharsets.UTF_8);
|
final byte[] contentBytes = content.getBytes(StandardCharsets.UTF_8);
|
||||||
final ByteBuffer buf = ByteBuffer.allocate(8 + contentBytes.length);
|
final ByteBuffer buf = ByteBuffer.allocate(8 + contentBytes.length);
|
||||||
@ -2283,7 +2290,7 @@ public abstract class Huami2021Support extends HuamiSupport {
|
|||||||
buf.put((byte) 0x02);
|
buf.put((byte) 0x02);
|
||||||
buf.put(requestId);
|
buf.put(requestId);
|
||||||
buf.put(HTTP_RESPONSE_SUCCESS);
|
buf.put(HTTP_RESPONSE_SUCCESS);
|
||||||
buf.put((byte) 0xc8); // ?
|
buf.put((byte) status);
|
||||||
buf.putInt(contentBytes.length);
|
buf.putInt(contentBytes.length);
|
||||||
buf.put(contentBytes);
|
buf.put(contentBytes);
|
||||||
|
|
||||||
|
@ -99,6 +99,24 @@ public class Huami2021Weather {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class ErrorResponse extends Response {
|
||||||
|
private final int code;
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
public ErrorResponse(final int code, final String message) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static abstract class Response {
|
public static abstract class Response {
|
||||||
public String toJson() {
|
public String toJson() {
|
||||||
return GSON.toJson(this);
|
return GSON.toJson(this);
|
||||||
@ -114,13 +132,13 @@ public class Huami2021Weather {
|
|||||||
// locationKey=00.000,-0.000,xiaomi_accu:000000
|
// locationKey=00.000,-0.000,xiaomi_accu:000000
|
||||||
public static class ForecastResponse extends Response {
|
public static class ForecastResponse extends Response {
|
||||||
public Date pubTime;
|
public Date pubTime;
|
||||||
public List<Object> humidity = new ArrayList<>();
|
public List<String> humidity = new ArrayList<>();
|
||||||
public List<Range> temperature = new ArrayList<>();
|
public List<Range> temperature = new ArrayList<>();
|
||||||
public List<Range> weather = new ArrayList<>();
|
public List<Range> weather = new ArrayList<>();
|
||||||
public List<Range> windDirection = new ArrayList<>();
|
public List<Range> windDirection = new ArrayList<>();
|
||||||
public List<Range> sunRiseSet = new ArrayList<>();
|
public List<Range> sunRiseSet = new ArrayList<>();
|
||||||
public List<Range> windSpeed = new ArrayList<>();
|
public List<Range> windSpeed = new ArrayList<>();
|
||||||
public Object moonRiseSet = new Object();
|
public Object moonRiseSet = new Object(); // MoonRiseSet
|
||||||
public List<Object> airQualities = new ArrayList<>();
|
public List<Object> airQualities = new ArrayList<>();
|
||||||
|
|
||||||
public ForecastResponse(final WeatherSpec weatherSpec, final int days) {
|
public ForecastResponse(final WeatherSpec weatherSpec, final int days) {
|
||||||
@ -176,6 +194,11 @@ public class Huami2021Weather {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class MoonRiseSet {
|
||||||
|
public List<String> moonPhaseValue = new ArrayList<>();
|
||||||
|
public List<Range> moonRise = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
private static class Range {
|
private static class Range {
|
||||||
public String from;
|
public String from;
|
||||||
public String to;
|
public String to;
|
||||||
@ -224,6 +247,7 @@ public class Huami2021Weather {
|
|||||||
// locationKey=00.000,-0.000,xiaomi_accu:000000
|
// locationKey=00.000,-0.000,xiaomi_accu:000000
|
||||||
public static class CurrentResponse extends Response {
|
public static class CurrentResponse extends Response {
|
||||||
public CurrentWeatherModel currentWeatherModel;
|
public CurrentWeatherModel currentWeatherModel;
|
||||||
|
public Object aqiModel = new Object();
|
||||||
|
|
||||||
public CurrentResponse(final WeatherSpec weatherSpec) {
|
public CurrentResponse(final WeatherSpec weatherSpec) {
|
||||||
this.currentWeatherModel = new CurrentWeatherModel(weatherSpec);
|
this.currentWeatherModel = new CurrentWeatherModel(weatherSpec);
|
||||||
@ -305,14 +329,14 @@ public class Huami2021Weather {
|
|||||||
// isGlobal=true
|
// isGlobal=true
|
||||||
// locationKey=00.000,-0.000,xiaomi_accu:000000
|
// locationKey=00.000,-0.000,xiaomi_accu:000000
|
||||||
public static class HourlyResponse extends Response {
|
public static class HourlyResponse extends Response {
|
||||||
public Object pubTime;
|
public Date pubTime;
|
||||||
public Object weather;
|
public List<String> weather;
|
||||||
public Object temperature;
|
public List<String> temperature;
|
||||||
public Object humidity;
|
public List<String> humidity;
|
||||||
public Object fxTime;
|
public List<String> fxTime; // pubTime format
|
||||||
public Object windDirection;
|
public List<String> windDirection;
|
||||||
public Object windSpeed;
|
public List<String> windSpeed;
|
||||||
public Object windScale;
|
public List<String> windScale; // each element in the form of 1-2
|
||||||
}
|
}
|
||||||
|
|
||||||
// /weather/alerts
|
// /weather/alerts
|
||||||
@ -323,6 +347,7 @@ public class Huami2021Weather {
|
|||||||
// isGlobal=true
|
// isGlobal=true
|
||||||
// locationKey=00.000,-0.000,xiaomi_accu:000000
|
// locationKey=00.000,-0.000,xiaomi_accu:000000
|
||||||
public static class AlertsResponse extends Response {
|
public static class AlertsResponse extends Response {
|
||||||
|
public List<IndexEntry> alerts = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
//@RequiresApi(api = Build.VERSION_CODES.O)
|
//@RequiresApi(api = Build.VERSION_CODES.O)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user