Skip to content

Commit

Permalink
[netatmo] Switching siren channel of the Presence to Read-Only (openh…
Browse files Browse the repository at this point in the history
…ab#17397)

* Switching siren channel of the Presence to Read-Only

Signed-off-by: Gaël L'hopital <gael@lhopital.org>
Signed-off-by: Patrik Gfeller <patrik.gfeller@proton.me>
  • Loading branch information
clinique authored and pgfeller committed Sep 29, 2024
1 parent 0d2857d commit a565627
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 27 deletions.
2 changes: 1 addition & 1 deletion bundles/org.openhab.binding.netatmo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ Warnings:
| 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 | String | Read-write | Sets the floodlight to ON/OFF/AUTO |
| presence | siren | Switch | Read-write | Status of the siren, if silent or emitting an alarm |
| presence | siren | Switch | Read-only | Status of the siren, if silent or emitting an alarm |
| 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 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.FeatureArea;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.FloodLightMode;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.SirenStatus;
import org.openhab.binding.netatmo.internal.api.dto.Home;
import org.openhab.binding.netatmo.internal.api.dto.HomeEvent;
import org.openhab.binding.netatmo.internal.api.dto.HomeEvent.NAEventsDataResponse;
Expand Down Expand Up @@ -127,12 +126,6 @@ public void changeFloodLightMode(String homeId, String cameraId, FloodLightMode
post(uriBuilder, ApiResponse.Ok.class, payload);
}

public void changeSirenStatus(String homeId, String moduleId, SirenStatus status) throws NetatmoException {
UriBuilder uriBuilder = getApiUriBuilder(PATH_STATE);
String payload = PAYLOAD_SIREN_PRESENCE.formatted(homeId, moduleId, status.name().toLowerCase());
post(uriBuilder, ApiResponse.Ok.class, payload);
}

public void setPersonAwayStatus(String homeId, String personId, boolean away) throws NetatmoException {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ ChannelGroup.BATTERY, ChannelGroup.TIMESTAMP, new ChannelGroup(DoorTagChannelHel
Set.of(ChannelHelperCapability.class, ParentUpdateCapability.class), ChannelGroup.SIGNAL,
ChannelGroup.BATTERY, ChannelGroup.TIMESTAMP, new ChannelGroup(SirenChannelHelper.class, GROUP_SIREN)),

PRESENCE(FeatureArea.SECURITY, "NOC", 1, "camera", HOME,
PRESENCE(FeatureArea.SECURITY, "NOC", 2, "camera", HOME,
Set.of(PresenceCapability.class, ChannelHelperCapability.class, ParentUpdateCapability.class),
ChannelGroup.SIGNAL, ChannelGroup.EVENT,
new ChannelGroup(PresenceChannelHelper.class, GROUP_SECURITY_EVENT, GROUP_CAM_STATUS, GROUP_CAM_LIVE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.FloodLightMode;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.SirenStatus;
import org.openhab.binding.netatmo.internal.handler.CommonInterface;
import org.openhab.binding.netatmo.internal.handler.channelhelper.ChannelHelper;
import org.openhab.binding.netatmo.internal.providers.NetatmoDescriptionProvider;
Expand Down Expand Up @@ -53,13 +52,12 @@ public void handleCommand(String channelName, Command command) {
try {
changeFloodlightMode(FloodLightMode.valueOf(command.toString()));
} catch (IllegalArgumentException e) {
logger.info("Incorrect command '{}' received for channel '{}'", command, channelName);
logger.warn("Incorrect command '{}' received for channel '{}'", command, channelName);
}
return;
}
} else if (CHANNEL_SIREN.equals(channelName) && command instanceof OnOffType) {
getSecurityCapability().ifPresent(cap -> cap.changeSirenStatus(handler.getId(),
command == OnOffType.ON ? SirenStatus.SOUND : SirenStatus.NO_SOUND));
} else if (CHANNEL_SIREN.equals(channelName)) {
logger.info("Channel '{}' is read-only", channelName);
return;
}
super.handleCommand(channelName, command);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.openhab.binding.netatmo.internal.api.SecurityApi;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.FeatureArea;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.FloodLightMode;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.SirenStatus;
import org.openhab.binding.netatmo.internal.api.dto.HomeData;
import org.openhab.binding.netatmo.internal.api.dto.HomeDataModule;
import org.openhab.binding.netatmo.internal.api.dto.HomeDataPerson;
Expand Down Expand Up @@ -237,15 +236,4 @@ public void changeFloodlightMode(String cameraId, FloodLightMode mode) {
}
});
}

public void changeSirenStatus(String moduleId, SirenStatus status) {
getApi().ifPresent(api -> {
try {
api.changeSirenStatus(handler.getId(), moduleId, status);
handler.expireData();
} catch (NetatmoException e) {
logger.warn("Error changing siren status '{}' : {}", status, e.getMessage());
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
<channel-group-type id="presence">
<label>Presence Camera</label>
<channels>
<channel id="siren" typeId="siren-status-rw"/>
<channel id="siren" typeId="siren-status"/>
<channel id="floodlight" typeId="floodlight-mode"/>
</channels>
</channel-group-type>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
</update-channel>
</instruction-set>

<instruction-set targetVersion="2">
<update-channel id="siren" groupIds="presence">
<type>netatmo:siren-status</type>
</update-channel>
</instruction-set>

</thing-type>

</update:update-descriptions>

0 comments on commit a565627

Please sign in to comment.