Add initial support for Owon AC201 Thermostat [02]#3423
Add initial support for Owon AC201 Thermostat [02]#3423manup merged 8 commits intodresden-elektronik:masterfrom
Conversation
manup
left a comment
There was a problem hiding this comment.
No errors just a few comments :)
| QString mode_set; | ||
|
|
||
| mode_set = QString("fully closed"); | ||
| if ( mode == 0x01 ) { mode_set = QString("fully closed"); } | ||
| if ( mode == 0x02 ) { mode_set = QString("fully open"); } | ||
| if ( mode == 0x03 ) { mode_set = QString("quarter open"); } | ||
| if ( mode == 0x04 ) { mode_set = QString("half open"); } | ||
| if ( mode == 0x05 ) { mode_set = QString("three quarters open"); } |
There was a problem hiding this comment.
The code has no errors, but for consistency please stick to camelCase — ugly, but well that's Qt style :)
Also use QLatin1String for all static strings, since it as no extra cost, only the pointer and length is stored. QString("abcd") always results in extra allocations on the heap and utf-8 conversion, not dramatic but it piles up.
Since mode has only one value, else if prevents evaluating every statement.
QString modeSet = QLatin1String("fully closed");
if ( mode == 0x01 ) { modeSet = QLatin1String("fully closed"); }
else if ( mode == 0x02 ) { modeSet = QLatin1String("fully open"); }
else if ( mode == 0x03 ) { modeSet = QLatin1String("quarter open"); }
else if ( mode == 0x04 ) { modeSet = QLatin1String("half open"); }
else if ( mode == 0x05 ) { modeSet = QLatin1String("three quarters open"); }
| QDataStream stream(&task.zclFrame.payload(), QIODevice::WriteOnly); | ||
| stream.setByteOrder(QDataStream::LittleEndian); | ||
|
|
||
| stream << (quint16) attrId; |
There was a problem hiding this comment.
Just a note for the future: We don't have a coding style yet, but always use c++ named casts instead old C style casts.
static_cast<quint16>(attrId)
This might seam a bit superfluous at first. But soon the next generation code will get proper types for certain values like ZclAttributeId_t, EndpointId_t, etc to prevent common mistakes.
The named casts help the compiler to figure out invalid type conversions at compile time to prevent accidental errors.
For example:
ZclAttributeId_t attrId(0x0077);
stream << (quint8) attrId; // programmer mistake won't be detected by compiler
stream << static_cast<quint8>(attrId); // compile error no valid conversion from ZclAttributeId_t to quint8
stream << static_cast<quint16>(attrId); // ok
stream << attrId; // ok, because operator<< for QDataStream
So once we have the new types we only need to change the function signature:
addTaskFanControlReadWriteAttribute(TaskItem &task, uint8_t readOrWriteCmd, uint16_t attrId, uint8_t attrType, uint32_t attrValue, uint16_t mfrCode)
to
addTaskFanControlReadWriteAttribute(TaskItem &task, uint8_t readOrWriteCmd, ZclAttributeId_t attrId, ZclDatatypeId_t attrType, uint32_t attrValue, ZclManufacturerCode_t mfrCode)
If we already use C++ named casts we get a hole lot of error checking without needing to rewrite all those C style casts, searching for them is also quite hard/impossible.
fan_control.cppto accomodate AC fan control for thermostatsRConfigFanModeto set AC fan modeRConfigSwingModeto set AC louvers position