Skip to content

Commit e6eb94b

Browse files
authored
Make sensors attr/mode a ResourceItem (dresden-elektronik#7462)
It's a legacy thing for switches which was hard wired to Sensor class. Having it as ResourceItem exposes it to DDF to convert legacy switches without breaking changes.
1 parent 890d6c0 commit e6eb94b

File tree

6 files changed

+37
-10
lines changed

6 files changed

+37
-10
lines changed

devices/generic/items/attr_mode_item.json

+24-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,28 @@
44
"datatype": "UInt32",
55
"access": "RW",
66
"public": true,
7-
"description": "Operational mode."
7+
"description": "Operational mode.",
8+
"default": 1,
9+
"values": [
10+
[
11+
0,
12+
"none"
13+
],
14+
[
15+
1,
16+
"scenes"
17+
],
18+
[
19+
2,
20+
"two_groups"
21+
],
22+
[
23+
3,
24+
"color_temperature"
25+
],
26+
[
27+
4,
28+
"dimmer"
29+
]
30+
]
831
}

resource.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const char *RAttrLastAnnounced = "attr/lastannounced";
6464
const char *RAttrLastSeen = "attr/lastseen";
6565
const char *RAttrLevelMin = "attr/levelmin";
6666
const char *RAttrManufacturerName = "attr/manufacturername";
67+
const char *RAttrMode = "attr/mode";
6768
const char *RAttrModelId = "attr/modelid";
6869
const char *RAttrName = "attr/name";
6970
const char *RAttrNwkAddress = "attr/nwkaddress";
@@ -379,6 +380,7 @@ void initResourceDescriptors()
379380
rItemDescriptors.emplace_back(ResourceItemDescriptor(DataTypeTime, QVariant::String, RAttrLastSeen));
380381
rItemDescriptors.emplace_back(ResourceItemDescriptor(DataTypeUInt8, QVariant::Double, RAttrLevelMin));
381382
rItemDescriptors.emplace_back(ResourceItemDescriptor(DataTypeString, QVariant::String, RAttrManufacturerName));
383+
rItemDescriptors.emplace_back(ResourceItemDescriptor(DataTypeUInt32, QVariant::Double, RAttrMode));
382384
rItemDescriptors.emplace_back(ResourceItemDescriptor(DataTypeString, QVariant::String, RAttrModelId));
383385
rItemDescriptors.emplace_back(ResourceItemDescriptor(DataTypeString, QVariant::String, RAttrName));
384386
rItemDescriptors.emplace_back(ResourceItemDescriptor(DataTypeUInt16, QVariant::Double, RAttrNwkAddress));

resource.h

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ extern const char *RAttrLastAnnounced;
9393
extern const char *RAttrLastSeen;
9494
extern const char *RAttrLevelMin;
9595
extern const char *RAttrManufacturerName;
96+
extern const char *RAttrMode;
9697
extern const char *RAttrModelId;
9798
extern const char *RAttrName;
9899
extern const char *RAttrNwkAddress;

rest_sensors.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -2748,6 +2748,11 @@ bool DeRestPluginPrivate::sensorToMap(const Sensor *sensor, QVariantMap &map, co
27482748
continue; // don't provide reachable for green power devices
27492749
}
27502750

2751+
if (rid.suffix == RAttrMode)
2752+
{
2753+
continue; // handled later on
2754+
}
2755+
27512756
if (strncmp(rid.suffix, "config/", 7) == 0)
27522757
{
27532758
const char *key = item->descriptor().suffix + 7;

sensor.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,14 @@ bool SensorFingerprint::hasOutCluster(quint16 clusterId) const
151151
Sensor::Sensor() :
152152
Resource(RSensors),
153153
m_deletedstate(Sensor::StateNormal),
154-
m_mode(ModeScenes),
155154
m_resetRetryCount(0)
156155
{
157156
durationDue = QDateTime();
158157

159158
// common sensor items
160159
addItem(DataTypeString, RAttrName);
161160
addItem(DataTypeString, RAttrManufacturerName);
161+
addItem(DataTypeUInt32, RAttrMode)->setValue(ModeScenes);
162162
addItem(DataTypeString, RAttrModelId);
163163
addItem(DataTypeString, RAttrType);
164164
addItem(DataTypeString, RAttrSwVersion);
@@ -173,7 +173,7 @@ Sensor::Sensor() :
173173
previousDirection = 0xFF;
174174
previousCt = 0xFFFF;
175175
previousSequenceNumber = 0xFF;
176-
previousCommandId = 0xFF;
176+
previousCommandId = 0xFF;
177177
}
178178

179179
/*! Returns the sensor deleted state.
@@ -222,18 +222,15 @@ void Sensor::setName(const QString &name)
222222
*/
223223
Sensor::SensorMode Sensor::mode() const
224224
{
225-
return m_mode;
225+
return static_cast<Sensor::SensorMode>(item(RAttrMode)->toNumber());
226226
}
227227

228-
/*! Sets the sensor mode (Lighting Switch).
229-
* 1 = Secenes
230-
* 2 = Groups
231-
* 3 = Color Temperature
228+
/*! Sets the sensor mode
232229
\param mode the sensor mode
233230
*/
234231
void Sensor::setMode(SensorMode mode)
235232
{
236-
m_mode = mode;
233+
item(RAttrMode)->setValue(static_cast<qint64>(mode));
237234
}
238235

239236
/*! Returns the sensor type.

sensor.h

-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ class Sensor : public Resource,
155155
private:
156156
DeletedState m_deletedstate;
157157
SensorFingerprint m_fingerPrint;
158-
SensorMode m_mode;
159158
uint8_t m_resetRetryCount;
160159
uint8_t m_zdpResetSeq;
161160
ButtonMapRef m_buttonMapRef{};

0 commit comments

Comments
 (0)