diff --git a/libnymea-core/nymeacore.cpp b/libnymea-core/nymeacore.cpp index 4d0f05f7..8a15050a 100644 --- a/libnymea-core/nymeacore.cpp +++ b/libnymea-core/nymeacore.cpp @@ -660,7 +660,17 @@ ZigbeeManager *NymeaCore::zigbeeManager() const void NymeaCore::gotEvent(const Event &event) { - m_logger->logEvent(event); + Thing *thing = m_thingManager->findConfiguredThing(event.thingId()); + ThingClass thingClass = thing ? thing->thingClass() : ThingClass(); + EventType eventType = thingClass.eventTypes().findById(event.eventTypeId()); + foreach (const QString &interfaceName, thingClass.interfaces()) { + Interface iface = m_thingManager->supportedInterfaces().findByName(interfaceName); + if (iface.eventTypes().findByName(eventType.name()).logged()) { + m_logger->logEvent(event); + break; + } + } + emit eventTriggered(event); QList actions; diff --git a/libnymea/integrations/thingutils.cpp b/libnymea/integrations/thingutils.cpp index cdf52435..6c384562 100644 --- a/libnymea/integrations/thingutils.cpp +++ b/libnymea/integrations/thingutils.cpp @@ -200,6 +200,7 @@ Interface ThingUtils::loadInterface(const QString &name) stateType.setMinValue(stateVariant.toMap().value("minValue")); stateType.setMaxValue(stateVariant.toMap().value("maxValue")); stateType.setOptional(stateVariant.toMap().value("optional", false).toBool()); + stateType.setLogged(stateVariant.toMap().value("logged", false).toBool()); if (stateVariant.toMap().contains("unit")) { QMetaEnum unitEnum = QMetaEnum::fromType(); int enumValue = unitEnum.keyToValue("Unit" + stateVariant.toMap().value("unit").toByteArray()); @@ -214,6 +215,7 @@ Interface ThingUtils::loadInterface(const QString &name) InterfaceEventType stateChangeEventType; stateChangeEventType.setName(stateType.name()); stateChangeEventType.setOptional(stateType.optional()); + stateChangeEventType.setLogged(stateType.logged()); ParamType stateChangeEventParamType; stateChangeEventParamType.setName(stateType.name()); stateChangeEventParamType.setType(stateType.type()); @@ -254,6 +256,7 @@ Interface ThingUtils::loadInterface(const QString &name) InterfaceEventType eventType; eventType.setName(eventVariant.toMap().value("name").toString()); eventType.setOptional(eventVariant.toMap().value("optional").toBool()); + eventType.setLogged(eventVariant.toMap().value("logged").toBool()); ParamTypes paramTypes; foreach (const QVariant &eventParamVariant, eventVariant.toMap().value("params").toList()) { ParamType paramType; diff --git a/libnymea/interfaces/battery.json b/libnymea/interfaces/battery.json index 8c580479..e6c0e3b2 100644 --- a/libnymea/interfaces/battery.json +++ b/libnymea/interfaces/battery.json @@ -2,7 +2,8 @@ "states": [ { "name": "batteryCritical", - "type": "bool" + "type": "bool", + "logged": true } ] } diff --git a/libnymea/interfaces/button.json b/libnymea/interfaces/button.json index 72211093..d98b2573 100644 --- a/libnymea/interfaces/button.json +++ b/libnymea/interfaces/button.json @@ -2,7 +2,8 @@ "description": "The base for all buttons that emit a pressed event.", "events": [ { - "name": "pressed" + "name": "pressed", + "logged": true } ] } diff --git a/libnymea/interfaces/closablesensor.json b/libnymea/interfaces/closablesensor.json index b8ef5b55..e8320fc5 100644 --- a/libnymea/interfaces/closablesensor.json +++ b/libnymea/interfaces/closablesensor.json @@ -4,7 +4,8 @@ "states": [ { "name": "closed", - "type": "bool" + "type": "bool", + "logged": true } ] } diff --git a/libnymea/interfaces/co2sensor.json b/libnymea/interfaces/co2sensor.json index 2174ebb8..e4673292 100644 --- a/libnymea/interfaces/co2sensor.json +++ b/libnymea/interfaces/co2sensor.json @@ -5,7 +5,8 @@ { "name": "co2", "type": "double", - "unit": "PartsPerMillion" + "unit": "PartsPerMillion", + "logged": true } ] } diff --git a/libnymea/interfaces/conductivitysensor.json b/libnymea/interfaces/conductivitysensor.json index d1d9e63c..4d4f7533 100644 --- a/libnymea/interfaces/conductivitysensor.json +++ b/libnymea/interfaces/conductivitysensor.json @@ -4,7 +4,8 @@ { "name": "conductivity", "type": "double", - "unit": "MicroSiemensPerCentimeter" + "unit": "MicroSiemensPerCentimeter", + "logged": true } ] } diff --git a/libnymea/interfaces/connectable.json b/libnymea/interfaces/connectable.json index bc061381..aca9566c 100644 --- a/libnymea/interfaces/connectable.json +++ b/libnymea/interfaces/connectable.json @@ -3,7 +3,8 @@ { "name": "connected", "type": "bool", - "defaultValue": false + "defaultValue": false, + "logged": true } ] } diff --git a/libnymea/interfaces/daylightsensor.json b/libnymea/interfaces/daylightsensor.json index db82c096..e391bec0 100644 --- a/libnymea/interfaces/daylightsensor.json +++ b/libnymea/interfaces/daylightsensor.json @@ -4,7 +4,8 @@ "states": [ { "name": "daylight", - "type": "bool" + "type": "bool", + "logged": true }, { "name": "sunriseTime", diff --git a/libnymea/interfaces/doorbell.json b/libnymea/interfaces/doorbell.json index e90aad65..bc6dd97d 100644 --- a/libnymea/interfaces/doorbell.json +++ b/libnymea/interfaces/doorbell.json @@ -2,7 +2,8 @@ "description": "An interface for doorbells. Emits \"doorbellPressed\" when the doorbell is pressed.", "events": [ { - "name": "doorbellPressed" + "name": "doorbellPressed", + "logged": true } ] } diff --git a/libnymea/interfaces/extendedclosable.json b/libnymea/interfaces/extendedclosable.json index d5ca5085..48b6342b 100644 --- a/libnymea/interfaces/extendedclosable.json +++ b/libnymea/interfaces/extendedclosable.json @@ -4,7 +4,8 @@ "states": [ { "name": "moving", - "type": "bool" + "type": "bool", + "logged": true }, { "name": "percentage", diff --git a/libnymea/interfaces/extendedsmartmeterconsumer.json b/libnymea/interfaces/extendedsmartmeterconsumer.json index f476bd9e..6aa31b31 100644 --- a/libnymea/interfaces/extendedsmartmeterconsumer.json +++ b/libnymea/interfaces/extendedsmartmeterconsumer.json @@ -5,7 +5,8 @@ { "name": "currentPower", "type": "double", - "unit": "Watt" + "unit": "Watt", + "logged": true } ] } diff --git a/libnymea/interfaces/extendedsmartmeterproducer.json b/libnymea/interfaces/extendedsmartmeterproducer.json index 0c8ad6c7..218f3bf0 100644 --- a/libnymea/interfaces/extendedsmartmeterproducer.json +++ b/libnymea/interfaces/extendedsmartmeterproducer.json @@ -4,7 +4,9 @@ "states": [ { "name": "currentPower", - "type": "double" + "type": "double", + "unit": "Watt", + "logged": true } ] } diff --git a/libnymea/interfaces/fingerprintreader.json b/libnymea/interfaces/fingerprintreader.json index 953222b5..5af7d805 100644 --- a/libnymea/interfaces/fingerprintreader.json +++ b/libnymea/interfaces/fingerprintreader.json @@ -24,7 +24,8 @@ "PinkyRight" ] } - ] + ], + "logged": true } ], "actions": [ diff --git a/libnymea/interfaces/garagegate.json b/libnymea/interfaces/garagegate.json index e692e7e9..653c68f8 100644 --- a/libnymea/interfaces/garagegate.json +++ b/libnymea/interfaces/garagegate.json @@ -5,7 +5,8 @@ { "name": "state", "type": "QString", - "allowedValues": ["open", "closed", "opening", "closing"] + "allowedValues": ["open", "closed", "opening", "closing"], + "logged": true }, { "name": "intermediatePosition", diff --git a/libnymea/interfaces/humiditysensor.json b/libnymea/interfaces/humiditysensor.json index 0f15fd86..a3629bf7 100644 --- a/libnymea/interfaces/humiditysensor.json +++ b/libnymea/interfaces/humiditysensor.json @@ -5,7 +5,8 @@ "name": "humidity", "type": "double", "minValue": 0, - "maxValue": 100 + "maxValue": 100, + "logged": true } ] } diff --git a/libnymea/interfaces/impulsegaragedoor.json b/libnymea/interfaces/impulsegaragedoor.json index 15155c3c..a662c9f2 100644 --- a/libnymea/interfaces/impulsegaragedoor.json +++ b/libnymea/interfaces/impulsegaragedoor.json @@ -3,7 +3,8 @@ "description": "This interface is for the simplest form of garage doors which can be controlled only via an impulse. Triggering the impulse will start moving the door, triggering it again will stop the movement. Triggering it yet another time will start movement in the reverse direction. Note that there is no feedback channel on such devices. The system has no chance of knowing the current state this device is actually in.", "actions": [ { - "name": "triggerImpulse" + "name": "triggerImpulse", + "logged": true } ] } diff --git a/libnymea/interfaces/inputtrigger.json b/libnymea/interfaces/inputtrigger.json index 393e47da..884a3797 100644 --- a/libnymea/interfaces/inputtrigger.json +++ b/libnymea/interfaces/inputtrigger.json @@ -1,7 +1,8 @@ { "events": [ { - "name": "triggered" + "name": "triggered", + "logged": true } ] } diff --git a/libnymea/interfaces/lightsensor.json b/libnymea/interfaces/lightsensor.json index 146b149a..54a425b2 100644 --- a/libnymea/interfaces/lightsensor.json +++ b/libnymea/interfaces/lightsensor.json @@ -4,7 +4,8 @@ { "name": "lightIntensity", "type": "double", - "unit": "Lux" + "unit": "Lux", + "logged": true } ] } diff --git a/libnymea/interfaces/longpressbutton.json b/libnymea/interfaces/longpressbutton.json index 75efeb8d..4a4ea4b5 100644 --- a/libnymea/interfaces/longpressbutton.json +++ b/libnymea/interfaces/longpressbutton.json @@ -3,7 +3,8 @@ "extends": "button", "events": [ { - "name": "longPressed" + "name": "longPressed", + "logged": true } ] } diff --git a/libnymea/interfaces/longpressmultibutton.json b/libnymea/interfaces/longpressmultibutton.json index 60fd2c7a..e696de50 100644 --- a/libnymea/interfaces/longpressmultibutton.json +++ b/libnymea/interfaces/longpressmultibutton.json @@ -9,7 +9,8 @@ "name": "buttonName", "type": "QString" } - ] + ], + "logged": true } ] } diff --git a/libnymea/interfaces/moisturesensor.json b/libnymea/interfaces/moisturesensor.json index bd01c0b9..a6c47379 100644 --- a/libnymea/interfaces/moisturesensor.json +++ b/libnymea/interfaces/moisturesensor.json @@ -3,7 +3,8 @@ "states": [ { "name": "moisture", - "type": "double" + "type": "double", + "logged": true } ] } diff --git a/libnymea/interfaces/multibutton.json b/libnymea/interfaces/multibutton.json index 8fc5ae08..20b94171 100644 --- a/libnymea/interfaces/multibutton.json +++ b/libnymea/interfaces/multibutton.json @@ -9,7 +9,8 @@ "name": "buttonName", "type": "QString" } - ] + ], + "logged": true } ] } diff --git a/libnymea/interfaces/noisesensor.json b/libnymea/interfaces/noisesensor.json index b69d0461..ec578352 100644 --- a/libnymea/interfaces/noisesensor.json +++ b/libnymea/interfaces/noisesensor.json @@ -5,7 +5,8 @@ { "name": "noise", "type": "double", - "unit": "Dezibel" + "unit": "Dezibel", + "logged": true } ] } diff --git a/libnymea/interfaces/notifications.json b/libnymea/interfaces/notifications.json index 1341ce3b..dc85d015 100644 --- a/libnymea/interfaces/notifications.json +++ b/libnymea/interfaces/notifications.json @@ -11,8 +11,8 @@ "name": "body", "type": "QString" } - ] + ], + "logged": true } - ] } diff --git a/libnymea/interfaces/power.json b/libnymea/interfaces/power.json index 160f9432..a70fbabf 100644 --- a/libnymea/interfaces/power.json +++ b/libnymea/interfaces/power.json @@ -3,7 +3,8 @@ { "name": "power", "type": "bool", - "writable": true + "writable": true, + "logged": true } ] } diff --git a/libnymea/interfaces/presencesensor.json b/libnymea/interfaces/presencesensor.json index 7806b3d9..6fcb8c00 100644 --- a/libnymea/interfaces/presencesensor.json +++ b/libnymea/interfaces/presencesensor.json @@ -4,7 +4,8 @@ "states": [ { "name": "isPresent", - "type": "bool" + "type": "bool", + "logged": true }, { "name": "lastSeenTime", diff --git a/libnymea/interfaces/pressuresensor.json b/libnymea/interfaces/pressuresensor.json index a8b45887..64802ed7 100644 --- a/libnymea/interfaces/pressuresensor.json +++ b/libnymea/interfaces/pressuresensor.json @@ -4,7 +4,8 @@ { "name": "pressure", "type": "double", - "unit": "MilliBar" + "unit": "MilliBar", + "logged": true } ] } diff --git a/libnymea/interfaces/smartlock.json b/libnymea/interfaces/smartlock.json index 498950d3..95c71fc2 100644 --- a/libnymea/interfaces/smartlock.json +++ b/libnymea/interfaces/smartlock.json @@ -4,7 +4,8 @@ { "name": "state", "type": "QString", - "allowedValues": ["locked", "locking", "unlocked", "unlocking", "unlatched", "unlatching"] + "allowedValues": ["locked", "locking", "unlocked", "unlocking", "unlatched", "unlatching"], + "logged": true } ], "actions": [ diff --git a/libnymea/interfaces/statefulgaragedoor.json b/libnymea/interfaces/statefulgaragedoor.json index cd0c9ecb..ed1271cd 100644 --- a/libnymea/interfaces/statefulgaragedoor.json +++ b/libnymea/interfaces/statefulgaragedoor.json @@ -5,7 +5,8 @@ { "name": "state", "type": "QString", - "allowedValues": ["open", "closed", "opening", "closing", "intermediate"] + "allowedValues": ["open", "closed", "opening", "closing", "intermediate"], + "logged": true } ] } diff --git a/libnymea/interfaces/temperaturesensor.json b/libnymea/interfaces/temperaturesensor.json index 04fafa42..7edad7f9 100644 --- a/libnymea/interfaces/temperaturesensor.json +++ b/libnymea/interfaces/temperaturesensor.json @@ -4,7 +4,8 @@ { "name": "temperature", "type": "double", - "unit": "DegreeCelsius" + "unit": "DegreeCelsius", + "logged": true } ] } diff --git a/libnymea/interfaces/useraccesscontrol.json b/libnymea/interfaces/useraccesscontrol.json index b1059651..5d43dccf 100644 --- a/libnymea/interfaces/useraccesscontrol.json +++ b/libnymea/interfaces/useraccesscontrol.json @@ -14,7 +14,8 @@ "name": "userId", "type": "QString" } - ] + ], + "logged": true } ], "actions": [ @@ -25,8 +26,8 @@ "name": "userId", "type": "QString" } - - ] + ], + "logged": true }, { "name": "removeUser", @@ -36,7 +37,8 @@ "type": "QString" } - ] + ], + "logged": true } ] } diff --git a/libnymea/interfaces/windspeedsensor.json b/libnymea/interfaces/windspeedsensor.json index 83bf0a01..62a61404 100644 --- a/libnymea/interfaces/windspeedsensor.json +++ b/libnymea/interfaces/windspeedsensor.json @@ -5,7 +5,8 @@ { "name": "windSpeed", "type": "double", - "unit": "MeterPerSecond" + "unit": "MeterPerSecond", + "logged": true } ] } diff --git a/libnymea/types/interfaceeventtype.cpp b/libnymea/types/interfaceeventtype.cpp index 1ee3f9ac..9d4ce6aa 100644 --- a/libnymea/types/interfaceeventtype.cpp +++ b/libnymea/types/interfaceeventtype.cpp @@ -15,6 +15,16 @@ void InterfaceEventType::setOptional(bool optional) m_optional = optional; } +bool InterfaceEventType::logged() const +{ + return m_logged; +} + +void InterfaceEventType::setLogged(bool logged) +{ + m_logged = logged; +} + InterfaceEventTypes::InterfaceEventTypes(const QList &other): QList(other) { diff --git a/libnymea/types/interfaceeventtype.h b/libnymea/types/interfaceeventtype.h index c81305b4..aa3a79c2 100644 --- a/libnymea/types/interfaceeventtype.h +++ b/libnymea/types/interfaceeventtype.h @@ -11,8 +11,12 @@ public: bool optional() const; void setOptional(bool optional); + bool logged() const; + void setLogged(bool logged); + private: bool m_optional = false; + bool m_logged = false; }; class InterfaceEventTypes: public QList diff --git a/libnymea/types/interfacestatetype.cpp b/libnymea/types/interfacestatetype.cpp index 97981bd1..e2b97191 100644 --- a/libnymea/types/interfacestatetype.cpp +++ b/libnymea/types/interfacestatetype.cpp @@ -15,6 +15,16 @@ void InterfaceStateType::setOptional(bool optional) m_optional = optional; } +bool InterfaceStateType::logged() const +{ + return m_logged; +} + +void InterfaceStateType::setLogged(bool logged) +{ + m_logged = logged; +} + InterfaceStateTypes::InterfaceStateTypes(const QList &other): QList(other) { diff --git a/libnymea/types/interfacestatetype.h b/libnymea/types/interfacestatetype.h index 247f3b48..88429916 100644 --- a/libnymea/types/interfacestatetype.h +++ b/libnymea/types/interfacestatetype.h @@ -11,8 +11,12 @@ public: bool optional() const; void setOptional(bool optional); + bool logged() const; + void setLogged(bool logged); + private: bool m_optional = false; + bool m_logged = false; }; class InterfaceStateTypes: public QList