diff --git a/libnymea/integrations/thing.cpp b/libnymea/integrations/thing.cpp index fb62b57f..48581061 100644 --- a/libnymea/integrations/thing.cpp +++ b/libnymea/integrations/thing.cpp @@ -383,6 +383,24 @@ State Thing::state(const StateTypeId &stateTypeId) const return State(StateTypeId(), ThingId()); } +void Thing::setStateLogged(const StateTypeId &stateTypeId, bool logged) +{ + for (int i = 0; i < m_states.count(); i++) { + if (m_states.at(i).stateTypeId() == stateTypeId) { + m_states[i].setLogged(logged); + } + } +} + +void Thing::setStateFilter(const StateTypeId &stateTypeId, Types::StateValueFilter filter) +{ + for (int i = 0; i < m_states.count(); i++) { + if (m_states.at(i).stateTypeId() == stateTypeId) { + m_states[i].setFilter(filter); + } + } +} + /*! Returns the \l{ThingId} of the parent of this thing. If the parentId is not set, this thing does not have a parent. */ diff --git a/libnymea/integrations/thing.h b/libnymea/integrations/thing.h index 2e739aa0..f5b46244 100644 --- a/libnymea/integrations/thing.h +++ b/libnymea/integrations/thing.h @@ -133,6 +133,9 @@ public: Q_INVOKABLE State state(const StateTypeId &stateTypeId) const; + void setStateLogged(const StateTypeId &stateTypeId, bool logged); + void setStateFilter(const StateTypeId &stateTypeId, Types::StateValueFilter filter); + ThingId parentId() const; void setParentId(const ThingId &parentId); diff --git a/libnymea/types/state.cpp b/libnymea/types/state.cpp index 8df85f32..3717bf85 100644 --- a/libnymea/types/state.cpp +++ b/libnymea/types/state.cpp @@ -80,6 +80,26 @@ void State::setValue(const QVariant &value) m_value = value; } +Types::StateValueFilter State::filter() const +{ + return m_filter; +} + +void State::setFilter(Types::StateValueFilter filter) +{ + m_filter = filter; +} + +bool State::logged() const +{ + return m_logged; +} + +void State::setLogged(bool logged) +{ + m_logged = logged; +} + /*! Writes the stateTypeId, the deviceId and the value of the given \a state to \a dbg. */ QDebug operator<<(QDebug dbg, const State &state) { diff --git a/libnymea/types/state.h b/libnymea/types/state.h index f6b43659..754fd843 100644 --- a/libnymea/types/state.h +++ b/libnymea/types/state.h @@ -42,6 +42,8 @@ class LIBNYMEA_EXPORT State Q_GADGET Q_PROPERTY(QUuid stateTypeId READ stateTypeId) Q_PROPERTY(QVariant value READ value) + Q_PROPERTY(Types::StateValueFilter filter READ filter) + Q_PROPERTY(bool logged READ logged) public: State(); @@ -53,10 +55,18 @@ public: QVariant value() const; void setValue(const QVariant &value); + Types::StateValueFilter filter() const; + void setFilter(Types::StateValueFilter filter); + + bool logged() const; + void setLogged(bool logged); + private: StateTypeId m_stateTypeId; ThingId m_thingId; QVariant m_value; + Types::StateValueFilter m_filter; + bool m_logged = false; }; Q_DECLARE_METATYPE(State) diff --git a/libnymea/types/statetype.cpp b/libnymea/types/statetype.cpp index 2550380b..d566752c 100644 --- a/libnymea/types/statetype.cpp +++ b/libnymea/types/statetype.cpp @@ -208,6 +208,16 @@ void StateType::setCached(bool cached) m_cached = cached; } +Types::StateValueFilter StateType::filter() const +{ + return m_filter; +} + +void StateType::setFilter(Types::StateValueFilter filter) +{ + m_filter = filter; +} + /*! Returns a list of all valid properties a DeviceClass definition can have. */ QStringList StateType::typeProperties() { diff --git a/libnymea/types/statetype.h b/libnymea/types/statetype.h index 1532a434..0b542360 100644 --- a/libnymea/types/statetype.h +++ b/libnymea/types/statetype.h @@ -93,6 +93,12 @@ public: bool cached() const; void setCached(bool cached); + bool logged() const; + void setLogged(bool logged); + + Types::StateValueFilter filter() const; + void setFilter(Types::StateValueFilter filter); + static QStringList typeProperties(); static QStringList mandatoryTypeProperties(); @@ -112,6 +118,8 @@ private: Types::IOType m_ioType = Types::IOTypeNone; bool m_writable = false; bool m_cached = true; + bool m_logged = false; + Types::StateValueFilter m_filter = Types::StateValueFilterNone; }; Q_DECLARE_METATYPE(StateType) diff --git a/libnymea/typeutils.h b/libnymea/typeutils.h index 39f914b7..eaa8cddb 100644 --- a/libnymea/typeutils.h +++ b/libnymea/typeutils.h @@ -173,6 +173,12 @@ public: IOTypeAnalogOutput }; Q_ENUM(IOType) + + enum StateValueFilter { + StateValueFilterNone, + StateValueFilterAdaptive + }; + Q_ENUM(StateValueFilter) }; Q_DECLARE_METATYPE(Types::InputType)