Skip to content

Commit

Permalink
Add new 'Control' widget and DDF editor
Browse files Browse the repository at this point in the history
- Control permit join from the GUI (properly)
- The DDf editor is alpha but supports editing items and hot reload changes
  • Loading branch information
manup committed Sep 6, 2021
1 parent a432c05 commit e8b8b8f
Show file tree
Hide file tree
Showing 24 changed files with 2,858 additions and 36 deletions.
4 changes: 4 additions & 0 deletions database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6600,6 +6600,10 @@ int DB_GetSubDeviceItemCount(QLatin1String uniqueId)
result = sqlite3_column_int(res, 0);
}
}
else
{
DBG_Printf(DBG_ERROR, "error preparing sql (err: %d): %s\n", rc, sql);
}

rc = sqlite3_finalize(res);
DBG_Assert(rc == SQLITE_OK);
Expand Down
16 changes: 15 additions & 1 deletion de_web.pro
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ HEADERS = bindings.h \
thermostat.h \
thermostat_ui_configuration.h \
tuya.h \
ui/ddf_editor.h \
ui/ddf_itemeditor.h \
ui/ddf_itemlist.h \
ui/ddf_treeview.h \
ui/device_widget.h \
ui/text_lineedit.h \
utils/bufstring.h \
utils/stringcache.h \
utils/utils.h \
Expand Down Expand Up @@ -240,6 +246,12 @@ SOURCES = air_quality.cpp \
rule.cpp \
state_change.cpp \
thermostat_ui_configuration.cpp \
ui/ddf_editor.cpp \
ui/ddf_itemeditor.cpp \
ui/ddf_itemlist.cpp \
ui/ddf_treeview.cpp \
ui/device_widget.cpp \
ui/text_lineedit.cpp \
upnp.cpp \
permitJoin.cpp \
scene.cpp \
Expand Down Expand Up @@ -292,4 +304,6 @@ win32:DESTDIR = ../../debug/plugins # TODO adjust
unix:DESTDIR = ..

FORMS += \
de_web_widget.ui
de_web_widget.ui \
ui/ddf_editor.ui \
ui/device_widget.ui
31 changes: 30 additions & 1 deletion de_web_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "de_web_plugin.h"
#include "de_web_plugin_private.h"
#include "de_web_widget.h"
#include "ui/device_widget.h"
#include "gateway_scanner.h"
#include "ias_ace.h"
#include "json.h"
Expand Down Expand Up @@ -12980,11 +12981,29 @@ void DeRestPluginPrivate::nodeEvent(const deCONZ::NodeEvent &event)
addLightNode(event.node());
}

if (deviceWidget)
{
deviceWidget->nodeEvent(event);
}

break;

case deCONZ::NodeEvent::NodeDeselected:
if (deviceWidget)
{
deviceWidget->nodeEvent(event);
}
break;

#if DECONZ_LIB_VERSION >= 0x011003
case deCONZ::NodeEvent::EditDeviceDDF:
if (deviceWidget)
{
deviceWidget->nodeEvent(event);
}
break;
#endif

case deCONZ::NodeEvent::NodeRemoved: // deleted via GUI
{
#if DECONZ_LIB_VERSION >= 0x011001
Expand All @@ -12993,6 +13012,10 @@ void DeRestPluginPrivate::nodeEvent(const deCONZ::NodeEvent &event)
restDevices->deleteDevice(event.node()->address().ext());
}
#endif
if (deviceWidget)
{
deviceWidget->nodeEvent(event);
}
}
break;

Expand Down Expand Up @@ -17197,6 +17220,7 @@ bool DeRestPlugin::hasFeature(Features feature)
switch (feature)
{
case DialogFeature:
case WidgetFeature:
case HttpClientHandlerFeature:
return true;

Expand All @@ -17212,7 +17236,12 @@ bool DeRestPlugin::hasFeature(Features feature)
*/
QWidget *DeRestPlugin::createWidget()
{
return 0;
if (!d->deviceWidget)
{
d->deviceWidget = new DeviceWidget(d->m_devices, nullptr);
connect(d->deviceWidget, &DeviceWidget::permitJoin, d, &DeRestPluginPrivate::permitJoin);
}
return d->deviceWidget;
}

/*! Creates a control dialog for this plugin.
Expand Down
1 change: 1 addition & 0 deletions de_web_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

class DeRestWidget;
class DeRestPluginPrivate;
class DeviceWidget;

#if DECONZ_LIB_VERSION < 0x010800
#error "The REST plugin requires at least deCONZ library version 1.8.0."
Expand Down
3 changes: 3 additions & 0 deletions de_web_plugin_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ extern const char *HttpContentSVG;

// Forward declarations
class DeviceDescriptions;
class DeviceWidget;
class Gateway;
class GatewayScanner;
class QUdpSocket;
Expand Down Expand Up @@ -2003,6 +2004,8 @@ public Q_SLOTS:
SearchSensorsDone,
};


DeviceWidget *deviceWidget = nullptr;
RestDevices *restDevices;

int sensorIndIdleTotalCounter;
Expand Down
9 changes: 5 additions & 4 deletions device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,10 +736,6 @@ void DEV_IdleStateHandler(Device *device, const Event &event)
d->setState(nullptr, STATE_LEVEL_POLL);
return;
}
else if (event.what() == REventDDFReload)
{
d->setState(DEV_InitStateHandler);
}
else if (event.what() != RAttrLastSeen && event.what() != REventPoll)
{
// DBG_Printf(DBG_INFO, "DEV Idle event %s/0x%016llX/%s\n", event.resource(), event.deviceKey(), event.what());
Expand Down Expand Up @@ -1458,6 +1454,11 @@ void Device::handleEvent(const Event &event, DEV_StateLevel level)
Q_ASSERT(event.num() < StateLevelMax);
d->state[event.num()](this, event);
}
else if (event.what() == REventDDFReload)
{
d->setState(DEV_InitStateHandler);
d->startStateTimer(50, StateLevel0);
}
else if (d->state[level])
{
if (event.what() == REventAwake && level == StateLevel0)
Expand Down
Loading

0 comments on commit e8b8b8f

Please sign in to comment.