pull/1/head
Simon Stürz 2014-01-04 02:16:04 +01:00
commit 29627726ba
9 changed files with 128 additions and 2 deletions

View File

@ -37,6 +37,16 @@ void DeviceClass::setName(const QString &name)
m_name = name;
}
QList<StateType> DeviceClass::states() const
{
return m_states;
}
void DeviceClass::setStates(const QList<StateType> &states)
{
m_states = states;
}
QList<TriggerType> DeviceClass::triggers() const
{
return m_triggers;

View File

@ -3,6 +3,7 @@
#include "triggertype.h"
#include "actiontype.h"
#include "statetype.h"
#include <QList>
#include <QUuid>
@ -20,6 +21,9 @@ public:
QString name() const;
void setName(const QString &name);
QList<StateType> states() const;
void setStates(const QList<StateType> &states);
QList<TriggerType> triggers() const;
void setTriggers(const QList<TriggerType> &triggers);
@ -35,6 +39,7 @@ private:
QUuid m_id;
QUuid m_pluginId;
QString m_name;
QList<StateType> m_states;
QList<TriggerType> m_triggers;
QList<ActionType> m_actions;
QVariantList m_params;

View File

@ -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

5
libhive/state.cpp Normal file
View File

@ -0,0 +1,5 @@
#include "state.h"
State::State(const QUuid &stateTypeId)
{
}

22
libhive/state.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef STATE_H
#define STATE_H
#include <QUuid>
#include <QVariant>
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

31
libhive/statetype.cpp Normal file
View File

@ -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;
}

26
libhive/statetype.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef STATETYPE_H
#define STATETYPE_H
#include <QUuid>
#include <QVariant>
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

View File

@ -30,6 +30,20 @@ QList<DeviceClass> DevicePluginMeisterAnker::supportedDevices() const
deviceClassMeisterAnkerThermometer.setParams(thermometerParams);
QList<StateType> 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<TriggerType> thermometerTriggers;
QVariantList paramsThermometer;

View File

@ -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;