| 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 |
*/
@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;
* 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);
}
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
import javax.ws.rs.core.UriBuilder;
*/
@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;
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");
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("&"));
}
}
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);
}
// 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";
<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>