it seems like math does not have "pow" anymore
veonua opened this issue · comments
function illuminance_measurement_defaults.illuminance_attr_handler(driver, device, value, zb_rx)
local lux_value = math.floor(math.pow(10, (value.value - 1) / 10000))
device:emit_event_for_endpoint(zb_rx.address_header.src_endpoint.value, capabilities.illuminanceMeasurement.illuminance(lux_value))
end
Zigbee Motion Sensor Illuminance Sensor thread encountered error: [string "st.zigbee.defaults.illuminanceMeasurement_def..."]:33: attempt to call a nil value (field 'pow')
math.pow
should be available with the currently deployed version of the platform. Is it possible that somehow the global math
is getting overwritten?
for example
math = {}
would overwrite the global math
variable with an empty table resulting in the error provided above, while
local math = {}
would create a locally scoped math
variable that would shadow the global math
also causing the same error but only for the file or function scope in which it is defined.
If not running on the platform, you might be hitting this issue if running lua version 5.4 since it was removed in that version.
probably you should look into your code first
I did confirm that math.pow
is being made available to the platform, I am trying to figure out the context in which it is being overwritten, the questions above are 2 possible places that this could be happening. Are you able to confirm neither of those are happening on your end?
it's ST illuminance_measurement_defaults.illuminance_attr_handler
no, there is no math = {}
in my code
Are you running this on a hub or locally on your computer? If locally what comes back from lua -e "print(_VERSION)"
?
on hub
Thank you for this all this information, it seem like our lua version isn't getting built with the appropriate flags.
Thanks for the report @veonua, With @FreeMasen, we dug in deeper and it looks like the embedded version of lua we are using is being built without LUA_COMPAT_MATHLIB
which resulted in the math methods deprecated in 5.3 not being included on in the interpreter. This particular part of the lib was covered by test infrastructure using a lua interpreter which did included math.pow
which is why this slipped by.
We'll be looking to address this (either by changing how the bundled interpreter is built or providing a polyfill) as part of the current hub firmware beta.
so the drivers are not tested on the hub itself :(
It would be nice to have integration tests