Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDF prevent load/store incomplete sensors with endpoint 0xFF #5757

Merged
merged 1 commit into from Feb 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 34 additions & 5 deletions database.cpp
Expand Up @@ -3211,12 +3211,30 @@ static int sqliteLoadAllSensorsCallback(void *user, int ncols, char **colval , c
quint64 extAddr = 0;
quint16 clusterId = 0;
quint8 endpoint = sensor.fingerPrint().endpoint;


if (!isClip && sensor.type() == QLatin1String("Daylight"))
{
isClip = true;
}

DBG_Printf(DBG_INFO_L2, "DB found sensor %s %s\n", qPrintable(sensor.name()), qPrintable(sensor.id()));

if (!isClip)
{
const auto ddf = d->deviceDescriptions->get(&sensor);
if (ddf.isValid())
{
unsigned ep = endpointFromUniqueId(sensor.uniqueId());
if (ep == 0xFF || ep == 0)
{
// in earlier versions the sensor was created from an DDF draft device with not yet set endpoint
// TODO(mpi): delete sensor from DB
// SELECT * FROM sensors where uniqueid LIKE '%-ff-%'
DBG_Printf(DBG_INFO, "DB skip loading sensor %s %s, invalid endpoint 0xff\n", qPrintable(sensor.name()), qPrintable(sensor.uniqueId()));
return 0;
}

const int itemCount = DB_GetSubDeviceItemCount(sensor.item(RAttrUniqueId)->toLatin1String());

if (itemCount == 0)
Expand All @@ -3231,11 +3249,6 @@ static int sqliteLoadAllSensorsCallback(void *user, int ncols, char **colval , c
}
}

if (!isClip && sensor.type() == QLatin1String("Daylight"))
{
isClip = true;
}

if (isClip)
{
sensor.removeItem(RAttrLastAnnounced);
Expand Down Expand Up @@ -5564,6 +5577,16 @@ void DeRestPluginPrivate::saveDb()
continue;
}

// don't store incomplete DDF draft sensors
if (i->type().startsWith('Z'))
{
unsigned ep = endpointFromUniqueId(i->uniqueId());
if (ep == 0xFF || ep == 0)
{
continue;
}
}

QString stateJSON = i->stateToString();
QString configJSON = i->configToString();
QString fingerPrintJSON = i->fingerPrint().toString();
Expand Down Expand Up @@ -6448,6 +6471,12 @@ bool DB_StoreSubDevice(const QString &parentUniqueId, const QString &uniqueId)
return false;
}

unsigned ep = endpointFromUniqueId(uniqueId);
if (ep == 0xFF || ep == 0) // incomplete DDF sub device uniqueid template
{
return false;
}

DeRestPluginPrivate::instance()->openDb();

if (!db)
Expand Down