add ruleRelevant flag for statetypes and eventtypes

This commit is contained in:
Simon Stürz 2016-05-16 19:47:27 +02:00 committed by Michael Zanetti
parent c160e5ba7d
commit a05b9ad1cb
10 changed files with 102 additions and 36 deletions

View File

@ -204,15 +204,15 @@
\li \e pushButton \unicode{0x2192} \l{DeviceClass::SetupMethodPushButton}
\endlist
\note For more information please take a look at \l{CreateMethods and SetupMethods} documentation.
\li - \underline{\e pairingInfo:} The \l{DeviceClass::pairingInfo()}{pairingInfo} will inform the user how to pair the device \unicode{0x2192} \l{DeviceClass::setupMethod()}. This parameter will only be used for \l{DeviceClass::SetupMethodDisplayPin}{DisplayPin} and \l{DeviceClass::SetupMethodEnterPin}{EnterPin} and \l{DeviceClass::SetupMethodPushButton}{PushButton}. Example: "Please press the button on the device before continue."
\li - \underline{\e pairingInfo:} Optional: The \l{DeviceClass::pairingInfo()}{pairingInfo} will inform the user how to pair the device \unicode{0x2192} \l{DeviceClass::setupMethod()}. This parameter will only be used for \l{DeviceClass::SetupMethodDisplayPin}{DisplayPin} and \l{DeviceClass::SetupMethodEnterPin}{EnterPin} and \l{DeviceClass::SetupMethodPushButton}{PushButton}. Example: "Please press the button on the device before continue."
\li - \underline{\e criticalStateTypeId:} Optional: Define which \l{StateType} is critical for this \l{Device}. The given \l{StateTypeId} sould refer to a \tt{bool} \l{State} which enables / disables the whole \l{Device} i.e. \e{"connected"}, \e{"available"} or \e{"reachable"}. This allowes a client developer to disable the device until this \l{State} becomes true.
\li - \underline{\e primaryStateTypeId:} Optional: Define which \l{StateType} is the primary \l{State} for this \l{Device}. This allowes a client developer to place the primary \l{State} value in the device overview.
\li - \underline{\e primaryActionTypeId:} Optional: Define which \l{ActionType} is the primary \l{Action} for this \l{Device}. This allowes a client developer to place the primary \l{Action} element in the device overview.
\li - \underline{\e discoveryParamTypes:} A list of \l{ParamType}{ParamTypes} which will be needed for discovering a device \unicode{0x2192} \l{DeviceClass::discoveryParamTypes()}. This parameter will only be used for devices with the \l{DeviceClass::CreateMethodDiscovery}{CreateMethodDiscovery} (see section "\l{The ParamType definition}").
\li - \underline{\e discoveryParamTypes:} Optional: A list of \l{ParamType}{ParamTypes} which will be needed for discovering a device \unicode{0x2192} \l{DeviceClass::discoveryParamTypes()}. This parameter will only be used for devices with the \l{DeviceClass::CreateMethodDiscovery}{CreateMethodDiscovery} (see section "\l{The ParamType definition}").
\li - \underline{\e paramTypes:} A list of \l{ParamType}{ParamTypes} which define the paramters of a device \unicode{0x2192} \l{DeviceClass::paramTypes()} (see section "\l{The ParamType definition}").
\li - \underline{\e stateTypes:} A list of \l{StateType}{StateTypes} of the device \unicode{0x2192} \l{DeviceClass::stateTypes()} (see section "\l{The StateType definition}").
\li - \underline{\e actionTypes:} A list of \l{ActionType}{ActionTypes} of the device \unicode{0x2192} \l{DeviceClass::actionTypes()} (see section "\l{The ActionType definition}").
\li - \underline{\e eventTypes:} A list of \l{EventType}{EventTypes} of the device \unicode{0x2192} \l{DeviceClass::eventTypes()} (see section "\l{The EventType definition}").
\li - \underline{\e stateTypes:} Optional: A list of \l{StateType}{StateTypes} of the device \unicode{0x2192} \l{DeviceClass::stateTypes()} (see section "\l{The StateType definition}").
\li - \underline{\e actionTypes:} Optional: A list of \l{ActionType}{ActionTypes} of the device \unicode{0x2192} \l{DeviceClass::actionTypes()} (see section "\l{The ActionType definition}").
\li - \underline{\e eventTypes:} Optional: A list of \l{EventType}{EventTypes} of the device \unicode{0x2192} \l{DeviceClass::eventTypes()} (see section "\l{The EventType definition}").
\endlist
@ -284,6 +284,7 @@ A \l{StateType} has following parameters:
"name": "name of the state",
"id": "uuid",
"idName": "stateName",
"index": "int",
"type": "DataType",
"unit": "The unit of the state value.",
"defaultValue": "The state will be initialized with this value."
@ -302,11 +303,12 @@ A \l{StateType} has following parameters:
\li - \underline{\e name:} The visible name of the \l{ParamType} \unicode{0x2192} \l{ParamType::name()}.
\li - \underline{\e idName:} This parameter will be used to define the StateTypeId variable named <idName>StateTypeId in the plugininfo.h, so it can be used in the code.
\li - \underline{\e id:} The actual uuid (\l{StateTypeId}) of the \l{StateType} \unicode{0x2192} \l{StateType::id()}.
\li - \underline{\e index:} The order index of the \l{StateType} \unicode{0x2192} \l{StateType::index()}. This index will be used for sorting the \l{State}{States} of a \l{Device} to make sure the types looks the same on all clients. Please make sure all \l{StateType}{StateTypes} together will create a list from \tt 0 to \tt x.
\li - \underline{\e type:} The data type of this state \unicode{0x2192} \l{StateType::type()}.
\li - \underline{\e unit:} With this parameter you can specify the unit of the state value i.e. \unicode{0x00B0}C \unicode{0x2192} DegreeCelsius (\l{Types::Unit}).
\li - \underline{\e possibleValues:} Gives you the possibility to define a list of possible values which this state can have. This allowes a user to create a rule based on a state and define only values which are possible. This is typically used for strings i.e. ["Loading", "Installing", "Removing"].
\li - \underline{\e unit:} Optional: With this parameter you can specify the unit of the state value i.e. \unicode{0x00B0}C \unicode{0x2192} DegreeCelsius (\l{Types::Unit}).
\li - \underline{\e defaultValue:} The state will be initialized with this value.
\li - \underline{\e writable:} If you define the "\e writable : true" value an \l{ActionType} will be created to set the \l{State} value. The created \l{ActionType} has the same uuid (\l{ActionTypeId}) like the \l{StateType} uuid and will be named "set <stateName>". The \l{ParamType} of the created \l{ActionType} will have the same values in the \e allowedValues list as the \l{StateType} in the \e possibleValues list. Also the \e minValue / \e maxValue will be taken over from the \l{StateType}.
\li - \underline{\e possibleValues:} Optional: Gives you the possibility to define a list of possible values which this state can have. This allowes a user to create a rule based on a state and define only values which are possible. This is typically used for strings i.e. ["Loading", "Installing", "Removing"].
\li - \underline{\e writable:} Optional: If you define the "\e writable : true" value an \l{ActionType} will be created to set the \l{State} value. The created \l{ActionType} has the same uuid (\l{ActionTypeId}) like the \l{StateType} uuid and will be named "set <stateName>". The \l{ParamType} of the created \l{ActionType} will have the same values in the \e allowedValues list as the \l{StateType} in the \e possibleValues list. Also the \e minValue / \e maxValue will be taken over from the \l{StateType}.
If a \l{StateType} has the property \e writable the \l{DeviceManager} will create automatically an \l{ActionType} for this state, which will also have exactly one \l{Param} with the same properties like the \l{StateType}. The created \l{ActionType} has the same uuid (\l{ActionTypeId}) like the \l{StateType} uuid and will be named "set <stateName>".
@ -323,6 +325,7 @@ This mechanism was created to ensure that the \l{EventType} and \l{ActionType} w
"idName": "volume",
"name": "volume",
"unit": "Percentage",
"index": "0",
"type": "int",
"minValue": 0,
"maxValue": 100,
@ -339,6 +342,7 @@ This mechanism was created to ensure that the \l{EventType} and \l{ActionType} w
{
"name": "volume",
"type": "int",
"index": 0,
"maxValue": 100,
"minValue": 0,
"unit": "Percentage"
@ -352,9 +356,11 @@ This mechanism was created to ensure that the \l{EventType} and \l{ActionType} w
{
"id": "{9dfe5d78-4c3f-497c-bab1-bb9fdf7e93a9}",
"name": "volume changed",
"index": 0,
"paramTypes": [
{
"name": "volume",
"index": 0,
"type": "int"
}
]
@ -387,7 +393,7 @@ This mechanism was created to ensure that the \l{EventType} and \l{ActionType} w
\li - \underline{\e idName:} This parameter will be used to define the ActionTypeId variable named <idName>ActionTypeId in the plugininfo.h, so it can be used in the code.
\li - \underline{\e id:} The actual uuid (\l{ActionTypeId}) of the \l{ActionType} \unicode{0x2192} \l{ActionType::id()}.
\li - \underline{\e index:} The order index of the \l{ActionType} \unicode{0x2192} \l{ActionType::index()}. This index will be used for sorting the \l{Action}{Actions} of a \l{Device} to make sure the \l{Device} looks the same on all clients. Please make sure all \l{ActionType}{ActionTypes} together will create a list from \tt 0 to \tt x.
\li - \underline{\e paramTypes:} A list of \l{ParamType}{ParamTypes} (see section "\l{The ParamType definition}") for this \l{ActionType}. This parameter is optional. You can also create an \l{ActionType} which has no \l{ParamType}{ParamTypes}.
\li - \underline{\e paramTypes:} Optional: A list of \l{ParamType}{ParamTypes} (see section "\l{The ParamType definition}") for this \l{ActionType}. This parameter is optional. You can also create an \l{ActionType} which has no \l{ParamType}{ParamTypes}.
\endlist
\section2 The EventType definition
@ -415,7 +421,7 @@ This mechanism was created to ensure that the \l{EventType} and \l{ActionType} w
\li - \underline{\e idName:} This parameter will be used to define the EventTypeId variable named <idName>EventTypeId in the plugininfo.h, so it can be used in the code.
\li - \underline{\e id:} The actual uuid (\l{EventTypeId}) of the \l{EventType} \unicode{0x2192} \l{EventType::id()}.
\li - \underline{\e index:} The order index of the \l{EventType} \unicode{0x2192} \l{EventType::index()}. This index will be used for sorting the \l{Event}{Events} of a \l{Device} to make sure the \l{Device} looks the same on all clients. Please make sure all \l{EventType}{EventTypes} together will create a list from \tt 0 to \tt x.
\li - \underline{\e paramTypes:} A list of \l{ParamType}{ParamTypes} (see section "\l{The ParamType definition}") for this \l{EventType}. This parameter is optional. You can also create an \l{EventType} which has no \l{ParamType}{ParamTypes}.
\li - \underline{\e paramTypes:} Optional: A list of \l{ParamType}{ParamTypes} (see section "\l{The ParamType definition}") for this \l{EventType}. This parameter is optional. You can also create an \l{EventType} which has no \l{ParamType}{ParamTypes}.
\endlist
*/

View File

@ -289,6 +289,8 @@ QList<StateType> DeviceClass::stateTypes() const
return m_stateTypes;
}
/*! Returns the \l{StateType} with the given \a stateTypeId of this \l{DeviceClass}.
* If there is no matching \l{StateType}, an invalid \l{StateType} will be returned.*/
StateType DeviceClass::getStateType(const StateTypeId &stateTypeId)
{
foreach (const StateType &stateType, m_stateTypes) {
@ -303,15 +305,6 @@ StateType DeviceClass::getStateType(const StateTypeId &stateTypeId)
void DeviceClass::setStateTypes(const QList<StateType> &stateTypes)
{
m_stateTypes = stateTypes;
m_allEventTypes = m_eventTypes;
foreach (const StateType &stateType, m_stateTypes) {
EventType eventType(EventTypeId(stateType.id().toString()));
eventType.setName(QString("%1 changed").arg(stateType.name()));
ParamType paramType("value", stateType.type());
eventType.setParamTypes(QList<ParamType>() << paramType);
m_allEventTypes.append(eventType);
}
}
/*! Returns true if this DeviceClass has a \l{StateType} with the given \a stateTypeId. */
@ -329,7 +322,7 @@ bool DeviceClass::hasStateType(const StateTypeId &stateTypeId)
from this \l{DeviceClass} must have their events matching to this template. */
QList<EventType> DeviceClass::eventTypes() const
{
return m_allEventTypes;
return m_eventTypes;
}
/*! Set the \a eventTypes of this DeviceClass. \{Device}{Devices} created
@ -337,15 +330,6 @@ QList<EventType> DeviceClass::eventTypes() const
void DeviceClass::setEventTypes(const QList<EventType> &eventTypes)
{
m_eventTypes = eventTypes;
m_allEventTypes = m_eventTypes;
foreach (const StateType &stateType, m_stateTypes) {
EventType eventType(EventTypeId(stateType.id().toString()));
eventType.setName(QString("%1 changed").arg(stateType.name()));
ParamType paramType("value", stateType.type());
eventType.setParamTypes(QList<ParamType>() << paramType);
m_allEventTypes.append(eventType);
}
}
/*! Returns true if this DeviceClass has a \l{EventType} with the given \a eventTypeId. */

View File

@ -182,7 +182,6 @@ private:
QList<BasicTag> m_basicTags;
QList<StateType> m_stateTypes;
QList<EventType> m_eventTypes;
QList<EventType> m_allEventTypes;
QList<ActionType> m_actionTypes;
QList<ParamType> m_paramTypes;
QList<ParamType> m_discoveryParamTypes;

View File

@ -257,9 +257,11 @@ QList<DeviceClass> DevicePlugin::supportedDevices() const
}
deviceClass.setBasicTags(basicTags);
// State Types
QList<ActionType> actionTypes;
QList<StateType> stateTypes;
QList<EventType> eventTypes;
// StateTypes
foreach (const QJsonValue &stateTypesJson, jo.value("stateTypes").toArray()) {
QJsonObject st = stateTypesJson.toObject();
QStringList missingFields = verifyFields(QStringList() << "type" << "id" << "name" << "index" << "defaultValue", st);
@ -288,6 +290,9 @@ QList<DeviceClass> DevicePlugin::supportedDevices() const
if (st.contains("maxValue"))
stateType.setMaxValue(st.value("maxValue").toVariant());
if (st.contains("ruleRelevant"))
stateType.setRuleRelevant(st.value("ruleRelevant").toBool());
if (st.contains("possibleValues")) {
QVariantList possibleValues;
foreach (const QJsonValue &possibleValueJson, st.value("possibleValues").toArray()) {
@ -304,6 +309,17 @@ QList<DeviceClass> DevicePlugin::supportedDevices() const
}
stateTypes.append(stateType);
// Events for state changed
EventType eventType(EventTypeId(stateType.id().toString()));
if (st.contains("eventRuleRelevant"))
eventType.setRuleRelevant(st.value("eventRuleRelevant").toBool());
eventType.setName(QString("%1 changed").arg(stateType.name()));
ParamType paramType("value", stateType.type());
eventType.setParamTypes(QList<ParamType>() << paramType);
eventType.setIndex(stateType.index());
eventTypes.append(eventType);
// ActionTypes for writeable StateTypes
if (st.contains("writable") && st.value("writable").toBool()) {
// Note: fields already checked in StateType
@ -346,7 +362,6 @@ QList<DeviceClass> DevicePlugin::supportedDevices() const
deviceClass.setActionTypes(actionTypes);
// EventTypes
QList<EventType> eventTypes;
foreach (const QJsonValue &eventTypesJson, jo.value("eventTypes").toArray()) {
QJsonObject et = eventTypesJson.toObject();
QStringList missingFields = verifyFields(QStringList() << "id" << "name" << "index", et);
@ -359,6 +374,8 @@ QList<DeviceClass> DevicePlugin::supportedDevices() const
EventType eventType(et.value("id").toString());
eventType.setName(et.value("name").toString());
eventType.setIndex(et.value("index").toInt());
if (et.contains("ruleRelevant"))
eventType.setRuleRelevant(et.value("ruleRelevant").toBool());
QPair<bool, QList<ParamType> > paramVerification = parseParamTypes(et.value("paramTypes").toArray());
if (!paramVerification.first) {
@ -367,7 +384,6 @@ QList<DeviceClass> DevicePlugin::supportedDevices() const
} else {
eventType.setParamTypes(paramVerification.second);
}
eventTypes.append(eventType);
}
deviceClass.setEventTypes(eventTypes);

View File

@ -34,7 +34,8 @@
/*! Constructs a EventType object with the given \a id. */
EventType::EventType(const EventTypeId &id):
m_id(id),
m_index(0)
m_index(0),
m_ruleRelevant(true)
{
}
@ -83,3 +84,15 @@ void EventType::setParamTypes(const QList<ParamType> &paramTypes)
{
m_paramTypes = paramTypes;
}
/*! Returns true if this EventType is relevant for the rule from a user perspective. */
bool EventType::ruleRelevant() const
{
return m_ruleRelevant;
}
/*! Sets this EventType relevant for the rule from a user perspective to \a ruleRelevant. */
void EventType::setRuleRelevant(const bool &ruleRelevant)
{
m_ruleRelevant = ruleRelevant;
}

View File

@ -44,12 +44,15 @@ public:
QList<ParamType> paramTypes() const;
void setParamTypes(const QList<ParamType> &paramTypes);
bool ruleRelevant() const;
void setRuleRelevant(const bool &ruleRelevant);
private:
EventTypeId m_id;
QString m_name;
int m_index;
QList<ParamType> m_paramTypes;
bool m_ruleRelevant;
};
#endif // TRIGGERTYPE_H

View File

@ -41,7 +41,8 @@ StateType::StateType(const StateTypeId &id):
m_minValue(QVariant()),
m_maxValue(QVariant()),
m_possibleValues(QVariantList()),
m_unit(Types::UnitNone)
m_unit(Types::UnitNone),
m_ruleRelevant(true)
{
}
@ -150,3 +151,15 @@ void StateType::setUnit(const Types::Unit &unit)
{
m_unit = unit;
}
/*! Returns true if this StateType is relevant for the rule from a user perspective. */
bool StateType::ruleRelevant() const
{
return m_ruleRelevant;
}
/*! Sets this StateType relevant for the rule from a user perspective to \a ruleRelevant. */
void StateType::setRuleRelevant(const bool &ruleRelevant)
{
m_ruleRelevant = ruleRelevant;
}

View File

@ -58,6 +58,9 @@ public:
Types::Unit unit() const;
void setUnit(const Types::Unit &unit);
bool ruleRelevant() const;
void setRuleRelevant(const bool &ruleRelevant);
private:
StateTypeId m_id;
QString m_name;
@ -68,6 +71,7 @@ private:
QVariant m_maxValue;
QVariantList m_possibleValues;
Types::Unit m_unit;
bool m_ruleRelevant;
};
#endif // STATETYPE_H

View File

@ -26,6 +26,8 @@
"name": "timezone",
"index": 0,
"type": "QString",
"ruleRelevant": false,
"eventRuleRelevant": false,
"defaultValue": "-"
},
{
@ -34,6 +36,8 @@
"name": "city",
"index": 1,
"type": "QString",
"ruleRelevant": false,
"eventRuleRelevant": false,
"defaultValue": "-"
},
{
@ -42,6 +46,8 @@
"name": "country",
"index": 2,
"type": "QString",
"ruleRelevant": false,
"eventRuleRelevant": false,
"defaultValue": "-"
},
{
@ -51,6 +57,7 @@
"index": 3,
"type": "int",
"defaultValue": 1,
"eventRuleRelevant": false,
"minValue": 1,
"maxValue": 31
},
@ -61,6 +68,7 @@
"index": 4,
"type": "int",
"defaultValue": 1,
"eventRuleRelevant": false,
"minValue": 1,
"maxValue": 12
},
@ -69,6 +77,8 @@
"idName": "monthName",
"name": "month name",
"index": 5,
"ruleRelevant": false,
"eventRuleRelevant": false,
"type": "QString",
"defaultValue": "-"
},
@ -77,6 +87,7 @@
"idName": "year",
"name": "year",
"index": 6,
"eventRuleRelevant": false,
"type": "int",
"defaultValue": "1970"
},
@ -86,6 +97,7 @@
"name": "weekday",
"type": "int",
"index": 7,
"eventRuleRelevant": false,
"defaultValue": 1,
"minValue": 1,
"maxValue": 7
@ -94,6 +106,8 @@
"id": "f627d052-cee6-4727-b9c6-0e935d41e04a",
"idName": "weekdayName",
"name": "weekday name",
"ruleRelevant": false,
"eventRuleRelevant": false,
"index": 8,
"type": "QString",
"defaultValue": "-"
@ -104,6 +118,7 @@
"name": "weekend",
"index": 9,
"type": "bool",
"eventRuleRelevant": false,
"defaultValue": false
},
{
@ -113,6 +128,7 @@
"index": 10,
"unit": "UnixTime",
"type": "int",
"eventRuleRelevant": false,
"defaultValue": 0
},
{
@ -122,6 +138,7 @@
"index": 11,
"unit": "UnixTime",
"type": "int",
"eventRuleRelevant": false,
"defaultValue": 0
},
{
@ -131,6 +148,7 @@
"index": 12,
"unit": "UnixTime",
"type": "int",
"eventRuleRelevant": false,
"defaultValue": 0
},
{
@ -140,6 +158,7 @@
"index": 13,
"unit": "UnixTime",
"type": "int",
"eventRuleRelevant": false,
"defaultValue": 0
},
{
@ -149,6 +168,7 @@
"index": 14,
"unit": "UnixTime",
"type": "int",
"eventRuleRelevant": false,
"defaultValue": 0
}
],

View File

@ -171,6 +171,7 @@ void JsonTypes::init()
s_stateType.insert("index", basicTypeToString(Int));
s_stateType.insert("defaultValue", basicTypeToString(Variant));
s_stateType.insert("o:unit", unitRef());
s_stateType.insert("o:ruleRelevant", basicTypeToString(Bool));
s_stateType.insert("o:minValue", basicTypeToString(Variant));
s_stateType.insert("o:maxValue", basicTypeToString(Variant));
s_stateType.insert("o:possibleValues", QVariantList() << basicTypeToString(Variant));
@ -196,6 +197,7 @@ void JsonTypes::init()
s_eventType.insert("name", basicTypeToString(String));
s_eventType.insert("index", basicTypeToString(Int));
s_eventType.insert("paramTypes", QVariantList() << paramTypeRef());
s_eventType.insert("o:ruleRelevant", basicTypeToString(Bool));
// Event
s_event.insert("eventTypeId", basicTypeToString(Uuid));
@ -392,6 +394,9 @@ QVariantMap JsonTypes::packEventType(const EventType &eventType)
variant.insert("id", eventType.id());
variant.insert("name", eventType.name());
variant.insert("index", eventType.index());
if (!eventType.ruleRelevant())
variant.insert("ruleRelevant", false);
QVariantList paramTypes;
foreach (const ParamType &paramType, eventType.paramTypes()) {
paramTypes.append(packParamType(paramType));
@ -505,6 +510,9 @@ QVariantMap JsonTypes::packStateType(const StateType &stateType)
variantMap.insert("type", basicTypeToString(stateType.type()));
variantMap.insert("defaultValue", stateType.defaultValue());
if (!stateType.ruleRelevant())
variantMap.insert("ruleRelevant", false);
if (stateType.maxValue().isValid())
variantMap.insert("maxValue", stateType.maxValue());