Closed Alex00101 closed 3 days ago
Does it work?
source:category(CATEGORY_TELEMETRY_SENSOR)
I don't understand what you are trying to do :) If you register a new Source, then its category is CATEGORY_LUA, and you cannot change its category
Yes. category, unit, decimals, value work. The rest (minimum, maximum, protocol , options etc) does not.
I don't understand how category can work, would you try to print source:category() ?
I am not sure of what you are trying to do. It seems to me that you need a DIY sernsor. If I am true, you should use model.createSensor(...)
where all the methods you are mentionning should work.
Sorry category is my bad. It has no effect (doesn't throw an error but has no effect, still returns category lua). I'm still able to change value, unit and decimals, and assumed I should be able to change min and max as well?
Min / Max are not needed, as only your script changes the value, you just need to define your own Min / Max which are Lua only, and private to the Lua Source.
protocolDecimals / protocolUnit are only used with DIY / Custom sensors, where there could be value conversion. But here on Lua sources, there is no protocol, you have to implement what you need in Lua.
Ok thank you. I suspected I might be doing something wrong.
To explain the intent. I wanted a "source" that would effectively work like a sensor but with relatively complex logic for calculating value. My understanding that model.createSensor dies not allow me to apply this logic (cannot hijack wakeup etc) but the source works perfectly for my purposes except that I'd like to be able to set programmaticaly at least one parameter from inside the source code on top of value, unit, decimals. Member, option, min, max whatever. The reason is to signal the caller (ie widget lua code) what "formula" the source is running. I.e. the unit is mah but the value could be mah remaining or mah spent. So option, member whatever would work.
Anyway I understand this is not a bug, happy to park it, but if you could consider this a an future enhancement or later offer me any alternative I'd appreciate that. Sorry if it was wrong time to ask.
Perhaps a new registerSensor
would be better as I understand you need units conversion
I don't understand how mAh remaining / mAh spent could be configured, you would need a Widget for that?
Perhaps a new system.registerSensor with the format similar to registerSource (init, wakeup...) would be ideal. Currently I set source parameters via source configure where I set calculation mode or formula as a choice (mah spent, mah remaining, etc) I just have no way to tell the source caller (ie widget) what mode the source in. If it makes sense.
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days.
It is very possible that the below is not an issue but my lack of understanding, if this the case I apologize and appreciate the clarification.
I'm referring to the following calls in [lua] Source (latest lua doc) and features introduced in 1.5.10
[lua] Source:minimum() Return the source minimum (and modify it on Vars and Sensors)
[lua] source:value(), source:protocolUnit(), source:protocolDecimals() can now modify the value / internal unit and decimals of a DIY telemetry sensor
I'm creating my custom source, using the code "template" below (I have removed irrelevant code). While source:category(CATEGORY_TELEMETRY_SENSOR), source:decimals(2), source:unit(UNIT_VOLT) calls work as expected other calls don't cause any effect e.g. source:minimum() always returns -1e9....
Appreciate any help
local SOURCE_NAME = 'My Source' local SOURCE_KEY = 'MySrc'
local function sourceInit(source) source:category(CATEGORY_TELEMETRY_SENSOR) source:decimals(2)
source:unit(UNIT_VOLT)
---- Above is working, below causes no effect
source:minimum(1) source:maximum(100) source:protocolUnit(UNIT_VOLT) source:protocolDecimals(2) end
local function sourceRead(source) end
local function sourceWrite(source) end
local function sourceWakeup(source)
source:value(101) -- works as expected end
local function sourceConfigure(source)
end
local function init() system.registerSource({key=SOURCE_KEY, name=SOURCE_NAME, init=sourceInit, wakeup=sourceWakeup, configure = sourceConfigure, read=sourceRead, write = sourceWrite }) end
return {init=init}