Expose NWK address as hex value through REST API - #8199
Conversation
|
This will work, but would it be cleaner to implement this logic only once, in |
@ebaauw Thanks Erik for the great suggestion. I always tend to overlook those functions, dunno why :) If @manup agrees, I'm more than happy to move the code into the |
|
Hmm no not really. I'm against bringing item specifics into Lets take a step back to see what this is about: exposing the item to the REST-API and here the external presentation is different from the internal one. I'd propose for now we add a free standing helper function in QVariant R_ItemToRestApiVariant(const ResourceItem *item)
{
if (item)
{
const ResourceItemDescriptor *rid = item->descriptor();
if (rid.suffix == RStateUnicorn)
{
// do special stuff
// return special stuff
}
return item->toVariant();
}
return {};
}In future this can be specified genericly in the item JSON descriptions like "this item should be exposed as hex string in the REST API". I have some plans here but this will take a while. |
We currently have quite some resource item descriptor specific logic in
I like that, but that's a significant refactor, probably beyond the scope of this PR. |
|
Let's start small and then let it grow as necessary 😉 Made the suggested changes hoping they're ok. |
manup
left a comment
There was a problem hiding this comment.
Nice almost there, I have two small change requests.
| const ResourceItemDescriptor rid = item->descriptor(); | ||
| if (rid.suffix == RAttrNwkAddress) | ||
| { | ||
| return QString("0x") + QString("%1").arg(item->toNumber(), 4, 16, QLatin1Char('0')).toUpper(); |
There was a problem hiding this comment.
I suggest a small change to save two QString constructions :)
return QString("0x%1").arg(item->toNumber(), 4, 16, QLatin1Char('0')).toUpper();
There was a problem hiding this comment.
I'm afraid, I did that on purpose, as the suggested amendment does not keep the small letter X. See the output of
deconz-rest-plugin/de_web_plugin.cpp
Lines 4382 to 4383 in 04bd307
There was a problem hiding this comment.
Oh ok indeed that makes sense. Until the item.json display extensions are ready that's ok for now.
Currently, the NWK address is exposed as decimal value. Exposing it as hex value may aid in expediting debugging, as some log line only provide the NWK address.