Provisions - overwrite 'declare'

#1

Hi,

I have a large Provision handling different device Models. Now I have a device which is rather buggy and does not accept boolean values for most of the paths. Using

declare(....,....,{ value: ["0", 'xsd:string'] });

works though.

Now I thought to overwrite the declare function. I cannot think of another way besides using dozens of else/if and that would seriously mess up my code.

However as I’m not experienced in node/js I need a little help. Below doesn’t work :frowning:

if (MODEL === 'buggyDevice') {
    var origDeclare = declare;  //does not work
    declare = function (path, timestamps, values) {
        if (values.value === false) {
            values.value = ["0", 'xsd:string'];
        }
        if (values.value === true) {
            values.value = ["1", 'xsd:string'];
        }
        return origDeclare(path, timestamps, values);
    }
}

thank you
Simon

#2

Why are you doing this to yourself :slight_smile: Just create different scripts for different models.

#3

Hehe, you’re kinda right. However I have 4 CPE Models same Vendor and they differ only very slightly in capabilities. Having quite complex logic I don’t want to modify 4 provisions (which I used to have) to add change something. But I guess I either have a separate provision for that “buggy” model or write a wrapping function.

But if you’d know a simple way to overwrite the declare that would be my preferred way.