[netatmo] Handle new event types (#15533)
* Adding new Netatmo events * Changed NAPushType to record. * Adding impact on WebhookEvent --------- Signed-off-by: clinique <gael@lhopital.org>
This commit is contained in:
parent
c21f9d5163
commit
c5739eccc9
|
@ -24,53 +24,57 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public enum EventSubType {
|
public enum EventSubType {
|
||||||
// SD Card sub events
|
// SD Card sub events
|
||||||
SD_CARD_MISSING(1, EventType.SD),
|
SD_CARD_MISSING("1", EventType.SD),
|
||||||
SD_CARD_INSERTED(2, EventType.SD),
|
SD_CARD_INSERTED("2", EventType.SD),
|
||||||
SD_CARD_FORMATTED(3, EventType.SD),
|
SD_CARD_FORMATTED("3", EventType.SD),
|
||||||
SD_CARD_WORKING(4, EventType.SD),
|
SD_CARD_WORKING("4", EventType.SD),
|
||||||
SD_CARD_DEFECTIVE(5, EventType.SD),
|
SD_CARD_DEFECTIVE("5", EventType.SD),
|
||||||
SD_CARD_INCOMPATIBLE_SPEED(6, EventType.SD),
|
SD_CARD_INCOMPATIBLE_SPEED("6", EventType.SD),
|
||||||
SD_CARD_INSUFFICIENT_SPACE(7, EventType.SD),
|
SD_CARD_INSUFFICIENT_SPACE("7", EventType.SD),
|
||||||
|
|
||||||
// Power sub events
|
// Power sub events
|
||||||
ALIM_INCORRECT_POWER(1, EventType.ALIM),
|
ALIM_INCORRECT_POWER("1", EventType.ALIM),
|
||||||
ALIM_CORRECT_POWER(2, EventType.ALIM),
|
ALIM_CORRECT_POWER("2", EventType.ALIM),
|
||||||
|
|
||||||
// Smoke detector sub events
|
// Smoke detector sub events
|
||||||
DETECTION_CHAMBER_CLEAN(0, EventType.DETECTION_CHAMBER_STATUS),
|
DETECTION_CHAMBER_CLEAN("0", EventType.DETECTION_CHAMBER_STATUS),
|
||||||
DETECTION_CHAMBER_DIRTY(1, EventType.DETECTION_CHAMBER_STATUS),
|
DETECTION_CHAMBER_DIRTY("1", EventType.DETECTION_CHAMBER_STATUS),
|
||||||
BATTERY_LOW(0, EventType.BATTERY_STATUS),
|
BATTERY_LOW("0", EventType.BATTERY_STATUS),
|
||||||
BATTERY_VERY_LOW(1, EventType.BATTERY_STATUS),
|
BATTERY_VERY_LOW("1", EventType.BATTERY_STATUS),
|
||||||
SMOKE_CLEARED(0, EventType.SMOKE),
|
SMOKE_CLEARED("0", EventType.SMOKE),
|
||||||
SMOKE_DETECTED(1, EventType.SMOKE),
|
SMOKE_DETECTED("1", EventType.SMOKE),
|
||||||
HUSH_ACTIVATED(0, EventType.HUSH),
|
HUSH_ACTIVATED("0", EventType.HUSH),
|
||||||
HUSH_DEACTIVATED(1, EventType.HUSH),
|
HUSH_DEACTIVATED("1", EventType.HUSH),
|
||||||
SOUND_TEST_OK(0, EventType.SOUND_TEST),
|
SOUND_TEST_OK("0", EventType.SOUND_TEST),
|
||||||
SOUND_TEST_ERROR(1, EventType.SOUND_TEST),
|
SOUND_TEST_ERROR("1", EventType.SOUND_TEST),
|
||||||
DETECTOR_READY(0, EventType.TAMPERED),
|
DETECTOR_READY("0", EventType.TAMPERED),
|
||||||
DETECTOR_TAMPERED(1, EventType.TAMPERED),
|
DETECTOR_TAMPERED("1", EventType.TAMPERED),
|
||||||
|
|
||||||
// Carbon Monoxide Alarm
|
// Carbon Monoxide Alarm
|
||||||
CO_OK(0, EventType.CO_DETECTED),
|
CO_OK("0", EventType.CO_DETECTED),
|
||||||
CO_PRE_ALARM(1, EventType.CO_DETECTED),
|
CO_PRE_ALARM("1", EventType.CO_DETECTED),
|
||||||
CO_ALARM(2, EventType.CO_DETECTED),
|
CO_ALARM("2", EventType.CO_DETECTED),
|
||||||
|
|
||||||
WIFI_STATUS_OK(1, EventType.WIFI_STATUS),
|
WIFI_STATUS_OK("1", EventType.WIFI_STATUS),
|
||||||
WIFI_STATUS_ERROR(0, EventType.WIFI_STATUS),
|
WIFI_STATUS_ERROR("0", EventType.WIFI_STATUS),
|
||||||
|
|
||||||
// Artificially implemented by the binding subtypes
|
// Artificially implemented by the binding subtypes
|
||||||
PERSON_ARRIVAL(1, EventType.PERSON, EventType.PERSON_HOME),
|
PERSON_ARRIVAL("1", EventType.PERSON, EventType.PERSON_HOME),
|
||||||
PERSON_SEEN(2, EventType.PERSON),
|
PERSON_SEEN("2", EventType.PERSON),
|
||||||
PERSON_DEPARTURE(1, EventType.PERSON_AWAY),
|
PERSON_DEPARTURE("1", EventType.PERSON_AWAY),
|
||||||
MOVEMENT_HUMAN(1, EventType.MOVEMENT, EventType.HUMAN),
|
MOVEMENT_HUMAN("1", EventType.MOVEMENT, EventType.HUMAN),
|
||||||
MOVEMENT_VEHICLE(2, EventType.MOVEMENT),
|
MOVEMENT_VEHICLE("2", EventType.MOVEMENT),
|
||||||
MOVEMENT_ANIMAL(3, EventType.MOVEMENT, EventType.ANIMAL);
|
MOVEMENT_ANIMAL("3", EventType.MOVEMENT, EventType.ANIMAL),
|
||||||
|
|
||||||
|
// Weather station events
|
||||||
|
RAIN_ALARM("rain", EventType.ALARM_EVENT),
|
||||||
|
CO2_ALARM("co2", EventType.ALARM_EVENT);
|
||||||
|
|
||||||
public final List<EventType> types;
|
public final List<EventType> types;
|
||||||
public final int subType;
|
public final String subType;
|
||||||
|
|
||||||
EventSubType(int i, EventType... types) {
|
EventSubType(String subType, EventType... types) {
|
||||||
this.types = List.of(types);
|
this.types = List.of(types);
|
||||||
this.subType = i;
|
this.subType = subType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,7 +143,25 @@ public enum EventType {
|
||||||
NEW_DEVICE(ModuleType.HOME),
|
NEW_DEVICE(ModuleType.HOME),
|
||||||
|
|
||||||
@SerializedName("co_detected")
|
@SerializedName("co_detected")
|
||||||
CO_DETECTED(ModuleType.CO_DETECTOR);
|
CO_DETECTED(ModuleType.CO_DETECTOR),
|
||||||
|
|
||||||
|
@SerializedName("alarm_event") // an alarm event arrived on a weather station module
|
||||||
|
ALARM_EVENT(ModuleType.WEATHER_STATION),
|
||||||
|
|
||||||
|
@SerializedName("entered") // the alarm was raised
|
||||||
|
ALARM_ENTERED(ModuleType.WEATHER_STATION),
|
||||||
|
|
||||||
|
@SerializedName("exited") // the alarm is stopped
|
||||||
|
ALARM_EXITED(ModuleType.WEATHER_STATION),
|
||||||
|
|
||||||
|
@SerializedName("display_change") // a manual action has been done on the thermostat
|
||||||
|
DISPLAY_CHANGE(ModuleType.THERMOSTAT),
|
||||||
|
|
||||||
|
@SerializedName("set_point") // a setpoint has been set
|
||||||
|
SET_POINT(ModuleType.THERMOSTAT),
|
||||||
|
|
||||||
|
@SerializedName("cancel_set_point") // manual setpoint ended
|
||||||
|
CANCEL_SET_POINT(ModuleType.THERMOSTAT);
|
||||||
|
|
||||||
public static final EnumSet<EventType> AS_SET = EnumSet.allOf(EventType.class);
|
public static final EnumSet<EventType> AS_SET = EnumSet.allOf(EventType.class);
|
||||||
|
|
||||||
|
@ -161,4 +179,8 @@ public enum EventType {
|
||||||
public boolean validFor(ModuleType searched) {
|
public boolean validFor(ModuleType searched) {
|
||||||
return appliesTo.contains(searched);
|
return appliesTo.contains(searched);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ModuleType getFirstModule() {
|
||||||
|
return appliesTo.iterator().next();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ public abstract class Event extends NAObject {
|
||||||
protected EventType type = EventType.UNKNOWN;
|
protected EventType type = EventType.UNKNOWN;
|
||||||
@SerializedName(value = "camera_id", alternate = { "module_id" })
|
@SerializedName(value = "camera_id", alternate = { "module_id" })
|
||||||
private String cameraId = "";
|
private String cameraId = "";
|
||||||
protected int subType = -1;
|
protected String subType = "";
|
||||||
|
|
||||||
public abstract ZonedDateTime getTime();
|
public abstract ZonedDateTime getTime();
|
||||||
|
|
||||||
|
@ -54,11 +54,11 @@ public abstract class Event extends NAObject {
|
||||||
@Override
|
@Override
|
||||||
public @Nullable String getName() {
|
public @Nullable String getName() {
|
||||||
String localMessage = super.getName();
|
String localMessage = super.getName();
|
||||||
return (localMessage != null ? localMessage.replace("<b>", "").replace("</b>", "") : "");
|
return localMessage != null ? localMessage.replace("<b>", "").replace("</b>", "") : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<EventSubType> getSubTypeDescription() {
|
public Optional<EventSubType> getSubTypeDescription() {
|
||||||
return Stream.of(EventSubType.values()).filter(v -> v.types.contains(getEventType()) && v.subType == subType)
|
return Stream.of(EventSubType.values())
|
||||||
.findFirst();
|
.filter(v -> v.types.contains(getEventType()) && v.subType.equals(subType)).findFirst();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.openhab.binding.netatmo.internal.deserialization.NAPushType;
|
||||||
public class WebhookEvent extends Event {
|
public class WebhookEvent extends Event {
|
||||||
private NAPushType pushType = NAPushType.UNKNOWN;
|
private NAPushType pushType = NAPushType.UNKNOWN;
|
||||||
private String homeId = "";
|
private String homeId = "";
|
||||||
|
private String roomId = "";
|
||||||
private String deviceId = "";
|
private String deviceId = "";
|
||||||
private @Nullable String snapshotUrl;
|
private @Nullable String snapshotUrl;
|
||||||
private @Nullable String vignetteUrl;
|
private @Nullable String vignetteUrl;
|
||||||
|
@ -50,7 +51,7 @@ public class WebhookEvent extends Event {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EventType getEventType() {
|
public EventType getEventType() {
|
||||||
return pushType.getEvent();
|
return pushType.event();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -77,6 +78,7 @@ public class WebhookEvent extends Event {
|
||||||
result.add(getCameraId());
|
result.add(getCameraId());
|
||||||
addNotBlank(result, homeId);
|
addNotBlank(result, homeId);
|
||||||
addNotBlank(result, deviceId);
|
addNotBlank(result, deviceId);
|
||||||
|
addNotBlank(result, roomId);
|
||||||
addNotBlank(result, getCameraId());
|
addNotBlank(result, getCameraId());
|
||||||
result.addAll(getPersons().keySet());
|
result.addAll(getPersons().keySet());
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -22,22 +22,6 @@ import org.openhab.binding.netatmo.internal.api.data.ModuleType;
|
||||||
* @author Gaël L'hopital - Initial contribution
|
* @author Gaël L'hopital - Initial contribution
|
||||||
*/
|
*/
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class NAPushType {
|
public record NAPushType(ModuleType moduleType, EventType event) {
|
||||||
public static final NAPushType UNKNOWN = new NAPushType(ModuleType.UNKNOWN, EventType.UNKNOWN);
|
public static final NAPushType UNKNOWN = new NAPushType(ModuleType.UNKNOWN, EventType.UNKNOWN);
|
||||||
|
|
||||||
private final ModuleType moduleType;
|
|
||||||
private final EventType event;
|
|
||||||
|
|
||||||
NAPushType(ModuleType moduleType, EventType event) {
|
|
||||||
this.moduleType = moduleType;
|
|
||||||
this.event = event;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ModuleType getModuleType() {
|
|
||||||
return moduleType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EventType getEvent() {
|
|
||||||
return event;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,12 +46,12 @@ class NAPushTypeDeserializer implements JsonDeserializer<NAPushType> {
|
||||||
moduleType = fromNetatmoObject(elements[0]);
|
moduleType = fromNetatmoObject(elements[0]);
|
||||||
eventType = fromEvent(elements[1]);
|
eventType = fromEvent(elements[1]);
|
||||||
} else if (elements.length == 1) {
|
} else if (elements.length == 1) {
|
||||||
moduleType = ModuleType.ACCOUNT;
|
|
||||||
eventType = fromEvent(string);
|
eventType = fromEvent(string);
|
||||||
|
moduleType = eventType.getFirstModule();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (moduleType.equals(ModuleType.UNKNOWN) || eventType.equals(EventType.UNKNOWN)) {
|
if (moduleType.equals(ModuleType.UNKNOWN) || eventType.equals(EventType.UNKNOWN)) {
|
||||||
logger.warn("Unknown module or event type : {}, deserialized to '{}-{}'", string, moduleType, eventType);
|
logger.warn("Unknown module or event type: {}, deserialized to '{}-{}'", string, moduleType, eventType);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new NAPushType(moduleType, eventType);
|
return new NAPushType(moduleType, eventType);
|
||||||
|
|
Loading…
Reference in New Issue