[netatmo] Floodlight switch repaired (#12743)

* [netatmo] Floodlight switch repaired

Signed-off-by: Sven Strohschein <sven.strohschein@gmail.com>
This commit is contained in:
Sven Strohschein 2022-05-16 09:28:44 +02:00 committed by GitHub
parent 049fd1766e
commit 6980102abf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 12 deletions

View File

@ -101,10 +101,12 @@ public class SecurityApi extends RestManager {
post(uriBuilder, ApiResponse.Ok.class, null, null);
}
public void changeFloodLightMode(String localCameraURL, FloodLightMode mode) throws NetatmoException {
UriBuilder uriBuilder = UriBuilder.fromUri(localCameraURL).path(PATH_COMMAND).path(SUB_PATH_FLOODLIGHTSET);
uriBuilder.queryParam("config", "%7B%22mode%22:%22" + mode.toString() + "%22%7D");
get(uriBuilder, ApiResponse.Ok.class);
public void changeFloodLightMode(String homeId, String cameraId, FloodLightMode mode) throws NetatmoException {
UriBuilder uriBuilder = getAppUriBuilder(PATH_STATE);
String payload = String.format(
"{\"home\": {\"id\":\"%s\",\"modules\": [ {\"id\":\"%s\",\"floodlight\":\"%s\"} ]}}", homeId, cameraId,
mode.name().toLowerCase());
post(uriBuilder, ApiResponse.Ok.class, payload, "application/json;charset=utf-8");
}
public void setPersonAwayStatus(String homeId, String personId, boolean away) throws NetatmoException {

View File

@ -119,6 +119,7 @@ public class NetatmoConstants {
public static final String PATH_OAUTH = "oauth2/token";
public static final String PATH_API = "api";
public static final String PATH_COMMAND = "command";
public static final String PATH_STATE = "setstate";
public static final String SUB_PATH_PERSON_AWAY = "setpersonsaway";
public static final String SUB_PATH_PERSON_HOME = "setpersonshome";
public static final String SUB_PATH_HOMES_DATA = "homesdata";
@ -134,7 +135,6 @@ public class NetatmoConstants {
public static final String SUB_PATH_GETEVENTS = "getevents";
public static final String SUB_PATH_PING = "ping";
public static final String SUB_PATH_CHANGESTATUS = "changestatus";
public static final String SUB_PATH_FLOODLIGHTSET = "floodlight_set_config";
public static final String PARAM_DEVICEID = "device_id";
public static final String PARAM_MODULEID = "module_id";
public static final String PARAM_HOMEID = "home_id";

View File

@ -62,6 +62,6 @@ public class PresenceCapability extends CameraCapability {
}
private void changeFloodlightMode(FloodLightMode mode) {
securityCapability.ifPresent(cap -> cap.changeFloodlightMode(localUrl, mode));
securityCapability.ifPresent(cap -> cap.changeFloodlightMode(handler.getId(), mode));
}
}

View File

@ -158,14 +158,10 @@ class SecurityCapability extends RestCapability<SecurityApi> {
});
}
public void changeFloodlightMode(@Nullable String localURL, FloodLightMode mode) {
if (localURL == null) {
logger.info("Changing floodlight mode can only be done on local camera.");
return;
}
public void changeFloodlightMode(String cameraId, FloodLightMode mode) {
getApi().ifPresent(api -> {
try {
api.changeFloodLightMode(localURL, mode);
api.changeFloodLightMode(handler.getId(), cameraId, mode);
handler.expireData();
} catch (NetatmoException e) {
logger.warn("Error changing Presence floodlight mode '{}' : {}", mode, e.getMessage());