diff --git a/libhive/deviceclass.cpp b/libhive/deviceclass.cpp index 314a86cf..dbcd74ae 100644 --- a/libhive/deviceclass.cpp +++ b/libhive/deviceclass.cpp @@ -37,6 +37,16 @@ void DeviceClass::setName(const QString &name) m_name = name; } +QList DeviceClass::states() const +{ + return m_states; +} + +void DeviceClass::setStates(const QList &states) +{ + m_states = states; +} + QList DeviceClass::triggers() const { return m_triggers; diff --git a/libhive/deviceclass.h b/libhive/deviceclass.h index 548a52b8..f55313f1 100644 --- a/libhive/deviceclass.h +++ b/libhive/deviceclass.h @@ -3,6 +3,7 @@ #include "triggertype.h" #include "actiontype.h" +#include "statetype.h" #include #include @@ -20,6 +21,9 @@ public: QString name() const; void setName(const QString &name); + QList states() const; + void setStates(const QList &states); + QList triggers() const; void setTriggers(const QList &triggers); @@ -35,6 +39,7 @@ private: QUuid m_id; QUuid m_pluginId; QString m_name; + QList m_states; QList m_triggers; QList m_actions; QVariantList m_params; diff --git a/libhive/libhive.pro b/libhive/libhive.pro index 7b017d07..9b54df41 100644 --- a/libhive/libhive.pro +++ b/libhive/libhive.pro @@ -16,6 +16,8 @@ SOURCES += device.cpp \ triggertype.cpp \ action.cpp \ actiontype.cpp \ + state.cpp \ + statetype.cpp HEADERS += device.h \ deviceclass.h \ @@ -27,4 +29,6 @@ HEADERS += device.h \ triggertype.h \ action.h \ actiontype.h \ + state.h \ + statetype.h diff --git a/libhive/state.cpp b/libhive/state.cpp new file mode 100644 index 00000000..6a9b7aff --- /dev/null +++ b/libhive/state.cpp @@ -0,0 +1,5 @@ +#include "state.h" + +State::State(const QUuid &stateTypeId) +{ +} diff --git a/libhive/state.h b/libhive/state.h new file mode 100644 index 00000000..51ab16cd --- /dev/null +++ b/libhive/state.h @@ -0,0 +1,22 @@ +#ifndef STATE_H +#define STATE_H + +#include +#include + +class State +{ +public: + State(const QUuid &stateTypeId); + + QUuid stateTypeId() const; + + QVariant value() const; + void setValue(const QVariant &value); + +private: + QUuid m_stateTypeId; + QVariant m_value; +}; + +#endif // STATE_H diff --git a/libhive/statetype.cpp b/libhive/statetype.cpp new file mode 100644 index 00000000..1001471b --- /dev/null +++ b/libhive/statetype.cpp @@ -0,0 +1,31 @@ +#include "statetype.h" + +StateType::StateType(const QUuid &id): + m_id(id) +{ +} + +QUuid StateType::id() const +{ + return m_id; +} + +QString StateType::name() const +{ + return m_name; +} + +void StateType::setName(const QString &name) +{ + m_name = name; +} + +QVariant::Type StateType::type() const +{ + return m_type; +} + +void StateType::setType(const QVariant::Type &type) +{ + m_type = type; +} diff --git a/libhive/statetype.h b/libhive/statetype.h new file mode 100644 index 00000000..d01cdaf5 --- /dev/null +++ b/libhive/statetype.h @@ -0,0 +1,26 @@ +#ifndef STATETYPE_H +#define STATETYPE_H + +#include +#include + +class StateType +{ +public: + StateType(const QUuid &id); + + QUuid id() const; + + QString name() const; + void setName(const QString &name); + + QVariant::Type type() const; + void setType(const QVariant::Type &type); + +private: + QUuid m_id; + QString m_name; + QVariant::Type m_type; +}; + +#endif // STATETYPE_H diff --git a/plugins/deviceplugins/devicepluginmeisteranker/devicepluginmeisteranker.cpp b/plugins/deviceplugins/devicepluginmeisteranker/devicepluginmeisteranker.cpp index eeebe5d7..d5e06b12 100644 --- a/plugins/deviceplugins/devicepluginmeisteranker/devicepluginmeisteranker.cpp +++ b/plugins/deviceplugins/devicepluginmeisteranker/devicepluginmeisteranker.cpp @@ -29,7 +29,21 @@ QList DevicePluginMeisterAnker::supportedDevices() const thermometerParams.append(idParam); deviceClassMeisterAnkerThermometer.setParams(thermometerParams); - + + QList thermometerStates; + + StateType tempState("a9849491-25f4-43a3-a6fe-3bfce43d6332"); + tempState.setName("Temperature"); + tempState.setType(QVariant::Double); + thermometerStates.append(tempState); + + StateType batteryState("ebf951ba-75ca-47ac-ba3c-ea9ec1e7bbd1"); + batteryState.setName("Battery"); + batteryState.setType(QVariant::Bool); + thermometerStates.append(batteryState); + + deviceClassMeisterAnkerThermometer.setStates(thermometerStates); + QList thermometerTriggers; QVariantList paramsThermometer; diff --git a/server/jsonrpcserver.cpp b/server/jsonrpcserver.cpp index 8b441c31..900dfe0e 100644 --- a/server/jsonrpcserver.cpp +++ b/server/jsonrpcserver.cpp @@ -194,6 +194,15 @@ QVariantMap JsonRPCServer::packDeviceClass(const DeviceClass &deviceClass) QVariantMap variant; variant.insert("name", deviceClass.name()); variant.insert("id", deviceClass.id()); + QVariantList stateTypes; + foreach (const StateType &stateType, deviceClass.states()) { + QVariantMap stateMap; + stateMap.insert("id", stateType.id().toString()); + stateMap.insert("name", stateType.name()); + stateMap.insert("type", QVariant::typeToName(stateType.type())); + + stateTypes.append(stateMap); + } QVariantList triggerTypes; foreach (const TriggerType &triggerType, deviceClass.triggers()) { QVariantMap triggerMap; @@ -204,7 +213,6 @@ QVariantMap JsonRPCServer::packDeviceClass(const DeviceClass &deviceClass) triggerTypes.append(triggerMap); } QVariantList actionTypes; - qDebug() << "*******************" << deviceClass.actions().count(); foreach (const ActionType &actionType, deviceClass.actions()) { QVariantMap actionMap; actionMap.insert("id", actionType.id().toString()); @@ -214,6 +222,7 @@ QVariantMap JsonRPCServer::packDeviceClass(const DeviceClass &deviceClass) actionTypes.append(actionMap); } variant.insert("params", deviceClass.params()); + variant.insert("states", stateTypes); variant.insert("triggers", triggerTypes); variant.insert("actions", actionTypes); return variant;