Skip to content

Commit 5fbc6be

Browse files
authored
Merge pull request dresden-elektronik#5359 from manup/ddf_descr_1
DDF add more sub device descriptions and provide sort order for them
2 parents 7110994 + f593953 commit 5fbc6be

35 files changed

+353
-6
lines changed

de_web_plugin.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17812,6 +17812,18 @@ void DeRestPluginPrivate::pushSensorInfoToCore(Sensor *sensor)
1781217812

1781317813
Q_Q(DeRestPlugin);
1781417814

17815+
bool isMainSubDevice = false;
17816+
Device *device = static_cast<Device*>(sensor->parentResource());
17817+
17818+
if (device)
17819+
{
17820+
const auto &subs = device->subDevices();
17821+
if (!subs.empty() && subs.front() == sensor)
17822+
{
17823+
isMainSubDevice = true;
17824+
}
17825+
}
17826+
1781517827
if (sensor->modelId().startsWith(QLatin1String("FLS-NB")))
1781617828
{ } // use name from light
1781717829
else if (sensor->modelId().startsWith(QLatin1String("D1")) || sensor->modelId().startsWith(QLatin1String("S1")) ||
@@ -17823,19 +17835,19 @@ void DeRestPluginPrivate::pushSensorInfoToCore(Sensor *sensor)
1782317835
{ } // use name from ZHAPresence sensor only
1782417836
else if (sensor->modelId() == QLatin1String("WarningDevice") && sensor->type() == QLatin1String("ZHAAlarm"))
1782517837
{ } // use name from light
17826-
else if (!sensor->name().isEmpty())
17838+
else if (!sensor->name().isEmpty() || isMainSubDevice)
1782717839
{
17828-
q->nodeUpdated(sensor->address().ext(), QLatin1String("name"), sensor->name());
17840+
emit q->nodeUpdated(sensor->address().ext(), QLatin1String("name"), sensor->name());
1782917841
}
1783017842

1783117843
if (!sensor->modelId().isEmpty())
1783217844
{
17833-
q->nodeUpdated(sensor->address().ext(), QLatin1String("modelid"), sensor->modelId());
17845+
emit q->nodeUpdated(sensor->address().ext(), QLatin1String("modelid"), sensor->modelId());
1783417846
}
1783517847

1783617848
if (!sensor->manufacturer().isEmpty())
1783717849
{
17838-
q->nodeUpdated(sensor->address().ext(), QLatin1String("vendor"), sensor->manufacturer());
17850+
emit q->nodeUpdated(sensor->address().ext(), QLatin1String("vendor"), sensor->manufacturer());
1783917851
}
1784017852

1784117853
if (!sensor->swVersion().isEmpty())

device.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,6 +1564,13 @@ void Device::addSubDevice(Resource *sub)
15641564
{
15651565
hnd = sub->handle();
15661566
DEV_CheckReachable(this);
1567+
1568+
std::sort(d->subResourceHandles.begin(), d->subResourceHandles.end(), [](const auto &a, const auto &b)
1569+
{
1570+
if (a.order == 0) { return false; }
1571+
return a.order < b.order;
1572+
});
1573+
15671574
return;
15681575
}
15691576
}

device_descriptions.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,9 @@ static DDF_SubDeviceDescriptor DDF_ReadSubDeviceFile(const QString &path)
14891489
{
14901490
result.restApi = obj.value(QLatin1String("restapi")).toString();
14911491
}
1492+
1493+
result.order = obj.value(QLatin1String("order")).toInt(SUBDEVICE_DEFAULT_ORDER);
1494+
14921495
if (obj.contains(QLatin1String("uuid")))
14931496
{
14941497
const auto uniqueId = obj.value(QLatin1String("uuid"));
@@ -1678,3 +1681,28 @@ static DeviceDescription DDF_MergeGenericItems(const std::vector<DeviceDescripti
16781681

16791682
return result;
16801683
}
1684+
1685+
uint8_t DDF_GetSubDeviceOrder(const QString &type)
1686+
{
1687+
if (type.isEmpty() || type.startsWith(QLatin1String("CLIP")))
1688+
{
1689+
return SUBDEVICE_DEFAULT_ORDER;
1690+
}
1691+
1692+
if (_priv)
1693+
{
1694+
auto i = std::find_if(_priv->subDevices.cbegin(), _priv->subDevices.cend(), [&](const auto &sub)
1695+
{ return sub.name == type; });
1696+
1697+
if (i != _priv->subDevices.cend())
1698+
{
1699+
return i->order;
1700+
}
1701+
}
1702+
1703+
#ifdef QT_DEBUG
1704+
DBG_Printf(DBG_DDF, "DDF: No subdevice for type: %s\n", qPrintable(type));
1705+
#endif
1706+
1707+
return SUBDEVICE_DEFAULT_ORDER;
1708+
}

device_descriptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "resource.h"
1717
#include "sensor.h"
1818

19+
#define SUBDEVICE_DEFAULT_ORDER 200
20+
1921
class Event;
2022

2123
class DDF_ZclReport
@@ -186,6 +188,7 @@ class DDF_SubDeviceDescriptor
186188
QString restApi;
187189
QStringList uniqueId;
188190
std::vector<const char*> items; // RAttrName, etc.
191+
int order;
189192
};
190193

191194
inline bool isValid(const DDF_SubDeviceDescriptor &sub)

devices/generic/constants.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@
1515
"$TYPE_BATTERY_SENSOR": "ZHABattery",
1616
"$TYPE_COLOR_TEMPERATURE_LIGHT": "Color temperature light",
1717
"$TYPE_COLOR_LIGHT": "Color light",
18+
"$TYPE_COLOR_DIMMABLE_LIGHT": "Color dimmable light",
1819
"$TYPE_DIMMABLE_LIGHT": "Dimmable light",
20+
"$TYPE_DIMMABLE_PLUGIN_UNIT": "Dimmable plug-in unit",
1921
"$TYPE_EXTENDED_COLOR_LIGHT": "Extended color light",
2022
"$TYPE_SMART_PLUG": "Smart plug",
23+
"$TYPE_ON_OFF_LIGHT": "On/Off light",
2124
"$TYPE_ON_OFF_PLUGIN_UNIT": "On/Off plug-in unit",
25+
"$TYPE_ON_OFF_OUTPUT": "On/Off output",
2226
"$TYPE_RANGE_EXTENDER": "Range extender",
2327
"$TYPE_AIR_QUALITY_SENSOR": "ZHAAirQuality",
2428
"$TYPE_CONSUMPTION_SENSOR": "ZHAConsumption",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"schema": "resourceitem1.schema.json",
3+
"id": "config/heatsetpoint",
4+
"datatype": "Int16",
5+
"access": "RW",
6+
"public": true,
7+
"default": 0,
8+
"description": "Target temperature of a thermostat.",
9+
"range": [500, 3200]
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"schema": "resourceitem1.schema.json",
3+
"id": "config/mode",
4+
"datatype": "String",
5+
"access": "RW",
6+
"public": true,
7+
"description": "Mode of the device."
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"schema": "resourceitem1.schema.json",
3+
"id": "state/airquality",
4+
"datatype": "String",
5+
"access": "R",
6+
"public": true,
7+
"description": "Text representation of the air quality."
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"schema": "resourceitem1.schema.json",
3+
"id": "state/airqualityppb",
4+
"datatype": "UInt16",
5+
"access": "R",
6+
"public": true,
7+
"description": "Measured air quality in PPB."
8+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"schema": "subdevice1.schema.json",
3+
"type": "$TYPE_AIR_QUALITY_SENSOR",
4+
"name": "ZHAAirQuality",
5+
"restapi": "/sensors",
6+
"order": 20,
7+
"uuid": ["$address.ext", "0x01", "0x0000"],
8+
"items": [
9+
"config/on",
10+
"config/reachable",
11+
"state/airquality",
12+
"state/airqualityppb",
13+
"state/lastupdated"
14+
]
15+
}

devices/generic/subdevices/battery_sensor.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"type": "$TYPE_BATTERY_SENSOR",
44
"name": "ZHABattery",
55
"restapi": "/sensors",
6+
"order": 30,
67
"uuid": ["$address.ext", "0x01", "0x0001"],
78
"items": [
89
"config/on",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"schema": "subdevice1.schema.json",
3+
"type": "$TYPE_COLOR_DIMMABLE_LIGHT",
4+
"name": "Color dimmable light",
5+
"restapi": "/lights",
6+
"order": 10,
7+
"uuid": ["$address.ext", "0x01"],
8+
"items": [
9+
"config/colorcapabilities",
10+
"state/alert",
11+
"state/bri",
12+
"state/colormode",
13+
"state/effect",
14+
"state/hue",
15+
"state/on",
16+
"state/reachable",
17+
"state/sat",
18+
"state/x",
19+
"state/y"
20+
]
21+
}

devices/generic/subdevices/color_temperature_light.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"type": "$TYPE_COLOR_TEMPERATURE_LIGHT",
44
"name": "Color temperature light",
55
"restapi": "/lights",
6+
"order": 11,
67
"uuid": ["$address.ext", "0x01"],
78
"items": [
89
"config/ctmax",

devices/generic/subdevices/consumption_sensor.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"type": "$TYPE_CONSUMPTION_SENSOR",
44
"name": "ZHAConsumption",
55
"restapi": "/sensors",
6+
"order": 22,
67
"uuid": ["$address.ext", "0x01", "0x0702"],
78
"items": [
89
"config/on",

devices/generic/subdevices/dimmable_light.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"type": "$TYPE_DIMMABLE_LIGHT",
44
"name": "Dimmable light",
55
"restapi": "/lights",
6+
"order": 11,
67
"uuid": ["$address.ext", "0x01"],
78
"items": [
89
"state/alert",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"schema": "subdevice1.schema.json",
3+
"type": "$TYPE_DIMMABLE_PLUGIN_UNIT",
4+
"name": "Dimmable plug-in unit",
5+
"restapi": "/lights",
6+
"order": 11,
7+
"uuid": ["$address.ext", "0x01"],
8+
"items": [
9+
"state/bri",
10+
"state/reachable",
11+
"state/on"
12+
]
13+
}

devices/generic/subdevices/extended_color_light.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"type": "$TYPE_EXTENDED_COLOR_LIGHT",
44
"name": "Extended color light",
55
"restapi": "/lights",
6+
"order": 10,
67
"uuid": ["$address.ext", "0x01"],
78
"items": [
89
"config/ctmax",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"schema": "subdevice1.schema.json",
3+
"type": "$TYPE_FIRE_SENSOR",
4+
"name": "ZHAFire",
5+
"restapi": "/sensors",
6+
"order": 20,
7+
"uuid": ["$address.ext", "0x01", "0x0500"],
8+
"items": [
9+
"config/on",
10+
"config/reachable",
11+
"state/fire",
12+
"state/lastupdated"
13+
]
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"schema": "subdevice1.schema.json",
3+
"type": "$TYPE_HUMIDITY_SENSOR",
4+
"name": "ZHAHumidity",
5+
"restapi": "/sensors",
6+
"order": 23,
7+
"uuid": ["$address.ext", "0x01", "0x0405"],
8+
"items": [
9+
"config/on",
10+
"config/offset",
11+
"config/reachable",
12+
"state/humidity",
13+
"state/lastupdated"
14+
]
15+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"schema": "subdevice1.schema.json",
3+
"type": "$TYPE_LIGHT_LEVEL_SENSOR",
4+
"name": "ZHALightLevel",
5+
"restapi": "/sensors",
6+
"order": 22,
7+
"uuid": ["$address.ext", "0x01", "0x0400"],
8+
"items": [
9+
"config/on",
10+
"config/reachable",
11+
"config/tholddark",
12+
"config/tholdoffset",
13+
"state/dark",
14+
"state/daylight",
15+
"state/lightlevel",
16+
"state/lux",
17+
"state/lastupdated"
18+
]
19+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"schema": "subdevice1.schema.json",
3+
"type": "$TYPE_ON_OFF_LIGHT",
4+
"name": "On/Off light",
5+
"restapi": "/lights",
6+
"order": 11,
7+
"uuid": ["$address.ext", "0x01"],
8+
"items": [
9+
"state/reachable",
10+
"state/on"
11+
]
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"schema": "subdevice1.schema.json",
3+
"type": "$TYPE_ON_OFF_OUTPUT",
4+
"name": "On/Off output",
5+
"restapi": "/lights",
6+
"order": 11,
7+
"uuid": ["$address.ext", "0x01"],
8+
"items": [
9+
"state/reachable",
10+
"state/on"
11+
]
12+
}

devices/generic/subdevices/onoff_plugin_unit.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"type": "$TYPE_ON_OFF_PLUGIN_UNIT",
44
"name": "On/Off plug-in unit",
55
"restapi": "/lights",
6+
"order": 11,
67
"uuid": ["$address.ext", "0x01"],
78
"items": [
89
"state/reachable",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"schema": "subdevice1.schema.json",
3+
"type": "$TYPE_OPEN_CLOSE_SENSOR",
4+
"name": "ZHAOpenClose",
5+
"restapi": "/sensors",
6+
"order": 20,
7+
"uuid": ["$address.ext", "0x01", "0x0500"],
8+
"items": [
9+
"config/on",
10+
"config/reachable",
11+
"state/open",
12+
"state/lastupdated"
13+
]
14+
}

devices/generic/subdevices/power_sensor.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"type": "$TYPE_POWER_SENSOR",
44
"name": "ZHAPower",
55
"restapi": "/sensors",
6+
"order": 21,
67
"uuid": ["$address.ext", "0x01", "0x0b04"],
78
"items": [
89
"config/on",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"schema": "subdevice1.schema.json",
3+
"type": "$TYPE_PRESENCE_SENSOR",
4+
"name": "ZHAPresence",
5+
"restapi": "/sensors",
6+
"order": 20,
7+
"uuid": ["$address.ext", "0x01", "0x0406"],
8+
"items": [
9+
"config/on",
10+
"config/duration",
11+
"config/reachable",
12+
"state/presence",
13+
"state/lastupdated"
14+
]
15+
}

0 commit comments

Comments
 (0)