[Netatmo] Floodlight issue on Presence Camera (#14492)

* Solving issue #14458

Signed-off-by: clinique <gael@lhopital.org>

* Removes the usage of "app.netatmo.net" since api now holds these entry points.
I think it was the origin of malfunction of floodlight (to be controlled by somebody who has one).

--------

Signed-off-by: clinique <gael@lhopital.org>
This commit is contained in:
Gaël L'hopital 2023-02-27 08:59:20 +01:00 committed by GitHub
parent fe0f49ea63
commit c95380f503
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 23 deletions

View File

@ -537,7 +537,7 @@ Warnings:
| live | vpn-stream-url (*) | String | Read-only | Url of the live stream for this camera through Netatmo VPN. |
| signal | strength | Number | Read-only | Signal strength (0 for no signal, 1 for weak...) |
| signal | value | Number:Power | Read-only | Signal strength in dBm |
| presence | floodlight | Switch | Read-write | Sets the floodlight to ON/OFF/AUTO |
| presence | floodlight | String | Read-write | Sets the floodlight to ON/OFF/AUTO |
| last-event | type | String | Read-only | Type of event |
| last-event | subtype | String | Read-only | Sub-type of event |
| last-event | time | DateTime | Read-only | Time of occurrence of event |

View File

@ -43,9 +43,8 @@ import org.slf4j.LoggerFactory;
*/
@NonNullByDefault
public class AuthenticationApi extends RestManager {
private static final UriBuilder OAUTH_BUILDER = getApiBaseBuilder().path(PATH_OAUTH);
private static final UriBuilder AUTH_BUILDER = OAUTH_BUILDER.clone().path(SUB_PATH_AUTHORIZE);
private static final URI TOKEN_URI = OAUTH_BUILDER.clone().path(SUB_PATH_TOKEN).build();
private static final UriBuilder AUTH_BUILDER = getApiBaseBuilder(PATH_OAUTH, SUB_PATH_AUTHORIZE);
private static final URI TOKEN_URI = getApiBaseBuilder(PATH_OAUTH, SUB_PATH_TOKEN).build();
private final Logger logger = LoggerFactory.getLogger(AuthenticationApi.class);
private final ScheduledExecutorService scheduler;

View File

@ -45,7 +45,7 @@ public class EnergyApi extends RestManager {
* response body
*/
public void switchSchedule(String homeId, String scheduleId) throws NetatmoException {
UriBuilder uriBuilder = getAppUriBuilder(SUB_PATH_SWITCH_SCHEDULE, PARAM_HOME_ID, homeId, PARAM_SCHEDULE_ID,
UriBuilder uriBuilder = getApiUriBuilder(SUB_PATH_SWITCH_SCHEDULE, PARAM_HOME_ID, homeId, PARAM_SCHEDULE_ID,
scheduleId);
post(uriBuilder, ApiResponse.Ok.class, null);
}

View File

@ -19,6 +19,7 @@ import java.net.URI;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.ws.rs.core.UriBuilder;
@ -36,9 +37,7 @@ import org.openhab.binding.netatmo.internal.handler.ApiBridgeHandler;
*/
@NonNullByDefault
public abstract class RestManager {
private static final UriBuilder API_BASE_BUILDER = UriBuilder.fromUri(URL_API);
private static final UriBuilder APP_URI_BUILDER = UriBuilder.fromUri(URL_APP).path(PATH_API);
private static final UriBuilder API_URI_BUILDER = getApiBaseBuilder().path(PATH_API);
private static final UriBuilder API_URI_BUILDER = getApiBaseBuilder(PATH_API);
private final Set<Scope> requiredScopes;
private final ApiBridgeHandler apiBridge;
@ -76,11 +75,11 @@ public abstract class RestManager {
throw new IllegalArgumentException("appendParams : params count must be even");
}
for (int i = 0; i < params.length; i += 2) {
Object query = params[i];
if (query instanceof String) {
Object param = params[i + 1];
if (param != null) {
builder.queryParam((String) query, param);
Object param1 = params[i];
Object param2 = params[i + 1];
if (param1 instanceof String query) {
if (param2 != null) { // or else just ignore this query element
builder.queryParam(query, param2);
}
} else {
throw new IllegalArgumentException("appendParams : even parameters must be Strings");
@ -89,18 +88,16 @@ public abstract class RestManager {
return builder;
}
protected static UriBuilder getApiBaseBuilder() {
return API_BASE_BUILDER.clone();
protected static UriBuilder getApiBaseBuilder(String... paths) {
UriBuilder builder = UriBuilder.fromUri(URL_API);
Stream.of(paths).forEach(path -> builder.path(path));
return builder;
}
public static UriBuilder getApiUriBuilder(String path, @Nullable Object... params) {
return appendParams(API_URI_BUILDER.clone().path(path), params);
}
protected static UriBuilder getAppUriBuilder(String path, @Nullable Object... params) {
return appendParams(APP_URI_BUILDER.clone().path(path), params);
}
private String toRequest(Map<String, String> entries) {
return entries.entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()).collect(Collectors.joining("&"));
}

View File

@ -122,13 +122,13 @@ public class SecurityApi extends RestManager {
}
public void changeFloodLightMode(String homeId, String cameraId, FloodLightMode mode) throws NetatmoException {
UriBuilder uriBuilder = getAppUriBuilder(PATH_STATE);
String payload = String.format(PAYLOAD_FLOODLIGHT, homeId, cameraId, mode.name().toLowerCase());
UriBuilder uriBuilder = getApiUriBuilder(PATH_STATE);
String payload = PAYLOAD_FLOODLIGHT.formatted(homeId, cameraId, mode.name().toLowerCase());
post(uriBuilder, ApiResponse.Ok.class, payload);
}
public void setPersonAwayStatus(String homeId, String personId, boolean away) throws NetatmoException {
UriBuilder uriBuilder = getAppUriBuilder(away ? SUB_PATH_PERSON_AWAY : SUB_PATH_PERSON_HOME);
UriBuilder uriBuilder = getApiUriBuilder(away ? SUB_PATH_PERSON_AWAY : SUB_PATH_PERSON_HOME);
String payload = String.format(away ? PAYLOAD_PERSON_AWAY : PAYLOAD_PERSON_HOME, homeId, personId);
post(uriBuilder, ApiResponse.Ok.class, payload);
}

View File

@ -120,7 +120,6 @@ public class NetatmoConstants {
// Netatmo API urls
public static final String URL_API = "https://api.netatmo.com/";
public static final String URL_APP = "https://app.netatmo.net/";
public static final String PATH_OAUTH = "oauth2";
public static final String SUB_PATH_TOKEN = "token";
public static final String SUB_PATH_AUTHORIZE = "authorize";

View File

@ -152,6 +152,7 @@
<item-type>String</item-type>
<label>Floodlight</label>
<description>State of the floodlight (On/Off/Auto)</description>
<category>Lightbulb</category>
<state pattern="%s">
<options>
<option value="ON">On</option>