[netatmo] Add Siren capability to Presence Outdoor Camera (#14485)

* Adding Siren capability to Presence Outdoor Camera
Resolves #14466

---------

Signed-off-by: clinique <gael@lhopital.org>
This commit is contained in:
Gaël L'hopital 2023-07-13 18:32:46 +02:00 committed by GitHub
parent 1fcc4fe70a
commit 1942dfeddc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 160 additions and 70 deletions

View File

@ -563,6 +563,7 @@ Warnings:
| signal | strength | Number | Read-only | Signal strength (0 for no signal, 1 for weak...) | | signal | strength | Number | Read-only | Signal strength (0 for no signal, 1 for weak...) |
| signal | value | Number:Power | Read-only | Signal strength in dBm | | signal | value | Number:Power | Read-only | Signal strength in dBm |
| presence | floodlight | String | Read-write | Sets the floodlight to ON/OFF/AUTO | | 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 |
| last-event | type | String | Read-only | Type of event | | last-event | type | String | Read-only | Type of event |
| last-event | subtype | String | Read-only | Sub-type of event | | last-event | subtype | String | Read-only | Sub-type of event |
| last-event | time | DateTime | Read-only | Time of occurrence of event | | last-event | time | DateTime | Read-only | Time of occurrence of event |
@ -614,7 +615,7 @@ Note: live feeds either locally or via VPN are not available in Netatmo API.
| Channel Group | Channel ID | Item Type | Read/Write | Description | | Channel Group | Channel ID | Item Type | Read/Write | Description |
| ------------- | ----------- | ------------ | ---------- | --------------------------------------------------- | | ------------- | ----------- | ------------ | ---------- | --------------------------------------------------- |
| siren | status | String | Read-only | Status of the siren, if silent or emitting an alarm | | siren | status | Switch | Read-only | Status of the siren, if silent or emitting an alarm |
| siren | monitoring | Switch | Read-only | State of the siren device | | siren | monitoring | Switch | Read-only | State of the siren device |
| signal | strength | Number | Read-only | Signal strength (0 for no signal, 1 for weak...) | | signal | strength | Number | Read-only | Signal strength (0 for no signal, 1 for weak...) |
| signal | value | Number:Power | Read-only | Signal strength in dBm | | signal | value | Number:Power | Read-only | Signal strength in dBm |

View File

@ -34,6 +34,7 @@ public class NetatmoBindingConstants {
public static final String PROPERTY_COUNTRY = "country"; public static final String PROPERTY_COUNTRY = "country";
public static final String PROPERTY_TIMEZONE = "timezone"; public static final String PROPERTY_TIMEZONE = "timezone";
public static final String PROPERTY_FEATURE = "feature"; public static final String PROPERTY_FEATURE = "feature";
public static final String PROPERTY_THING_TYPE_VERSION = "thingTypeVersion";
// Channel group ids // Channel group ids
public static final String GROUP_LAST_EVENT = "last-event"; public static final String GROUP_LAST_EVENT = "last-event";
@ -113,6 +114,7 @@ public class NetatmoBindingConstants {
public static final String CHANNEL_SUM_RAIN24 = "sum-24"; public static final String CHANNEL_SUM_RAIN24 = "sum-24";
public static final String CHANNEL_WIND_ANGLE = "angle"; public static final String CHANNEL_WIND_ANGLE = "angle";
public static final String CHANNEL_STATUS = GROUP_CAM_STATUS; public static final String CHANNEL_STATUS = GROUP_CAM_STATUS;
public static final String CHANNEL_SIREN = GROUP_SIREN;
public static final String CHANNEL_WIND_STRENGTH = "strength"; public static final String CHANNEL_WIND_STRENGTH = "strength";
public static final String CHANNEL_MAX_WIND_STRENGTH = "max-strength"; public static final String CHANNEL_MAX_WIND_STRENGTH = "max-strength";
public static final String CHANNEL_DATE_MAX_WIND_STRENGTH = "max-strength-date"; public static final String CHANNEL_DATE_MAX_WIND_STRENGTH = "max-strength-date";

View File

@ -16,7 +16,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.ServiceError; import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.ServiceError;
/** /**
* The {@link ApiError} models an errored response from API * The {@link ApiError} models an error response from API
* *
* @author Gaël L'hopital - Initial contribution * @author Gaël L'hopital - Initial contribution
*/ */

View File

@ -29,11 +29,11 @@ public class NetatmoException extends IOException {
private ServiceError statusCode = ServiceError.UNKNOWN; private ServiceError statusCode = ServiceError.UNKNOWN;
public NetatmoException(String format, Object... args) { public NetatmoException(String format, Object... args) {
super(String.format(format, args)); super(format.formatted(args));
} }
public NetatmoException(Exception e, String format, Object... args) { public NetatmoException(Exception e, String format, Object... args) {
super(String.format(format, args), e); super(format.formatted(args), e);
} }
public NetatmoException(String message) { public NetatmoException(String message) {
@ -54,6 +54,6 @@ public class NetatmoException extends IOException {
String message = super.getMessage(); String message = super.getMessage();
return message == null ? null return message == null ? null
: ServiceError.UNKNOWN.equals(statusCode) ? message : ServiceError.UNKNOWN.equals(statusCode) ? message
: String.format("Rest call failed: statusCode=%s, message=%s", statusCode, message); : "Rest call failed: statusCode=%s, message=%s".formatted(statusCode, message);
} }
} }

View File

@ -25,6 +25,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; 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.FeatureArea;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.FloodLightMode; 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.Home;
import org.openhab.binding.netatmo.internal.api.dto.HomeEvent; import org.openhab.binding.netatmo.internal.api.dto.HomeEvent;
import org.openhab.binding.netatmo.internal.api.dto.HomeEvent.NAEventsDataResponse; import org.openhab.binding.netatmo.internal.api.dto.HomeEvent.NAEventsDataResponse;
@ -126,6 +127,12 @@ public class SecurityApi extends RestManager {
post(uriBuilder, ApiResponse.Ok.class, payload); 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 { public void setPersonAwayStatus(String homeId, String personId, boolean away) throws NetatmoException {
UriBuilder uriBuilder = getApiUriBuilder(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); String payload = String.format(away ? PAYLOAD_PERSON_AWAY : PAYLOAD_PERSON_HOME, homeId, personId);

View File

@ -64,66 +64,67 @@ import org.openhab.core.thing.ThingTypeUID;
*/ */
@NonNullByDefault @NonNullByDefault
public enum ModuleType { public enum ModuleType {
UNKNOWN(FeatureArea.NONE, "", null, Set.of()), UNKNOWN(FeatureArea.NONE, "", 1, null, Set.of()),
ACCOUNT(FeatureArea.NONE, "", null, Set.of(), new ChannelGroup(ApiBridgeChannelHelper.class, GROUP_MONITORING)), ACCOUNT(FeatureArea.NONE, "", 1, null, Set.of(), new ChannelGroup(ApiBridgeChannelHelper.class, GROUP_MONITORING)),
HOME(FeatureArea.NONE, "NAHome", ACCOUNT, HOME(FeatureArea.NONE, "NAHome", 1, ACCOUNT,
Set.of(DeviceCapability.class, HomeCapability.class, ChannelHelperCapability.class), Set.of(DeviceCapability.class, HomeCapability.class, ChannelHelperCapability.class),
new ChannelGroup(SecurityChannelHelper.class, GROUP_SECURITY_EVENT, GROUP_SECURITY), new ChannelGroup(SecurityChannelHelper.class, GROUP_SECURITY_EVENT, GROUP_SECURITY),
new ChannelGroup(EnergyChannelHelper.class, GROUP_ENERGY)), new ChannelGroup(EnergyChannelHelper.class, GROUP_ENERGY)),
PERSON(FeatureArea.SECURITY, "NAPerson", HOME, Set.of(PersonCapability.class, ChannelHelperCapability.class), PERSON(FeatureArea.SECURITY, "NAPerson", 1, HOME, Set.of(PersonCapability.class, ChannelHelperCapability.class),
new ChannelGroup(PersonChannelHelper.class, GROUP_PERSON), new ChannelGroup(PersonChannelHelper.class, GROUP_PERSON),
new ChannelGroup(EventPersonChannelHelper.class, GROUP_PERSON_LAST_EVENT)), new ChannelGroup(EventPersonChannelHelper.class, GROUP_PERSON_LAST_EVENT)),
WELCOME(FeatureArea.SECURITY, "NACamera", HOME, Set.of(CameraCapability.class, ChannelHelperCapability.class), WELCOME(FeatureArea.SECURITY, "NACamera", 1, HOME, Set.of(CameraCapability.class, ChannelHelperCapability.class),
ChannelGroup.SIGNAL, ChannelGroup.EVENT, ChannelGroup.SIGNAL, ChannelGroup.EVENT,
new ChannelGroup(CameraChannelHelper.class, GROUP_SECURITY_EVENT, GROUP_CAM_STATUS, GROUP_CAM_LIVE)), new ChannelGroup(CameraChannelHelper.class, GROUP_SECURITY_EVENT, GROUP_CAM_STATUS, GROUP_CAM_LIVE)),
TAG(FeatureArea.SECURITY, "NACamDoorTag", WELCOME, Set.of(ChannelHelperCapability.class), ChannelGroup.SIGNAL, TAG(FeatureArea.SECURITY, "NACamDoorTag", 1, WELCOME, Set.of(ChannelHelperCapability.class), ChannelGroup.SIGNAL,
ChannelGroup.BATTERY, ChannelGroup.TIMESTAMP, new ChannelGroup(DoorTagChannelHelper.class, GROUP_TAG)), ChannelGroup.BATTERY, ChannelGroup.TIMESTAMP, new ChannelGroup(DoorTagChannelHelper.class, GROUP_TAG)),
SIREN(FeatureArea.SECURITY, "NIS", WELCOME, Set.of(ChannelHelperCapability.class), ChannelGroup.SIGNAL, SIREN(FeatureArea.SECURITY, "NIS", 1, WELCOME, Set.of(ChannelHelperCapability.class), ChannelGroup.SIGNAL,
ChannelGroup.BATTERY, ChannelGroup.TIMESTAMP, new ChannelGroup(SirenChannelHelper.class, GROUP_SIREN)), ChannelGroup.BATTERY, ChannelGroup.TIMESTAMP, new ChannelGroup(SirenChannelHelper.class, GROUP_SIREN)),
PRESENCE(FeatureArea.SECURITY, "NOC", HOME, Set.of(PresenceCapability.class, ChannelHelperCapability.class), PRESENCE(FeatureArea.SECURITY, "NOC", 1, HOME, Set.of(PresenceCapability.class, ChannelHelperCapability.class),
ChannelGroup.SIGNAL, ChannelGroup.EVENT, ChannelGroup.SIGNAL, ChannelGroup.EVENT,
new ChannelGroup(PresenceChannelHelper.class, GROUP_SECURITY_EVENT, GROUP_CAM_STATUS, GROUP_CAM_LIVE, new ChannelGroup(PresenceChannelHelper.class, GROUP_SECURITY_EVENT, GROUP_CAM_STATUS, GROUP_CAM_LIVE,
GROUP_PRESENCE), GROUP_PRESENCE),
new ChannelGroup(EventCameraChannelHelper.class, GROUP_SUB_EVENT)), new ChannelGroup(EventCameraChannelHelper.class, GROUP_SUB_EVENT)),
DOORBELL(FeatureArea.SECURITY, "NDB", HOME, Set.of(DoorbellCapability.class, ChannelHelperCapability.class), DOORBELL(FeatureArea.SECURITY, "NDB", 1, HOME, Set.of(DoorbellCapability.class, ChannelHelperCapability.class),
ChannelGroup.SIGNAL, ChannelGroup.SIGNAL,
new ChannelGroup(CameraChannelHelper.class, GROUP_SECURITY_EVENT, GROUP_DOORBELL_STATUS, new ChannelGroup(CameraChannelHelper.class, GROUP_SECURITY_EVENT, GROUP_DOORBELL_STATUS,
GROUP_DOORBELL_LIVE), GROUP_DOORBELL_LIVE),
new ChannelGroup(EventCameraChannelHelper.class, GROUP_DOORBELL_LAST_EVENT, GROUP_DOORBELL_SUB_EVENT)), new ChannelGroup(EventCameraChannelHelper.class, GROUP_DOORBELL_LAST_EVENT, GROUP_DOORBELL_SUB_EVENT)),
WEATHER_STATION(FeatureArea.WEATHER, "NAMain", ACCOUNT, WEATHER_STATION(FeatureArea.WEATHER, "NAMain", 1, ACCOUNT,
Set.of(DeviceCapability.class, WeatherCapability.class, MeasureCapability.class, Set.of(DeviceCapability.class, WeatherCapability.class, MeasureCapability.class,
ChannelHelperCapability.class), ChannelHelperCapability.class),
ChannelGroup.SIGNAL, ChannelGroup.HUMIDITY, ChannelGroup.TSTAMP_EXT, ChannelGroup.MEASURE, ChannelGroup.SIGNAL, ChannelGroup.HUMIDITY, ChannelGroup.TSTAMP_EXT, ChannelGroup.MEASURE,
ChannelGroup.AIR_QUALITY, ChannelGroup.LOCATION, ChannelGroup.NOISE, ChannelGroup.TEMP_INSIDE_EXT, ChannelGroup.AIR_QUALITY, ChannelGroup.LOCATION, ChannelGroup.NOISE, ChannelGroup.TEMP_INSIDE_EXT,
new ChannelGroup(PressureChannelHelper.class, MeasureClass.PRESSURE, GROUP_TYPE_PRESSURE_EXTENDED)), new ChannelGroup(PressureChannelHelper.class, MeasureClass.PRESSURE, GROUP_TYPE_PRESSURE_EXTENDED)),
OUTDOOR(FeatureArea.WEATHER, "NAModule1", WEATHER_STATION, OUTDOOR(FeatureArea.WEATHER, "NAModule1", 1, WEATHER_STATION,
Set.of(MeasureCapability.class, ChannelHelperCapability.class), ChannelGroup.SIGNAL, ChannelGroup.HUMIDITY, Set.of(MeasureCapability.class, ChannelHelperCapability.class), ChannelGroup.SIGNAL, ChannelGroup.HUMIDITY,
ChannelGroup.TSTAMP_EXT, ChannelGroup.MEASURE, ChannelGroup.BATTERY, ChannelGroup.TEMP_OUTSIDE_EXT), ChannelGroup.TSTAMP_EXT, ChannelGroup.MEASURE, ChannelGroup.BATTERY, ChannelGroup.TEMP_OUTSIDE_EXT),
WIND(FeatureArea.WEATHER, "NAModule2", WEATHER_STATION, Set.of(ChannelHelperCapability.class), ChannelGroup.SIGNAL, WIND(FeatureArea.WEATHER, "NAModule2", 1, WEATHER_STATION, Set.of(ChannelHelperCapability.class),
ChannelGroup.TSTAMP_EXT, ChannelGroup.BATTERY, new ChannelGroup(WindChannelHelper.class, GROUP_WIND)), ChannelGroup.SIGNAL, ChannelGroup.TSTAMP_EXT, ChannelGroup.BATTERY,
new ChannelGroup(WindChannelHelper.class, GROUP_WIND)),
RAIN(FeatureArea.WEATHER, "NAModule3", WEATHER_STATION, RAIN(FeatureArea.WEATHER, "NAModule3", 1, WEATHER_STATION,
Set.of(MeasureCapability.class, ChannelHelperCapability.class), ChannelGroup.SIGNAL, Set.of(MeasureCapability.class, ChannelHelperCapability.class), ChannelGroup.SIGNAL,
ChannelGroup.TSTAMP_EXT, ChannelGroup.MEASURE, ChannelGroup.BATTERY, ChannelGroup.TSTAMP_EXT, ChannelGroup.MEASURE, ChannelGroup.BATTERY,
new ChannelGroup(RainChannelHelper.class, MeasureClass.RAIN_QUANTITY, GROUP_RAIN)), new ChannelGroup(RainChannelHelper.class, MeasureClass.RAIN_QUANTITY, GROUP_RAIN)),
INDOOR(FeatureArea.WEATHER, "NAModule4", WEATHER_STATION, INDOOR(FeatureArea.WEATHER, "NAModule4", 1, WEATHER_STATION,
Set.of(MeasureCapability.class, ChannelHelperCapability.class), ChannelGroup.SIGNAL, Set.of(MeasureCapability.class, ChannelHelperCapability.class), ChannelGroup.SIGNAL,
ChannelGroup.TSTAMP_EXT, ChannelGroup.MEASURE, ChannelGroup.BATTERY, ChannelGroup.HUMIDITY, ChannelGroup.TSTAMP_EXT, ChannelGroup.MEASURE, ChannelGroup.BATTERY, ChannelGroup.HUMIDITY,
ChannelGroup.TEMP_INSIDE_EXT, ChannelGroup.AIR_QUALITY), ChannelGroup.TEMP_INSIDE_EXT, ChannelGroup.AIR_QUALITY),
HOME_COACH(FeatureArea.AIR_CARE, "NHC", ACCOUNT, HOME_COACH(FeatureArea.AIR_CARE, "NHC", 1, ACCOUNT,
Set.of(DeviceCapability.class, AirCareCapability.class, MeasureCapability.class, Set.of(DeviceCapability.class, AirCareCapability.class, MeasureCapability.class,
ChannelHelperCapability.class), ChannelHelperCapability.class),
ChannelGroup.LOCATION, ChannelGroup.SIGNAL, ChannelGroup.NOISE, ChannelGroup.HUMIDITY, ChannelGroup.LOCATION, ChannelGroup.SIGNAL, ChannelGroup.NOISE, ChannelGroup.HUMIDITY,
@ -131,22 +132,23 @@ public enum ModuleType {
new ChannelGroup(AirQualityChannelHelper.class, GROUP_TYPE_AIR_QUALITY_EXTENDED), new ChannelGroup(AirQualityChannelHelper.class, GROUP_TYPE_AIR_QUALITY_EXTENDED),
new ChannelGroup(PressureChannelHelper.class, MeasureClass.PRESSURE, GROUP_PRESSURE)), new ChannelGroup(PressureChannelHelper.class, MeasureClass.PRESSURE, GROUP_PRESSURE)),
PLUG(FeatureArea.ENERGY, "NAPlug", HOME, Set.of(ChannelHelperCapability.class), ChannelGroup.SIGNAL), PLUG(FeatureArea.ENERGY, "NAPlug", 1, HOME, Set.of(ChannelHelperCapability.class), ChannelGroup.SIGNAL),
VALVE(FeatureArea.ENERGY, "NRV", PLUG, Set.of(ChannelHelperCapability.class), ChannelGroup.SIGNAL, VALVE(FeatureArea.ENERGY, "NRV", 1, PLUG, Set.of(ChannelHelperCapability.class), ChannelGroup.SIGNAL,
ChannelGroup.BATTERY_EXT), ChannelGroup.BATTERY_EXT),
THERMOSTAT(FeatureArea.ENERGY, "NATherm1", PLUG, Set.of(ChannelHelperCapability.class), ChannelGroup.SIGNAL, THERMOSTAT(FeatureArea.ENERGY, "NATherm1", 1, PLUG, Set.of(ChannelHelperCapability.class), ChannelGroup.SIGNAL,
ChannelGroup.BATTERY_EXT, new ChannelGroup(Therm1ChannelHelper.class, GROUP_TYPE_TH_PROPERTIES)), ChannelGroup.BATTERY_EXT, new ChannelGroup(Therm1ChannelHelper.class, GROUP_TYPE_TH_PROPERTIES)),
ROOM(FeatureArea.ENERGY, "NARoom", HOME, Set.of(RoomCapability.class, ChannelHelperCapability.class), ROOM(FeatureArea.ENERGY, "NARoom", 1, HOME, Set.of(RoomCapability.class, ChannelHelperCapability.class),
new ChannelGroup(RoomChannelHelper.class, GROUP_TYPE_ROOM_PROPERTIES, GROUP_TYPE_ROOM_TEMPERATURE), new ChannelGroup(RoomChannelHelper.class, GROUP_TYPE_ROOM_PROPERTIES, GROUP_TYPE_ROOM_TEMPERATURE),
new ChannelGroup(SetpointChannelHelper.class, GROUP_SETPOINT)), new ChannelGroup(SetpointChannelHelper.class, GROUP_SETPOINT)),
SMOKE_DETECTOR(FeatureArea.SECURITY, "NSD", HOME, Set.of(AlarmEventCapability.class, ChannelHelperCapability.class), SMOKE_DETECTOR(FeatureArea.SECURITY, "NSD", 1, HOME,
ChannelGroup.SIGNAL, ChannelGroup.TIMESTAMP, ChannelGroup.ALARM_LAST_EVENT), Set.of(AlarmEventCapability.class, ChannelHelperCapability.class), ChannelGroup.SIGNAL,
ChannelGroup.TIMESTAMP, ChannelGroup.ALARM_LAST_EVENT),
CO_DETECTOR(FeatureArea.SECURITY, "NCO", HOME, Set.of(AlarmEventCapability.class, ChannelHelperCapability.class), CO_DETECTOR(FeatureArea.SECURITY, "NCO", 1, HOME, Set.of(AlarmEventCapability.class, ChannelHelperCapability.class),
ChannelGroup.SIGNAL, ChannelGroup.TIMESTAMP, ChannelGroup.ALARM_LAST_EVENT); ChannelGroup.SIGNAL, ChannelGroup.TIMESTAMP, ChannelGroup.ALARM_LAST_EVENT);
public static final EnumSet<ModuleType> AS_SET = EnumSet.allOf(ModuleType.class); public static final EnumSet<ModuleType> AS_SET = EnumSet.allOf(ModuleType.class);
@ -157,8 +159,9 @@ public enum ModuleType {
public final ThingTypeUID thingTypeUID; public final ThingTypeUID thingTypeUID;
public final FeatureArea feature; public final FeatureArea feature;
public final String apiName; public final String apiName;
public final int thingTypeVersion;
ModuleType(FeatureArea feature, String apiName, @Nullable ModuleType bridge, ModuleType(FeatureArea feature, String apiName, int thingTypeVersion, @Nullable ModuleType bridge,
Set<Class<? extends Capability>> capabilities, ChannelGroup... channelGroups) { Set<Class<? extends Capability>> capabilities, ChannelGroup... channelGroups) {
this.bridgeType = Optional.ofNullable(bridge); this.bridgeType = Optional.ofNullable(bridge);
this.feature = feature; this.feature = feature;
@ -166,6 +169,7 @@ public enum ModuleType {
this.apiName = apiName; this.apiName = apiName;
this.channelGroups = Set.of(channelGroups); this.channelGroups = Set.of(channelGroups);
this.thingTypeUID = new ThingTypeUID(BINDING_ID, name().toLowerCase().replace("_", "-")); this.thingTypeUID = new ThingTypeUID(BINDING_ID, name().toLowerCase().replace("_", "-"));
this.thingTypeVersion = thingTypeVersion;
} }
public boolean isLogical() { public boolean isLogical() {

View File

@ -158,6 +158,7 @@ public class NetatmoConstants {
// Payloads // Payloads
public static final String PAYLOAD_FLOODLIGHT = "{\"home\": {\"id\":\"%s\",\"modules\": [ {\"id\":\"%s\",\"floodlight\":\"%s\"} ]}}"; public static final String PAYLOAD_FLOODLIGHT = "{\"home\": {\"id\":\"%s\",\"modules\": [ {\"id\":\"%s\",\"floodlight\":\"%s\"} ]}}";
public static final String PAYLOAD_SIREN_PRESENCE = "{\"home\": {\"id\":\"%s\",\"modules\": [ {\"id\":\"%s\",\"siren_status\":\"%s\"} ]}}";
public static final String PAYLOAD_PERSON_AWAY = "{\"home_id\":\"%s\",\"person_id\":\"%s\"}"; public static final String PAYLOAD_PERSON_AWAY = "{\"home_id\":\"%s\",\"person_id\":\"%s\"}";
public static final String PAYLOAD_PERSON_HOME = "{\"home_id\":\"%s\",\"person_ids\":[\"%s\"]}"; public static final String PAYLOAD_PERSON_HOME = "{\"home_id\":\"%s\",\"person_ids\":[\"%s\"]}";
@ -348,6 +349,20 @@ public class NetatmoConstants {
UNKNOWN; UNKNOWN;
} }
public enum SirenStatus {
SOUND,
NO_SOUND,
UNKNOWN;
public static SirenStatus get(String value) {
try {
return valueOf(value.toUpperCase());
} catch (IllegalArgumentException e) {
return UNKNOWN;
}
}
}
public enum BatteryState { public enum BatteryState {
@SerializedName("full") @SerializedName("full")
FULL(100), FULL(100),

View File

@ -21,6 +21,7 @@ import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.Alimentati
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.BatteryState; import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.BatteryState;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.FloodLightMode; import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.FloodLightMode;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.SdCardStatus; import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.SdCardStatus;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.SirenStatus;
import org.openhab.core.library.types.OnOffType; import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.OpenClosedType; import org.openhab.core.library.types.OpenClosedType;
import org.openhab.core.types.State; import org.openhab.core.types.State;
@ -42,7 +43,7 @@ public class HomeStatusModule extends NAThing {
private FloodLightMode floodlight = FloodLightMode.UNKNOWN; private FloodLightMode floodlight = FloodLightMode.UNKNOWN;
private SdCardStatus sdStatus = SdCardStatus.UNKNOWN; private SdCardStatus sdStatus = SdCardStatus.UNKNOWN;
private AlimentationStatus alimStatus = AlimentationStatus.UNKNOWN; private AlimentationStatus alimStatus = AlimentationStatus.UNKNOWN;
private @Nullable String sirenStatus; private SirenStatus sirenStatus = SirenStatus.UNKNOWN;
private @Nullable String vpnUrl; private @Nullable String vpnUrl;
private boolean isLocal; private boolean isLocal;
private BatteryState batteryState = BatteryState.UNKNOWN; private BatteryState batteryState = BatteryState.UNKNOWN;
@ -90,8 +91,8 @@ public class HomeStatusModule extends NAThing {
return alimStatus; return alimStatus;
} }
public Optional<String> getSirenStatus() { public SirenStatus getSirenStatus() {
return Optional.ofNullable(sirenStatus); return sirenStatus;
} }
public @Nullable String getVpnUrl() { public @Nullable String getVpnUrl() {

View File

@ -317,6 +317,7 @@ public class ApiBridgeHandler extends BaseBridgeHandler {
InputStream stream = new ByteArrayInputStream(payload.getBytes(StandardCharsets.UTF_8)); InputStream stream = new ByteArrayInputStream(payload.getBytes(StandardCharsets.UTF_8));
try (InputStreamContentProvider inputStreamContentProvider = new InputStreamContentProvider(stream)) { try (InputStreamContentProvider inputStreamContentProvider = new InputStreamContentProvider(stream)) {
request.content(inputStreamContentProvider, contentType); request.content(inputStreamContentProvider, contentType);
request.header(HttpHeader.ACCEPT, "application/json");
} }
logger.trace(" -with payload : {} ", payload); logger.trace(" -with payload : {} ", payload);
} }
@ -404,10 +405,9 @@ public class ApiBridgeHandler extends BaseBridgeHandler {
home.getRooms().values().stream().forEach(room -> { home.getRooms().values().stream().forEach(room -> {
room.getModuleIds().stream().map(id -> home.getModules().get(id)) room.getModuleIds().stream().map(id -> home.getModules().get(id))
.map(m -> m != null ? m.getType().feature : FeatureArea.NONE) .map(m -> m != null ? m.getType().feature : FeatureArea.NONE)
.filter(f -> FeatureArea.ENERGY.equals(f)).findAny().ifPresent(f -> { .filter(f -> FeatureArea.ENERGY.equals(f)).findAny()
action.apply(room, homeUID) .ifPresent(f -> action.apply(room, homeUID)
.ifPresent(roomUID -> bridgesUids.put(room.getId(), roomUID)); .ifPresent(roomUID -> bridgesUids.put(room.getId(), roomUID)));
});
}); });
// Creating modules that have no bridge first, avoiding weather station itself // Creating modules that have no bridge first, avoiding weather station itself

View File

@ -180,7 +180,7 @@ public interface CommonInterface {
String channelName = channelUID.getIdWithoutGroup(); String channelName = channelUID.getIdWithoutGroup();
getCapabilities().values().forEach(cap -> cap.handleCommand(channelName, command)); getCapabilities().values().forEach(cap -> cap.handleCommand(channelName, command));
} else { } else {
getLogger().debug("Command {}, on channel {} dropped - thing is not ONLINE", command, channelUID); getLogger().debug("Command {} on channel {} dropped - thing is not ONLINE", command, channelUID);
} }
} }

View File

@ -12,7 +12,7 @@
*/ */
package org.openhab.binding.netatmo.internal.handler.capability; package org.openhab.binding.netatmo.internal.handler.capability;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.VENDOR; import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.core.thing.Thing.*; import static org.openhab.core.thing.Thing.*;
import java.util.Collection; import java.util.Collection;
@ -97,11 +97,14 @@ public class Capability {
protected void beforeNewData() { protected void beforeNewData() {
properties = new HashMap<>(thing.getProperties()); properties = new HashMap<>(thing.getProperties());
firstLaunch = properties.isEmpty(); firstLaunch = properties.isEmpty();
if (firstLaunch && !moduleType.isLogical()) { if (firstLaunch) {
properties.put(PROPERTY_THING_TYPE_VERSION, Integer.toString(moduleType.thingTypeVersion));
if (!moduleType.isLogical()) {
String name = moduleType.apiName.isBlank() ? moduleType.name() : moduleType.apiName; String name = moduleType.apiName.isBlank() ? moduleType.name() : moduleType.apiName;
properties.put(PROPERTY_MODEL_ID, name); properties.put(PROPERTY_MODEL_ID, name);
properties.put(PROPERTY_VENDOR, VENDOR); properties.put(PROPERTY_VENDOR, VENDOR);
} }
}
statusReason = null; statusReason = null;
} }

View File

@ -12,12 +12,14 @@
*/ */
package org.openhab.binding.netatmo.internal.handler.capability; package org.openhab.binding.netatmo.internal.handler.capability;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.CHANNEL_FLOODLIGHT; import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import java.util.List; import java.util.List;
import org.eclipse.jdt.annotation.NonNullByDefault; 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.FloodLightMode;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.SirenStatus;
import org.openhab.binding.netatmo.internal.api.dto.HomeStatusModule;
import org.openhab.binding.netatmo.internal.handler.CommonInterface; import org.openhab.binding.netatmo.internal.handler.CommonInterface;
import org.openhab.binding.netatmo.internal.handler.channelhelper.ChannelHelper; import org.openhab.binding.netatmo.internal.handler.channelhelper.ChannelHelper;
import org.openhab.binding.netatmo.internal.providers.NetatmoDescriptionProvider; import org.openhab.binding.netatmo.internal.providers.NetatmoDescriptionProvider;
@ -42,6 +44,12 @@ public class PresenceCapability extends CameraCapability {
super(handler, descriptionProvider, channelHelpers); super(handler, descriptionProvider, channelHelpers);
} }
@Override
public void updateHomeStatusModule(HomeStatusModule newData) {
super.updateHomeStatusModule(newData);
getSecurityCapability().ifPresent(cap -> cap.changeSirenStatus(handler.getId(), SirenStatus.SOUND));
}
@Override @Override
public void handleCommand(String channelName, Command command) { public void handleCommand(String channelName, Command command) {
if (CHANNEL_FLOODLIGHT.equals(channelName)) { if (CHANNEL_FLOODLIGHT.equals(channelName)) {
@ -50,13 +58,16 @@ public class PresenceCapability extends CameraCapability {
return; return;
} else if (command instanceof StringType) { } else if (command instanceof StringType) {
try { try {
FloodLightMode mode = FloodLightMode.valueOf(command.toString()); changeFloodlightMode(FloodLightMode.valueOf(command.toString()));
changeFloodlightMode(mode);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
logger.info("Incorrect command '{}' received for channel '{}'", command, channelName); logger.info("Incorrect command '{}' received for channel '{}'", command, channelName);
} }
return; 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));
return;
} }
super.handleCommand(channelName, command); super.handleCommand(channelName, command);
} }

View File

@ -25,6 +25,7 @@ import org.openhab.binding.netatmo.internal.api.NetatmoException;
import org.openhab.binding.netatmo.internal.api.SecurityApi; 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.FeatureArea;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.FloodLightMode; 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.HomeData;
import org.openhab.binding.netatmo.internal.api.dto.HomeDataModule; import org.openhab.binding.netatmo.internal.api.dto.HomeDataModule;
import org.openhab.binding.netatmo.internal.api.dto.HomeDataPerson; import org.openhab.binding.netatmo.internal.api.dto.HomeDataPerson;
@ -238,4 +239,15 @@ class SecurityCapability extends RestCapability<SecurityApi> {
} }
}); });
} }
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());
}
});
}
} }

View File

@ -12,7 +12,7 @@
*/ */
package org.openhab.binding.netatmo.internal.handler.channelhelper; package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.CHANNEL_FLOODLIGHT; import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.toStringType; import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.toStringType;
import java.util.Set; import java.util.Set;
@ -22,7 +22,9 @@ import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.dto.HomeStatusModule; import org.openhab.binding.netatmo.internal.api.dto.HomeStatusModule;
import org.openhab.binding.netatmo.internal.api.dto.NAThing; import org.openhab.binding.netatmo.internal.api.dto.NAThing;
import org.openhab.core.config.core.Configuration; import org.openhab.core.config.core.Configuration;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.types.State; import org.openhab.core.types.State;
import org.openhab.core.types.UnDefType;
/** /**
* The {@link PresenceChannelHelper} handles specific channels of Presence external cameras * The {@link PresenceChannelHelper} handles specific channels of Presence external cameras
@ -39,11 +41,19 @@ public class PresenceChannelHelper extends CameraChannelHelper {
@Override @Override
protected @Nullable State internalGetProperty(String channelId, NAThing naThing, Configuration config) { protected @Nullable State internalGetProperty(String channelId, NAThing naThing, Configuration config) {
if (naThing instanceof HomeStatusModule) { if (naThing instanceof HomeStatusModule presence) {
HomeStatusModule camera = (HomeStatusModule) naThing;
switch (channelId) { switch (channelId) {
case CHANNEL_FLOODLIGHT: case CHANNEL_FLOODLIGHT:
return toStringType(camera.getFloodlight()); return toStringType(presence.getFloodlight());
case CHANNEL_SIREN:
switch (presence.getSirenStatus()) {
case NO_SOUND:
return OnOffType.OFF;
case SOUND:
return OnOffType.ON;
case UNKNOWN:
return UnDefType.NULL;
}
} }
} }
return super.internalGetProperty(channelId, naThing, config); return super.internalGetProperty(channelId, naThing, config);

View File

@ -13,15 +13,16 @@
package org.openhab.binding.netatmo.internal.handler.channelhelper; package org.openhab.binding.netatmo.internal.handler.channelhelper;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*; import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.toStringType;
import java.util.Set; import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.SirenStatus;
import org.openhab.binding.netatmo.internal.api.dto.HomeStatusModule; import org.openhab.binding.netatmo.internal.api.dto.HomeStatusModule;
import org.openhab.binding.netatmo.internal.api.dto.NAThing; import org.openhab.binding.netatmo.internal.api.dto.NAThing;
import org.openhab.core.config.core.Configuration; import org.openhab.core.config.core.Configuration;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.types.State; import org.openhab.core.types.State;
import org.openhab.core.types.UnDefType; import org.openhab.core.types.UnDefType;
@ -32,7 +33,7 @@ import org.openhab.core.types.UnDefType;
* *
*/ */
@NonNullByDefault @NonNullByDefault
public class SirenChannelHelper extends ChannelHelper { public class SirenChannelHelper extends EventChannelHelper {
public SirenChannelHelper(Set<String> providedGroups) { public SirenChannelHelper(Set<String> providedGroups) {
super(providedGroups); super(providedGroups);
@ -40,14 +41,14 @@ public class SirenChannelHelper extends ChannelHelper {
@Override @Override
protected @Nullable State internalGetProperty(String channelId, NAThing naThing, Configuration config) { protected @Nullable State internalGetProperty(String channelId, NAThing naThing, Configuration config) {
if (naThing instanceof HomeStatusModule) { if (naThing instanceof HomeStatusModule homeStatus) {
HomeStatusModule homeStatus = (HomeStatusModule) naThing; return switch (channelId) {
switch (channelId) { case CHANNEL_MONITORING -> homeStatus.getMonitoring();
case CHANNEL_MONITORING: case CHANNEL_STATUS -> homeStatus.getStatus().map(SirenStatus::get)
return homeStatus.getMonitoring(); .map(status -> SirenStatus.SOUND == status ? OnOffType.ON : OnOffType.OFF)
case CHANNEL_STATUS: .map(State.class::cast).orElse(UnDefType.UNDEF);
return homeStatus.getStatus().map(status -> toStringType(status)).orElse(UnDefType.UNDEF); default -> null;
} };
} }
return null; return null;
} }

View File

@ -311,10 +311,10 @@ channel-type.netatmo.setpoint.label = Setpoint
channel-type.netatmo.setpoint.description = Thermostat temperature setpoint. channel-type.netatmo.setpoint.description = Thermostat temperature setpoint.
channel-type.netatmo.siren-monitoring.label = Monitoring channel-type.netatmo.siren-monitoring.label = Monitoring
channel-type.netatmo.siren-monitoring.description = Monitoring state of the equipment channel-type.netatmo.siren-monitoring.description = Monitoring state of the equipment
channel-type.netatmo.siren-status.label = Status channel-type.netatmo.siren-status-rw.label = Siren
channel-type.netatmo.siren-status-rw.description = Status of the siren
channel-type.netatmo.siren-status.label = Siren
channel-type.netatmo.siren-status.description = Status of the siren channel-type.netatmo.siren-status.description = Status of the siren
channel-type.netatmo.siren-status.state.option.no_sound = Silent
channel-type.netatmo.siren-status.state.option.sound = Alarm
channel-type.netatmo.tag-status.label = Door Status channel-type.netatmo.tag-status.label = Door Status
channel-type.netatmo.th-mode.label = Thermostat Mode channel-type.netatmo.th-mode.label = Thermostat Mode
channel-type.netatmo.th-mode.description = Chosen thermostat mode (home, frost guard, manual, max). channel-type.netatmo.th-mode.description = Chosen thermostat mode (home, frost guard, manual, max).

View File

@ -18,15 +18,18 @@
</channel-type> </channel-type>
<channel-type id="siren-status"> <channel-type id="siren-status">
<item-type>String</item-type> <item-type>Switch</item-type>
<label>Status</label> <label>Siren</label>
<description>Status of the siren</description> <description>Status of the siren</description>
<state pattern="%s" readOnly="true"> <category>Soundvolume</category>
<options> <state readOnly="true"/>
<option value="no_sound">Silent</option> </channel-type>
<option value="sound">Alarm</option>
</options> <channel-type id="siren-status-rw">
</state> <item-type>Switch</item-type>
<label>Siren</label>
<description>Status of the siren</description>
<category>Soundvolume</category>
</channel-type> </channel-type>
<channel-type id="window-open"> <channel-type id="window-open">

View File

@ -225,6 +225,7 @@
<channel-group-type id="presence"> <channel-group-type id="presence">
<label>Presence Camera</label> <label>Presence Camera</label>
<channels> <channels>
<channel id="siren" typeId="siren-status-rw"/>
<channel id="floodlight" typeId="floodlight-mode"/> <channel id="floodlight" typeId="floodlight-mode"/>
</channels> </channels>
</channel-group-type> </channel-group-type>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<update:update-descriptions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:update="https://openhab.org/schemas/update-description/v1.0.0"
xsi:schemaLocation="https://openhab.org/schemas/update-description/v1.0.0 https://openhab.org/schemas/update-description-1.0.0.xsd">
<thing-type uid="netatmo:presence">
<instruction-set targetVersion="1">
<add-channel id="siren" groupIds="presence">
<type>netatmo:siren-status-rw</type>
</add-channel>
<update-channel id="status" groupIds="siren">
<type>netatmo:siren-status</type>
</update-channel>
</instruction-set>
</thing-type>
</update:update-descriptions>