mirror of https://github.com/nymea/nymea.git
make it a little more typesafe
parent
53a8498172
commit
6485ebbff5
|
|
@ -311,7 +311,7 @@ QList<Device *> DeviceManager::findConfiguredDevices(const DeviceClassId &device
|
|||
|
||||
/*! For conveninece, this returns the \{DeviceClass} with the id given by \a deviceClassId.
|
||||
Note: The returned DeviceClass may be invalid.*/
|
||||
DeviceClass DeviceManager::findDeviceClass(const QUuid &deviceClassId) const
|
||||
DeviceClass DeviceManager::findDeviceClass(const DeviceClassId &deviceClassId) const
|
||||
{
|
||||
foreach (const DeviceClass &deviceClass, m_supportedDevices) {
|
||||
if (deviceClass.id() == deviceClassId) {
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ public:
|
|||
|
||||
Device* findConfiguredDevice(const DeviceId &id) const;
|
||||
QList<Device*> findConfiguredDevices(const DeviceClassId &deviceClassId) const;
|
||||
DeviceClass findDeviceClass(const QUuid &deviceClassId) const;
|
||||
DeviceClass findDeviceClass(const DeviceClassId &deviceClassId) const;
|
||||
|
||||
signals:
|
||||
void loaded();
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ void Device::setStates(const QList<State> &states)
|
|||
m_states = states;
|
||||
}
|
||||
|
||||
bool Device::hasState(const QUuid &stateTypeId) const
|
||||
bool Device::hasState(const StateTypeId &stateTypeId) const
|
||||
{
|
||||
foreach (const State &state, m_states) {
|
||||
if (state.stateTypeId() == stateTypeId) {
|
||||
|
|
@ -116,7 +116,7 @@ bool Device::hasState(const QUuid &stateTypeId) const
|
|||
}
|
||||
|
||||
/*! For convenience, this finds the \l{State} matching the given \a stateTypeId and returns the current valie in this Device. */
|
||||
QVariant Device::stateValue(const QUuid &stateTypeId) const
|
||||
QVariant Device::stateValue(const StateTypeId &stateTypeId) const
|
||||
{
|
||||
qDebug() << "device has states:" << m_states.count();
|
||||
foreach (const State &state, m_states) {
|
||||
|
|
|
|||
|
|
@ -49,8 +49,8 @@ public:
|
|||
QList<State> states() const;
|
||||
void setStates(const QList<State> &states);
|
||||
|
||||
bool hasState(const QUuid &stateTypeId) const;
|
||||
QVariant stateValue(const QUuid &stateTypeId) const;
|
||||
bool hasState(const StateTypeId &stateTypeId) const;
|
||||
QVariant stateValue(const StateTypeId &stateTypeId) const;
|
||||
void setStateValue(const StateTypeId &stateTypeId, const QVariant &value);
|
||||
|
||||
signals:
|
||||
|
|
|
|||
|
|
@ -71,6 +71,13 @@ void Event::setParams(const QVariantMap ¶ms)
|
|||
Events are equal (returns true) if eventTypeId, deviceId and params match. */
|
||||
bool Event::operator ==(const Event &other) const
|
||||
{
|
||||
|
||||
bool result =m_eventTypeId == other.eventTypeId()
|
||||
&& m_deviceId == other.deviceId()
|
||||
&& m_params == other.params();
|
||||
|
||||
qDebug() << "comparing event" << *this << "with" << other << "result is" << result << "params" << m_params << "other" << other.params();
|
||||
|
||||
return m_eventTypeId == other.eventTypeId()
|
||||
&& m_deviceId == other.deviceId()
|
||||
&& m_params == other.params();
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@ public: \
|
|||
type##Id(): QUuid() {} \
|
||||
static type##Id create##type##Id() { return type##Id(QUuid::createUuid().toString()); } \
|
||||
static type##Id fromUuid(const QUuid &uuid) { return type##Id(uuid.toString()); } \
|
||||
bool operator==(const type##Id &other) const { \
|
||||
return toString() == other.toString(); \
|
||||
} \
|
||||
}; \
|
||||
Q_DECLARE_METATYPE(type##Id);
|
||||
|
||||
|
|
@ -25,4 +28,14 @@ DECLARE_TYPE_ID(StateType)
|
|||
DECLARE_TYPE_ID(ActionType)
|
||||
DECLARE_TYPE_ID(Plugin)
|
||||
|
||||
|
||||
enum ParamOperand {
|
||||
ParamOperandEquals,
|
||||
ParamOperandNotEquals,
|
||||
ParamOperandLess,
|
||||
ParamOperandGreater,
|
||||
ParamOperandLessThan,
|
||||
ParamOperandGreaterThan
|
||||
};
|
||||
|
||||
#endif // TYPEUTILS_H
|
||||
|
|
|
|||
|
|
@ -114,12 +114,10 @@ void DevicePluginLircd::buttonPressed(const QString &remoteName, const QString &
|
|||
|
||||
qDebug() << "found remote" << remoteName << supportedDevices().first().events().count();
|
||||
foreach (const EventType &eventType, supportedDevices().first().events()) {
|
||||
qDebug() << "checking eventType" << eventType.name() << "with" << buttonName;
|
||||
if (eventType.name() == buttonName) {
|
||||
QVariantMap param;
|
||||
param.insert("repeat", repeat);
|
||||
Event event(eventType.id(), remote->id(), param);
|
||||
qDebug() << "emitting event";
|
||||
emitEvent(event);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,9 +35,9 @@ void HttpDaemon::incomingConnection(qintptr socket)
|
|||
|
||||
}
|
||||
|
||||
void HttpDaemon::actionExecuted(const QUuid &actionTypeId)
|
||||
void HttpDaemon::actionExecuted(const ActionTypeId &actionTypeId)
|
||||
{
|
||||
m_actionList.append(qMakePair<QUuid, QDateTime>(actionTypeId, QDateTime::currentDateTime()));
|
||||
m_actionList.append(qMakePair<ActionTypeId, QDateTime>(actionTypeId, QDateTime::currentDateTime()));
|
||||
}
|
||||
|
||||
void HttpDaemon::readClient()
|
||||
|
|
@ -160,7 +160,7 @@ QString HttpDaemon::generateWebPage()
|
|||
body.append("<table border=2px>");
|
||||
body.append("<tr><td>Name</td><td>Type ID</td><td>Timestamp</td></tr>");
|
||||
for (int i = 0; i < m_actionList.count(); ++i) {
|
||||
QUuid actionTypeId = m_actionList.at(i).first;
|
||||
ActionTypeId actionTypeId = ActionTypeId(m_actionList.at(i).first);
|
||||
QDateTime timestamp = m_actionList.at(i).second;
|
||||
QString actionName;
|
||||
foreach (const ActionType &at, deviceClass.actions()) {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public:
|
|||
|
||||
void incomingConnection(qintptr socket) override;
|
||||
|
||||
void actionExecuted(const QUuid&actionTypeId);
|
||||
void actionExecuted(const ActionTypeId &actionTypeId);
|
||||
|
||||
signals:
|
||||
void setState(const StateTypeId &stateTypeId, const QVariant &value);
|
||||
|
|
@ -38,7 +38,7 @@ private:
|
|||
DevicePlugin *m_plugin;
|
||||
Device *m_device;
|
||||
|
||||
QList<QPair<QUuid, QDateTime> > m_actionList;
|
||||
QList<QPair<ActionTypeId, QDateTime> > m_actionList;
|
||||
};
|
||||
|
||||
#endif // HTTPDAEMON_H
|
||||
|
|
|
|||
|
|
@ -332,7 +332,7 @@ JsonReply* DeviceHandler::GetEventTypes(const QVariantMap ¶ms) const
|
|||
QVariantMap returns;
|
||||
|
||||
QVariantList eventList;
|
||||
DeviceClass deviceClass = GuhCore::instance()->deviceManager()->findDeviceClass(params.value("deviceClassId").toUuid());
|
||||
DeviceClass deviceClass = GuhCore::instance()->deviceManager()->findDeviceClass(DeviceClassId(params.value("deviceClassId").toString()));
|
||||
foreach (const EventType &eventType, deviceClass.events()) {
|
||||
eventList.append(JsonTypes::packEventType(eventType));
|
||||
}
|
||||
|
|
@ -345,7 +345,7 @@ JsonReply* DeviceHandler::GetActionTypes(const QVariantMap ¶ms) const
|
|||
QVariantMap returns;
|
||||
|
||||
QVariantList actionList;
|
||||
DeviceClass deviceClass = GuhCore::instance()->deviceManager()->findDeviceClass(params.value("deviceClassId").toUuid());
|
||||
DeviceClass deviceClass = GuhCore::instance()->deviceManager()->findDeviceClass(DeviceClassId(params.value("deviceClassId").toString()));
|
||||
foreach (const ActionType &actionType, deviceClass.actions()) {
|
||||
actionList.append(JsonTypes::packActionType(actionType));
|
||||
}
|
||||
|
|
@ -358,7 +358,7 @@ JsonReply* DeviceHandler::GetStateTypes(const QVariantMap ¶ms) const
|
|||
QVariantMap returns;
|
||||
|
||||
QVariantList stateList;
|
||||
DeviceClass deviceClass = GuhCore::instance()->deviceManager()->findDeviceClass(params.value("deviceClassId").toUuid());
|
||||
DeviceClass deviceClass = GuhCore::instance()->deviceManager()->findDeviceClass(DeviceClassId(params.value("deviceClassId").toString()));
|
||||
foreach (const StateType &stateType, deviceClass.states()) {
|
||||
stateList.append(JsonTypes::packStateType(stateType));
|
||||
}
|
||||
|
|
@ -376,12 +376,12 @@ JsonReply* DeviceHandler::GetStateValue(const QVariantMap ¶ms) const
|
|||
returns.insert("errorMessage", "No such device");
|
||||
return createReply(returns);
|
||||
}
|
||||
if (!device->hasState(params.value("stateTypeId").toUuid())) {
|
||||
if (!device->hasState(StateTypeId(params.value("stateTypeId").toString()))) {
|
||||
returns.insert("success", false);
|
||||
returns.insert("errorMessage", QString("Device %1 %2 doesn't have such a state.").arg(device->name()).arg(device->id().toString()));
|
||||
return createReply(returns);
|
||||
}
|
||||
QVariant stateValue = device->stateValue(params.value("stateTypeId").toUuid());
|
||||
QVariant stateValue = device->stateValue(StateTypeId(params.value("stateTypeId").toString()));
|
||||
|
||||
returns.insert("success", true);
|
||||
returns.insert("errorMessage", "");
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ LIBS += -L../plugins/deviceplugins/openweathermap -lguh_devicepluginopenweatherm
|
|||
LIBS += -L../plugins/deviceplugins/lircd -lguh_devicepluginlircd
|
||||
|
||||
boblight {
|
||||
LIBS += -L../plugins/deviceplugins/boblight -lguh_devicepluginboblight -L/usr/local/lib/ -lboblight
|
||||
xcompile {
|
||||
LIBS += -L../plugins/deviceplugins/boblight -lguh_devicepluginboblight -lboblight
|
||||
} else {
|
||||
LIBS += -L../plugins/deviceplugins/boblight -lguh_devicepluginboblight -L/usr/local/lib/ -lboblight
|
||||
}
|
||||
DEFINES += USE_BOBLIGHT
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue