// 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 ZWAVEMANAGER_H #define ZWAVEMANAGER_H #include #include #include "engine.h" #include "zwavenetwork.h" #include "types/serialports.h" class JsonRpcClient; class ZWaveManager : public QObject { Q_OBJECT Q_PROPERTY(Engine *engine READ engine WRITE setEngine NOTIFY engineChanged FINAL) Q_PROPERTY(bool fetchingData READ fetchingData NOTIFY fetchingDataChanged FINAL) Q_PROPERTY(bool zwaveAvailable READ zwaveAvailable NOTIFY zwaveAvailableChanged FINAL) Q_PROPERTY(SerialPorts *serialPorts READ serialPorts CONSTANT FINAL) Q_PROPERTY(ZWaveNetworks *networks READ networks CONSTANT FINAL) public: enum ZWaveError { ZWaveErrorNoError, ZWaveErrorInUse, ZWaveErrorNetworkUuidNotFound, ZWaveErrorNodeIdNotFound, ZWaveErrorTimeout, ZWaveErrorBackendError }; Q_ENUM(ZWaveError) explicit ZWaveManager(QObject *parent = nullptr); ~ZWaveManager(); void setEngine(Engine *engine); Engine *engine() const; bool fetchingData() const; bool zwaveAvailable() const; SerialPorts *serialPorts() const; ZWaveNetworks *networks() const; Q_INVOKABLE int addNetwork(const QString &serialPort); Q_INVOKABLE int removeNetwork(const QUuid &networkUuid); Q_INVOKABLE int addNode(const QUuid &networkUuid); Q_INVOKABLE void cancelPendingOperation(const QUuid &networkUuid); Q_INVOKABLE int factoryResetNetwork(const QUuid &networkUuid); // Q_INVOKABLE void getNodes(const QUuid &networkUuid); Q_INVOKABLE int removeNode(const QUuid &networkUuid); Q_INVOKABLE int removeFailedNode(const QUuid &networkUuid, int nodeId); signals: void engineChanged(); void fetchingDataChanged(); void zwaveAvailableChanged(); void addNetworkReply(int commandId, ZWaveManager::ZWaveError error, const QUuid &networkUuid); void removeNetworkReply(int commandId, ZWaveManager::ZWaveError error); void cancelPendingOperationReply(int commandId, ZWaveManager::ZWaveError error); void softResetControllerReply(int commandId, ZWaveManager::ZWaveError error); void factoryResetNetworkReply(int commandId, ZWaveManager::ZWaveError error); void addNodeReply(int commandId, ZWaveManager::ZWaveError error); void removeNodeReply(int commandId, ZWaveManager::ZWaveError error); void removeFailedNodeReply(int commandId, ZWaveManager::ZWaveError error); private: void init(); Q_INVOKABLE void isZWaveAvailableResponse(int commandId, const QVariantMap ¶ms); Q_INVOKABLE void getSerialPortsResponse(int commandId, const QVariantMap ¶ms); Q_INVOKABLE void getNetworksResponse(int commandId, const QVariantMap ¶ms); Q_INVOKABLE void getNodesResponse(int commandId, const QVariantMap ¶ms); Q_INVOKABLE void addNetworkResponse(int commandId, const QVariantMap ¶ms); Q_INVOKABLE void removeNetworkResponse(int commandId, const QVariantMap ¶ms); Q_INVOKABLE void cancelPendingOperationResponse(int commandId, const QVariantMap ¶ms); Q_INVOKABLE void softResetControllerResponse(int commandId, const QVariantMap ¶ms); Q_INVOKABLE void factoryResetNetworkResponse(int commandId, const QVariantMap ¶ms); Q_INVOKABLE void addNodeResponse(int commandId, const QVariantMap ¶ms); Q_INVOKABLE void removeNodeResponse(int commandId, const QVariantMap ¶ms); Q_INVOKABLE void removeFailedNodeResponse(int commandId, const QVariantMap ¶ms); Q_INVOKABLE void notificationReceived(const QVariantMap &data); private: Engine *m_engine = nullptr; bool m_fetchingData = false; bool m_zwaveAvailable = false; SerialPorts *m_serialPorts = nullptr; ZWaveNetworks *m_networks = nullptr; QHash m_pendingGetNodeCalls; ZWaveNetwork *unpackNetwork(const QVariantMap &networkMap, ZWaveNetwork *network = nullptr); ZWaveNode *unpackNode(const QVariantMap &nodeMap, ZWaveNode *node = nullptr); }; #endif // ZWAVEMANAGER_H