// SPDX-License-Identifier: LGPL-3.0-or-later /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright (C) 2013 - 2024, nymea GmbH * Copyright (C) 2024 - 2025, chargebyte austria GmbH * * This file is part of libnymea-app. * * libnymea-app is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. * * libnymea-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with libnymea-app. If not, see . * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #ifndef THING_H #define THING_H #include #include #include "params.h" #include "states.h" #include "statesproxy.h" #include "thingclass.h" class ThingManager; class Thing : public QObject { Q_OBJECT Q_PROPERTY(QUuid id READ id CONSTANT) Q_PROPERTY(QUuid thingClassId READ thingClassId CONSTANT) Q_PROPERTY(QUuid parentId READ parentId CONSTANT) Q_PROPERTY(bool isChild READ isChild CONSTANT) Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(ThingSetupStatus setupStatus READ setupStatus NOTIFY setupStatusChanged) Q_PROPERTY(QString setupDisplayMessage READ setupDisplayMessage NOTIFY setupStatusChanged) Q_PROPERTY(Params *params READ params NOTIFY paramsChanged) Q_PROPERTY(Params *settings READ settings NOTIFY settingsChanged) Q_PROPERTY(States *states READ states NOTIFY statesChanged) Q_PROPERTY(ThingClass *thingClass READ thingClass CONSTANT) Q_PROPERTY(QList loggedStateTypeIds READ loggedStateTypeIds NOTIFY loggedStateTypeIdsChanged) Q_PROPERTY(QList loggedEventTypeIds READ loggedEventTypeIds NOTIFY loggedEventTypeIdsChanged) Q_PROPERTY(QList loggedActionTypeIds READ loggedActionTypeIds NOTIFY loggedActionTypeIdsChanged) public: enum ThingSetupStatus { ThingSetupStatusNone, ThingSetupStatusInProgress, ThingSetupStatusComplete, ThingSetupStatusFailed }; Q_ENUM(ThingSetupStatus) enum ThingError { ThingErrorNoError, ThingErrorPluginNotFound, ThingErrorVendorNotFound, ThingErrorThingNotFound, ThingErrorThingClassNotFound, ThingErrorActionTypeNotFound, ThingErrorStateTypeNotFound, ThingErrorEventTypeNotFound, ThingErrorThingDescriptorNotFound, ThingErrorMissingParameter, ThingErrorInvalidParameter, ThingErrorSetupFailed, ThingErrorDuplicateUuid, ThingErrorCreationMethodNotSupported, ThingErrorSetupMethodNotSupported, ThingErrorHardwareNotAvailable, ThingErrorHardwareFailure, ThingErrorAuthenticationFailure, ThingErrorThingInUse, ThingErrorThingInRule, ThingErrorThingIsChild, ThingErrorPairingTransactionIdNotFound, ThingErrorParameterNotWritable, ThingErrorItemNotFound, ThingErrorItemNotExecutable, ThingErrorUnsupportedFeature, ThingErrorTimeout, }; Q_ENUM(ThingError) explicit Thing(ThingManager *thingManager, ThingClass *thingClass, const QUuid &parentId = QUuid(), QObject *parent = nullptr); QUuid id() const; void setId(const QUuid &id); QString name() const; void setName(const QString &name); QUuid thingClassId() const; QUuid parentId() const; bool isChild() const; Thing::ThingSetupStatus setupStatus() const; QString setupDisplayMessage() const; void setSetupStatus(Thing::ThingSetupStatus setupStatus, const QString &displayMessage); Params *params() const; void setParams(Params *params); Params *settings() const; void setSettings(Params *settings); States *states() const; void setStates(States *states); void setStateValue(const QUuid &stateTypeId, const QVariant &value); QList loggedStateTypeIds() const; void setLoggedStateTypeIds(const QList &loggedStateTypeIds); QList loggedEventTypeIds() const; void setLoggedEventTypeIds(const QList &loggedEventTypeIds); QList loggedActionTypeIds() const; void setLoggedActionTypeIds(const QList &loggedActionTypeIds); ThingClass *thingClass() const; Q_INVOKABLE bool hasState(const QUuid &stateTypeId) const; Q_INVOKABLE State *state(const QUuid &stateTypeId) const; Q_INVOKABLE State *stateByName(const QString &stateName) const; Q_INVOKABLE QVariant stateValue(const QUuid &stateTypeId) const; Q_INVOKABLE Param *param(const QUuid ¶mTypeId) const; Q_INVOKABLE Param *paramByName(const QString ¶mName) const; Q_INVOKABLE virtual int executeAction(const QString &actionName, const QVariantList ¶ms = QVariantList()); signals: void nameChanged(); void setupStatusChanged(); void paramsChanged(); void settingsChanged(); void statesChanged(); void loggedStateTypeIdsChanged(); void loggedEventTypeIdsChanged(); void loggedActionTypeIdsChanged(); void eventTriggered(const QUuid &eventTypeId, const QVariantList ¶ms); signals: void executeActionReply(int commandId, Thing::ThingError thingError, const QString &displayMessage); protected: ThingManager *m_thingManager = nullptr; QString m_name; QUuid m_id; QUuid m_parentId; ThingSetupStatus m_setupStatus = ThingSetupStatusNone; QString m_setupDisplayMessage; Params *m_params = nullptr; Params *m_settings = nullptr; States *m_states = nullptr; ThingClass *m_thingClass = nullptr; QList m_loggedStateTypeIds; QList m_loggedEventTypeIds; QList m_loggedActionTypeIds; QList m_pendingActions; }; Q_DECLARE_METATYPE(Thing::ThingError) QDebug operator<<(QDebug &dbg, Thing* thing); #endif // THING_H