Fix TypeError NoneType variant.py

What

The fromJSON method currently crashes when _ARON_VALUE is None in the input dictionary. This concerns the file python3-armarx/armarx_memory/aron/data/variant.py.

This concerns line 117: value: np.float32 = np.float32(float(j["_ARON_VALUE"])) This is the stack trace:

File "...", line 41, in load_data
    instance.load()
  File ".../.venv/lib/python3.10/site-packages/armarx_memory/ltm/base/entity_instance.py", line 59, in load
    self.data = AronDict.fromJSON(json_data)
  File ".../.venv/lib/python3.10/site-packages/armarx_memory/aron/data/variant.py", line 506, in fromJSON
    d = AronDict.fromJSON(v)
  File ".../.venv/lib/python3.10/site-packages/armarx_memory/aron/data/variant.py", line 488, in fromJSON
    d = AronFloat.fromJSON(v)
  File ".../.venv/lib/python3.10/site-packages/armarx_memory/aron/data/variant.py", line 117, in fromJSON
    value: np.float32 = np.float32(float(j["_ARON_VALUE"]))
TypeError: float() argument must be a string or a real number, not 'NoneType'

Why

This is caused by json_data in entity_instance.py with the value {'_ARON_PATH': ['extraFloats', 'PowerBoard.remainingTime_h'], '_ARON_TYPE': '_ARON_FLOAT', '_ARON_VALUE': None}.

And this comes from the following snapshot data:

"PowerBoard.remainingTime_h": {
          "_ARON_PATH": [
            "extraFloats",
            "PowerBoard.remainingTime_h"
          ],
          "_ARON_TYPE": "_ARON_FLOAT",
          "_ARON_VALUE": null
        },

How fixed?

null seems to be a possibility for '_ARON_VALUE' and probably was not taken into account when writing variant.py. To fix this, a null check was added to line 117 and in this case _ARON_VALUE just defaults to 0.0.

Merge request reports

Loading