Skip to content

Commit 54a8559

Browse files
committed
Merge branch 'poll_control2' into stable
2 parents e9a15a6 + a520010 commit 54a8559

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

de_web_plugin.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -4734,6 +4734,8 @@ void DeRestPluginPrivate::addSensorNode(const deCONZ::Node *node, const deCONZ::
47344734
std::vector<Sensor>::iterator i = sensors.begin();
47354735
std::vector<Sensor>::iterator end = sensors.end();
47364736

4737+
bool pollControlInitialized = false;
4738+
47374739
for (; i != end; ++i)
47384740
{
47394741
if (i->address().ext() == node->address().ext())
@@ -4749,6 +4751,18 @@ void DeRestPluginPrivate::addSensorNode(const deCONZ::Node *node, const deCONZ::
47494751
DBG_Printf(DBG_INFO, "SensorNode %s set node %s\n", qPrintable(i->id()), qPrintable(node->address().toStringExt()));
47504752

47514753
pushSensorInfoToCore(&*i);
4754+
4755+
// If device has Poll Control cluster, configure it via the first Sensor.
4756+
if (!pollControlInitialized && PC_GetPollControlEndpoint(node) > 0)
4757+
{
4758+
auto *itemPending = i->item(RConfigPending);
4759+
if (itemPending)
4760+
{
4761+
DBG_Printf(DBG_INFO, "Init Poll Control for %s\n", qPrintable(node->address().toStringExt()));
4762+
pollControlInitialized = true;
4763+
itemPending->setValue(itemPending->toNumber() | R_PENDING_WRITE_POLL_CHECKIN_INTERVAL | R_PENDING_SET_LONG_POLL_INTERVAL);
4764+
}
4765+
}
47524766
}
47534767

47544768
auto *item = i->item(RStateBattery);
@@ -6843,7 +6857,7 @@ void DeRestPluginPrivate::addSensorNode(const deCONZ::Node *node, const SensorFi
68436857
{
68446858
sensorNode.setManufacturer("Samjin");
68456859

6846-
if (fingerPrint.hasInCluster(IAS_ZONE_CLUSTER_ID)) // POLL_CONTROL_CLUSTER_ID
6860+
if (PC_GetPollControlEndpoint(node) > 0)
68476861
{
68486862
item = sensorNode.addItem(DataTypeUInt8, RConfigPending);
68496863
item->setValue(item->toNumber() | R_PENDING_WRITE_POLL_CHECKIN_INTERVAL | R_PENDING_SET_LONG_POLL_INTERVAL);

poll_control.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ bool DeRestPluginPrivate::checkPollControlClusterTask(Sensor *sensor)
113113
return false;
114114
}
115115

116+
if (sensor->node()->nodeDescriptor().manufacturerCode() == VENDOR_IKEA && (item->toNumber() & R_PENDING_SET_LONG_POLL_INTERVAL) != 0)
117+
{
118+
// for IKEA devices leave long poll interval at factory default settings
119+
// TODO configure in DDF
120+
item->setValue(item->toNumber() & ~(R_PENDING_SET_LONG_POLL_INTERVAL));
121+
}
122+
116123
if (item->toNumber() & R_PENDING_WRITE_POLL_CHECKIN_INTERVAL)
117124
{
118125
// write poll control checkin interval
@@ -128,12 +135,13 @@ bool DeRestPluginPrivate::checkPollControlClusterTask(Sensor *sensor)
128135
item->setValue(item->toNumber() & ~R_PENDING_WRITE_POLL_CHECKIN_INTERVAL);
129136
return true;
130137
}
138+
139+
return false; // only send Set Long Poll Interval after writing this attribute
131140
}
132141

133142
if (item->toNumber() & R_PENDING_SET_LONG_POLL_INTERVAL)
134143
{
135144
deCONZ::ApsDataRequest apsReq;
136-
deCONZ::ZclFrame zclFrame;
137145

138146
// ZDP Header
139147
apsReq.dstAddress() = sensor->address();
@@ -146,7 +154,7 @@ bool DeRestPluginPrivate::checkPollControlClusterTask(Sensor *sensor)
146154
apsReq.setTxOptions(deCONZ::ApsTxAcknowledgedTransmission);
147155

148156
deCONZ::ZclFrame outZclFrame;
149-
outZclFrame.setSequenceNumber(zclFrame.sequenceNumber());
157+
outZclFrame.setSequenceNumber(static_cast<quint8>(QDateTime::currentMSecsSinceEpoch()));
150158
outZclFrame.setCommandId(0x02); // set long poll interval
151159
outZclFrame.setFrameControl(deCONZ::ZclFCClusterCommand | deCONZ::ZclFCDirectionClientToServer);
152160

rest_sensors.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -2723,7 +2723,7 @@ void DeRestPluginPrivate::handleSensorEvent(const Event &e)
27232723
if (strncmp(e.what(), "state/", 6) == 0)
27242724
{
27252725
ResourceItem *item = sensor->item(e.what());
2726-
if (item)
2726+
if (item && item->isPublic())
27272727
{
27282728
if (item->descriptor().suffix == RStatePresence && item->toBool())
27292729
{
@@ -2781,7 +2781,7 @@ void DeRestPluginPrivate::handleSensorEvent(const Event &e)
27812781
{
27822782
iy = item;
27832783
}
2784-
else if (item->lastSet().isValid() && (gwWebSocketNotifyAll || rid.suffix == RStateButtonEvent || (item->lastChanged().isValid() && item->lastChanged() >= sensor->lastStatePush)))
2784+
else if (item->isPublic() && item->lastSet().isValid() && (gwWebSocketNotifyAll || rid.suffix == RStateButtonEvent || (item->lastChanged().isValid() && item->lastChanged() >= sensor->lastStatePush)))
27852785
{
27862786
state[key] = item->toVariant();
27872787
}
@@ -2825,7 +2825,7 @@ void DeRestPluginPrivate::handleSensorEvent(const Event &e)
28252825
else if (strncmp(e.what(), "config/", 7) == 0)
28262826
{
28272827
ResourceItem *item = sensor->item(e.what());
2828-
if (item)
2828+
if (item && item->isPublic())
28292829
{
28302830
if (sensor->lastConfigPush.isValid() &&
28312831
item->lastSet() < sensor->lastConfigPush)
@@ -2871,7 +2871,7 @@ void DeRestPluginPrivate::handleSensorEvent(const Event &e)
28712871
{
28722872
ilct = item;
28732873
}
2874-
else if (item->lastSet().isValid() && (gwWebSocketNotifyAll || (item->lastChanged().isValid() && item->lastChanged() >= sensor->lastConfigPush)))
2874+
else if (item->isPublic() && item->lastSet().isValid() && (gwWebSocketNotifyAll || (item->lastChanged().isValid() && item->lastChanged() >= sensor->lastConfigPush)))
28752875
{
28762876
if (rid.suffix == RConfigSchedule)
28772877
{
@@ -2911,7 +2911,7 @@ void DeRestPluginPrivate::handleSensorEvent(const Event &e)
29112911
else if (strncmp(e.what(), "attr/", 5) == 0)
29122912
{
29132913
ResourceItem *item = sensor->item(e.what());
2914-
if (item)
2914+
if (item && item->isPublic())
29152915
{
29162916
QVariantMap map;
29172917
map["t"] = QLatin1String("event");

0 commit comments

Comments
 (0)