mirror of
https://github.com/Fishwaldo/qt-openzwave.git
synced 2025-03-15 19:41:24 +00:00
Implement Button, Raw, BitSet and List setValue variants
This commit is contained in:
parent
b6fdb56eff
commit
9826d80f73
4 changed files with 128 additions and 27 deletions
72
docs/MQTT.md
72
docs/MQTT.md
|
@ -76,24 +76,24 @@ Type: - Enum
|
|||
Description: The Stage of the Interview process of a Node. The Target Stage would be Complete.
|
||||
|
||||
Possible Values:
|
||||
** None ** - Interview Process has not started for this node
|
||||
** ProtocolInfo ** - Obtaining basic Z-Wave Capabilities of this node from the controller
|
||||
** Probe ** - Check if the Node is Alive/Awake
|
||||
** WakeUp ** - Setup Support for Wakeup Queues and Messages
|
||||
** ManufacturerSpecific1 ** - Obtain Manufacturer/Product ID and Type Codes from device
|
||||
** NodeInfo ** - Obtain supported Command Classes from the Node
|
||||
** NodePlusInfo ** - Obtain Z-Wave+ Relvent information if supported by the Node
|
||||
** ManufacturerSpecific2 ** - Obtain Manufacturer/Product ID and Type Codes from device.
|
||||
** Versions ** - Get information about Firmware and CommandClass Versions
|
||||
** Instances ** - Get Details about what instances/channels a device supports
|
||||
** Static ** - Obtain Values from the device that are static/don't change.
|
||||
** CacheLoad ** - Load information from the Cache File. If its a sleeping device, it will stay at this stage until the device wakes up
|
||||
** Associations ** - Refresh Association Groups and Memberships
|
||||
** Neighbors ** - Get the Neighbors List
|
||||
** Session ** - Get infrequently changing values from device
|
||||
** Dynamic ** - Get Frequently changing values from device
|
||||
** Configuration ** - Obtain Configuration Values from the device
|
||||
** Complete ** - Interview Process is Complete.
|
||||
* *None* - Interview Process has not started for this node
|
||||
* *ProtocolInfo* - Obtaining basic Z-Wave Capabilities of this node from the controller
|
||||
* *Probe* - Check if the Node is Alive/Awake
|
||||
* *WakeUp* - Setup Support for Wakeup Queues and Messages
|
||||
* *ManufacturerSpecific1* - Obtain Manufacturer/Product ID and Type Codes from device
|
||||
* *NodeInfo* - Obtain supported Command Classes from the Node
|
||||
* *NodePlusInfo* - Obtain Z-Wave+ Relvent information if supported by the Node
|
||||
* *ManufacturerSpecific2* - Obtain Manufacturer/Product ID and Type Codes from device.
|
||||
* *Versions* - Get information about Firmware and CommandClass Versions
|
||||
* *Instances* - Get Details about what instances/channels a device supports
|
||||
* *Static* - Obtain Values from the device that are static/don't change.
|
||||
* *CacheLoad* - Load information from the Cache File. If its a sleeping device, it will stay at this stage until the device wakes up
|
||||
* *Associations* - Refresh Association Groups and Memberships
|
||||
* *Neighbors* - Get the Neighbors List
|
||||
* *Session* - Get infrequently changing values from device
|
||||
* *Dynamic* - Get Frequently changing values from device
|
||||
* *Configuration* - Obtain Configuration Values from the device
|
||||
* *Complete* - Interview Process is Complete.
|
||||
|
||||
### isListening
|
||||
Type: Bool
|
||||
|
@ -1060,9 +1060,45 @@ See Also:
|
|||
|
||||
## setValue
|
||||
|
||||
This allows a MQTT Client to set a value on a Device. As OZW supports many different types of Values, you must ensure that the payload that you send matches the type of Value you are attempting to change (String, Integer etc)
|
||||
|
||||
**Params**:
|
||||
"ValueIDKey" - the ValueID Key Number of the Value You want ot change
|
||||
|
||||
"Value" - The new Value to Set - Encoded as below:
|
||||
|
||||
BitSet - A Array of Bits you wish to change:
|
||||
```"Value": { [
|
||||
{"Label":"<string label of the BitSet you wish to change>",
|
||||
"Value":<bool>
|
||||
},
|
||||
{"Position":<position of the BitSet you wish to change>,
|
||||
"Value":<bool>
|
||||
}
|
||||
]}```
|
||||
You can specify either Label or Position
|
||||
|
||||
Bool - true/false
|
||||
|
||||
Button - true/false
|
||||
sending "True" simulates a button push, sending false simulates a button release
|
||||
|
||||
Byte/Short/Integer - Decimal value that falls within the range of the type you are changing
|
||||
|
||||
Decimal - Value encoded as a JSON Double
|
||||
|
||||
List - Value is the Position of the entry you wish to select
|
||||
|
||||
Raw - Value is encoded as a Hex String
|
||||
|
||||
String - Value is encoded as a JSON String
|
||||
|
||||
**Returns:**
|
||||
"setValue" - If OZW accepted the command
|
||||
|
||||
**Notification**:
|
||||
|
||||
The Affected ValueID Topic will be updated with the new value if the Device accepted the change.
|
||||
|
||||
**Notes**:
|
||||
|
||||
|
|
|
@ -969,6 +969,7 @@ bool QTOZWManager_Internal::convertValueID(quint64 vidKey) {
|
|||
}
|
||||
case OpenZWave::ValueID::ValueType_Schedule:
|
||||
{
|
||||
qCWarning(manager) << "ValueType_Schedule Not Implemented for convertValueID";
|
||||
this->m_valueModel->setValueData(vidKey, QTOZW_ValueIds::ValueIdColumns::Type, QTOZW_ValueIds::ValueIdTypes::Schedule, true);
|
||||
this->m_valueModel->finishTransaction(vidKey);
|
||||
return true;
|
||||
|
@ -993,14 +994,23 @@ bool QTOZWManager_Internal::convertValueID(quint64 vidKey) {
|
|||
}
|
||||
case OpenZWave::ValueID::ValueType_Button:
|
||||
{
|
||||
bool value;
|
||||
this->m_manager->GetValueAsBool(vid, &value);
|
||||
this->m_valueModel->setValueData(vidKey, QTOZW_ValueIds::ValueIdColumns::Value, QVariant::fromValue(value), true);
|
||||
this->m_valueModel->setValueData(vidKey, QTOZW_ValueIds::ValueIdColumns::Type, QTOZW_ValueIds::ValueIdTypes::Button, true);
|
||||
this->m_valueModel->finishTransaction(vidKey);
|
||||
return true;
|
||||
}
|
||||
case OpenZWave::ValueID::ValueType_Raw:
|
||||
{
|
||||
uint8* rawval;
|
||||
uint8 length; // strangely GetValueAsRaw wants uint8
|
||||
this->m_manager->GetValueAsRaw(vid, &rawval, &length);
|
||||
QByteArray value(value, length);
|
||||
this->m_valueModel->setValueData(vidKey, QTOZW_ValueIds::ValueIdColumns::Value, QVariant::fromValue(value), true);
|
||||
this->m_valueModel->setValueData(vidKey, QTOZW_ValueIds::ValueIdColumns::Type, QTOZW_ValueIds::ValueIdTypes::Raw, true);
|
||||
this->m_valueModel->finishTransaction(vidKey);
|
||||
delete[] rawval;
|
||||
return true;
|
||||
}
|
||||
case OpenZWave::ValueID::ValueType_BitSet:
|
||||
|
@ -1711,12 +1721,13 @@ void QTOZWManager_Internal::pvt_valueModelDataChanged(const QModelIndex &topLeft
|
|||
}
|
||||
case OpenZWave::ValueID::ValueType_Button:
|
||||
{
|
||||
qCWarning(valueModel) << "ValueType_Button TODO";
|
||||
this->m_manager->SetValue(vid, topLeft.data().toBool());
|
||||
return;
|
||||
}
|
||||
case OpenZWave::ValueID::ValueType_Raw:
|
||||
{
|
||||
qCWarning(valueModel) << "ValueType_Raw TODO";
|
||||
QByteArray val = topLeft.data().toByteArray();
|
||||
this->m_manager->SetValue(vid, (uint8 const*)val.data(), val.length());
|
||||
return;
|
||||
}
|
||||
case OpenZWave::ValueID::ValueType_BitSet:
|
||||
|
|
|
@ -212,11 +212,12 @@ bool mqttValueIDModel::encodeValue(rapidjson::Document &value, quint64 vidKey) {
|
|||
break;
|
||||
}
|
||||
case QTOZW_ValueIds::ValueIdTypes::Raw: {
|
||||
qCWarning(ozwmpvalue) << "Raw ValueType not handled in mqttValueIdModel::encodeValue yet";
|
||||
QByteArray ba = data.value<QByteArray>();
|
||||
changed = QT2JS::SetString(value, "Value", ba.toHex());
|
||||
break;
|
||||
}
|
||||
case QTOZW_ValueIds::ValueIdTypes::Schedule: {
|
||||
qCWarning(ozwmpvalue) << "Raw ValueType not handled in mqttValueIdModel::encodeValue yet";
|
||||
qCWarning(ozwmpvalue) << "Schedule ValueType not handled in mqttValueIdModel::encodeValue yet";
|
||||
break;
|
||||
}
|
||||
case QTOZW_ValueIds::ValueIdTypes::Short: {
|
||||
|
|
|
@ -30,8 +30,36 @@ bool MqttCommand_SetValue::processMessage(rapidjson::Document &msg) {
|
|||
QVariant data;
|
||||
switch (types) {
|
||||
case QTOZW_ValueIds::ValueIdTypes::BitSet: {
|
||||
qCWarning(ozwmcsv) << "BitSet Not Done Yet";
|
||||
return false;
|
||||
if (!msg["Value"].IsArray()) {
|
||||
this->sendSimpleStatus(false, QString("Incorrect Field Type for Value: Not Array: ").append(msg["Value"].GetType()));
|
||||
qCWarning(ozwmcsv) << "Incorrect Field Type (Array) for " << GetCommand() << ": Value: " << msg["Value"].GetType();
|
||||
return false;
|
||||
}
|
||||
rapidjson::Value bitsets = msg["Value"].GetArray();
|
||||
QTOZW_ValueIDBitSet bits = this->getValueData(vidKey, QTOZW_ValueIds::ValueIdColumns::Value).value<QTOZW_ValueIDBitSet>();
|
||||
for (rapidjson::SizeType i = 0; i < bitsets.Size(); i++) {
|
||||
qint32 pos = -1;
|
||||
if (bitsets[i].HasMember("Label")) {
|
||||
QString label = bitsets[i]["Label"].GetString();
|
||||
pos = bits.label.key(label, -1);
|
||||
} else if (bitsets[i].HasMember("Position")) {
|
||||
pos = bitsets[i]["Position"].GetUint();
|
||||
} else {
|
||||
this->sendSimpleStatus(false, QString("BitSet Array Does not have a Label or Position Value: "));
|
||||
qCWarning(ozwmcsv) << "BitSet Array does not have a Label or Position Value:" << GetCommand() << ": Value: " << msg["Value"].GetString();
|
||||
return false;
|
||||
}
|
||||
if (pos < 0) {
|
||||
this->sendSimpleStatus(false, QString("BitSet Array Does not have a Valid Label or Position Value: "));
|
||||
qCWarning(ozwmcsv) << "BitSet Array does not have a Valid Label or Position Value:" << GetCommand() << ": Value: " << msg["Value"].GetString();
|
||||
return false;
|
||||
}
|
||||
if (bits.values[pos] != bitsets[i]["Value"].GetBool()) {
|
||||
bits.values.setBit(pos, bitsets[i]["Value"].GetBool());
|
||||
}
|
||||
}
|
||||
data = QVariant::fromValue<QTOZW_ValueIDBitSet>(bits);
|
||||
break;
|
||||
}
|
||||
|
||||
case QTOZW_ValueIds::ValueIdTypes::Bool: {
|
||||
|
@ -89,10 +117,35 @@ bool MqttCommand_SetValue::processMessage(rapidjson::Document &msg) {
|
|||
data = msg["Value"].GetUint();
|
||||
break;
|
||||
}
|
||||
case QTOZW_ValueIds::ValueIdTypes::List:
|
||||
case QTOZW_ValueIds::ValueIdTypes::Raw:
|
||||
case QTOZW_ValueIds::ValueIdTypes::List: {
|
||||
if (!msg["Value"].IsUint()) {
|
||||
this->sendSimpleStatus(false, QString("Incorrect Field Type for Value: Not Integer: ").append(msg["Value"].GetType()));
|
||||
qCWarning(ozwmcsv) << "Incorrect Field Type (Integer) for " << GetCommand() << ": Value: " << msg["Value"].GetType();
|
||||
return false;
|
||||
}
|
||||
QTOZW_ValueIDList list = this->getValueData(vidKey, QTOZW_ValueIds::ValueIdColumns::Value).value<QTOZW_ValueIDList>();
|
||||
int index = list.values.indexOf(msg["Value"].GetUint());
|
||||
if (index < 0) {
|
||||
this->sendSimpleStatus(false, QString("Selected List Value is not in Lists: ").append(msg["Value"].GetUint()));
|
||||
qCWarning(ozwmcsv) << "Selected List Value is Not In List for " << GetCommand() << ": Value: " << msg["Value"].GetUint() << "List:" << list.labels;
|
||||
return false;
|
||||
}
|
||||
list.selectedItem = list.labels[index];
|
||||
data.fromValue<QTOZW_ValueIDList>(list);
|
||||
break;
|
||||
}
|
||||
case QTOZW_ValueIds::ValueIdTypes::Raw: {
|
||||
if (!msg["Value"].IsString()) {
|
||||
this->sendSimpleStatus(false, QString("Incorrect Field Type for Value: Not String: ").append(msg["Value"].GetType()));
|
||||
qCWarning(ozwmcsv) << "Incorrect Field Type (String) for " << GetCommand() << ": Value: " << msg["Value"].GetType();
|
||||
return false;
|
||||
}
|
||||
data = QByteArray::fromHex(msg["Value"].GetString());
|
||||
break;
|
||||
}
|
||||
|
||||
case QTOZW_ValueIds::ValueIdTypes::Schedule: {
|
||||
qCWarning(ozwmcsv) << "List/Raw/Schedule Not Done Yet";
|
||||
qCWarning(ozwmcsv) << "Raw/Schedule Not Done Yet";
|
||||
return false;
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue