Skip to content

Commit

Permalink
[netatmo] Floodlight switch repaired (openhab#12743)
Browse files Browse the repository at this point in the history
* [netatmo] Floodlight switch repaired

Signed-off-by: Sven Strohschein <sven.strohschein@gmail.com>
  • Loading branch information
Novanic authored and psmedley committed Feb 23, 2023
1 parent 4fbf8b2 commit 93ba9fa
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@ public void changeStatus(String localCameraURL, boolean setOn) throws NetatmoExc
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public enum MeasureClass {
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";
Expand All @@ -134,7 +135,6 @@ public enum MeasureClass {
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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ public void handleCommand(String channelName, Command command) {
}

private void changeFloodlightMode(FloodLightMode mode) {
securityCapability.ifPresent(cap -> cap.changeFloodlightMode(localUrl, mode));
securityCapability.ifPresent(cap -> cap.changeFloodlightMode(handler.getId(), mode));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,10 @@ public void changeStatus(@Nullable String localURL, boolean status) {
});
}

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());
Expand Down

0 comments on commit 93ba9fa

Please sign in to comment.