Hello
What is the correct way to instantiate a device that needs @framework in a plugin?
Ex: variablesDevice.
I always receive a “framework not defined” error in the constructor of the device.
Thanks
Instantiate variablesdevice in my plugin
Hello
What is the correct way to instantiate a device that needs @framework in a plugin?
Ex: variablesDevice.
I always receive a “framework not defined” error in the constructor of the device.
Thanks
@360manu You can simply pass in the plugin object and use plugin.framework. For example, see https://github.com/flybysun/pimatic-dewpoint/blob/master/dewpoint.coffee#L62
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
Many thanks!!
I read most of the plugins code, but not this one.
it will help a lot !
I am interessted in what is wrong with my code ?
class ManuThermostat extends env.plugins.Plugin
init: (app, @framework, @config) =>
deviceConfigDef = require("./device-config-schema")
@framework.deviceManager.registerDeviceClass("ManuHeatingThermostat", {
configDef: deviceConfigDef.ManuHeatingThermostat,
createCallback: (config, lastState) -> new ManuHeatingThermostat(config, lastState, @framework)
})
and the device
class ManuHeatingThermostat extends env.devices.Device
...
constructor: (@config, lastState, framework) ->
@_vars = framework.variableManager # !! error is here !!
@_vars.on "variableValueChanged", (variable, value) =>
if variable.name is "tempsalon.temperature"
env.logger.debug "log temp : ", variable.name, value
super()
@360manu said:
I am interessted in what is wrong with my code ?
You’re missing the formal parameter framework
in createCallback
. It should work as follows
createCallback: (config, lastState, framework) -> new ManuHeatingThermostat(config, lastState, @framework)
# ^^^^^
EDIT: However, it is also possible to avoid the additional parameter and use the plugin variable as it is done in the dewpoint plugin
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law