Closed FWuellhorst closed 3 months ago
It seems to me that conCenFan_oveAct_u
is a command
in IoTAent, and the entity attribute is also created by IoTAent.
If that is the case, I will suggest to use command
as the type. For example:
{
"protocol": "IoTA-JSON",
"transport": "MQTT",
"explicitAttrs": false,
"device_id": ???,
"entity_name": "conCenFan_oveAct_u",
"entity_type": "Actuator",
"commands": [
{
"name": "conCenFan_oveAct_u",
"type": "command"
}
],
"attributes": [
...
],
"ngsiVersion": "v2"
}
That is correct. But the type of the command is a Number, not "command". And we never changed this implementation, it was working some months ago.
It works specifying the type="command"
, but I don't get why this only occurs now. We use the development fiware cluster, did you update the iotagent / orion?
As far as I know, IoTagent will always create such an attribute in Orion. So I think the creation of conCenFan_oveAct_u
is not a bug.
And still, I recommend using command
as the data type, because it will be then easier to recognize the command in context broker, and this kind of attribute will not have any meaningful value anyway. The value is stored in conCenFan_oveAct_u_info
Apart from that, are you expecting filip to ignore such a data type error?
{
"conCenFan_oveAct_u": {
"type": "Number",
"value": ""
}
}
ok, thanks! Yes, filip should avoid this error. The attr is not even listed in mongo-express. As the error only occurs due to the conversion from "" to float, this should be catched using some sort of float(value) if value else None
I agree. I will have a look
@FWuellhorst @djs0109 I just faced the exact same issue. I looked into it and the trouble occurs in the ContextAttribute creation and validation.
Let's start at the beginning:
filip.models.ngsi_v2.base.BaseValueAttribute.validate_value_type
to handle EmptyStrings. Otherwise we need to use the the command type so far, which I probably would recommend anyways. If you want to add additional info about the type maybe the metadata field works by now for commands. The latter would require to adjust the command model which would be a minor issue filip.models.ngsi_v2.iot.DeviceCommand
. Let's check on the docs! Here we go: https://iotagent-node-lib.readthedocs.io/en/latest/api.html command
. Probably I followed that in the original implementation but forgot to fix the type in the CommandModel.I'm happy to help out here :) It is true that this is annoying. However, I will not be free until November. Maybe @FWuellhorst @djs0109 you can already try to realize the second option.
Oh, btw @FWuellhorst. If you use command
you can access them directly using the api of the ContextEntity ;) same for relationships :)
@tstorek Thanks for your suggestions! I saw that if the data type is command
, the value will not be validated in filip.models.ngsi_v2.base.BaseValueAttribute.validate_value_type
. That is to say, if using command
as type, empty string will not cause any problem.
For adding the metadata
in DeviceModel, I check the docs. It is actually contradictory... some part suggests that only attribute
can have metadata
, and the other part says that command
can also have metadata
.
So I test it with LibVersion 3.3, JSON-version 2.3:
Metadata in command will cause syntax error
"commands": [
{
"name": "com1",
"type": "command",
"metadata": {
"unitCode": { "type": "Text", "value": "CAL" }
}
}
]
But metadata in attributes can work
"attributes": [
{
"name": "attr1",
"type": "Integer",
"metadata": {
"unitCode": { "type": "Text", "value": "CAL" }
}
}
],
@djs0109 @FWuellhorst According to the previous test, we should do the two things:
What Do you think? Shall we allow any types favoring the missing metadata object? Mostly likely it would be useful also for the other conversions, right?
Okay, thanks for checking! I would suggest to fix the validate_value_type
function for this issue, the rest would be another issue, or?
I think I would add an if
statement to every data type, i.e. to explicitly allow missing values in the form of None
, and ""
. float/int/str(value) if value else None
will be too risky, because it will ignore for example 0
Describe the bug
For this entity:
I get the following attributes when calling
get_attributes
in ngsi_v2:The attribute
conCenFan_oveAct_u
does not exist, and as the value is an empty string but the type a Number, I get a float conversion error.