ioBroker / ioBroker.js-controller

ioBroker controller
http://iobroker.net
MIT License
294 stars 60 forks source link

setBinaryState requires namespace? #1674

Closed klein0r closed 1 year ago

klein0r commented 2 years ago

If I call this.setBinaryState('myId') I receive

2022-01-15 16:37:02.275  - error: octoprint.0 (3012) Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch().
2022-01-15 16:37:02.276  - error: octoprint.0 (3012) unhandled promise rejection: Object does not exist
2022-01-15 16:37:02.278  - error: octoprint.0 (3012) Error: Object does not exist

I have to use this.setBinaryState(this.namespace + '.myId')

Why?

https://github.com/ioBroker/ioBroker.js-controller/blob/adbf47e986cc9568187ab6953df3d37f2b5c6e41/packages/adapter/lib/adapter/adapter.js#L6583

foxriver76 commented 2 years ago

Yes, I guess the method was added on demand a long time ago and was only introduced for foreign objects, like some other not that common methods.

The problem I see is that we need to update all adapters and release new versions with the next controller Dep which use this atm (to get foreign stuff, own could be detected and handled), because breaking change.. no clue how many adapters are affected. @Apollon77 could grep, but maybe it would be a more realistic solution to document this behavior in docs + typings.

Apollon77 commented 2 years ago

Seems 8 adapters ...

ioBroker.cameras/main.js:                            return adapter.setBinaryStateAsync(adapter.namespace + '.cameras.' + cam.name, Buffer.from(_imageData.body));
ioBroker.phantomjs/main.js:                    adapter.setBinaryState(adapter.namespace + '.pictures.' + fileName, data, function (err) {
ioBroker.ring/ring.js:        if (snapshot) await adapter.setBinaryStateAsync(stateId, snapshot.image);
ioBroker.ring/ring.js:          if (livestream) await adapter.setBinaryStateAsync(stateId, livestream.video);
ioBroker.sonos/main.js:                adapter.setBinaryState(id, data, err => {
ioBroker.sonos/main.js:                adapter.setBinaryState(stateName, fileData, () => 
ioBroker.sonos/main.js:        adapter.setBinaryState(stateName, fileData, () =>
ioBroker.admin/lib/socket.js:        socket.on('setBinaryState', function (id, base64, callback) {
ioBroker.admin/lib/socket.js:                        adapter.log.warn('[setBinaryState] Cannot convert base64 data: ' + e);
ioBroker.admin/lib/socket.js:                    adapter.setBinaryState(id, data, (err, ...args) =>
ioBroker.admin/lib/socket.js:                    adapter.log.warn('[setBinaryState] Invalid callback');
ioBroker.chromecast/lib/chromecastDevice.js:                    adapter.setBinaryState(exported_file_state, fs.readFileSync(url2play), err => {
ioBroker.javascript/lib/sandbox.js:        const setStateFunc = isBinary ? adapter.setBinaryState.bind(adapter) : adapter.setForeignState.bind(adapter);
ioBroker.javascript/lib/sandbox.js:                result.setBinaryState = function () {
ioBroker.javascript/lib/sandbox.js:            result.setBinaryState = function (state, isAck, callback) {
ioBroker.javascript/lib/sandbox.js:                result.setBinaryStateAsync(state, isAck).then(() => {
ioBroker.javascript/lib/sandbox.js:            result.setBinaryStateAsync = async function (state, isAck) {
ioBroker.javascript/lib/sandbox.js:                    await adapter.setBinaryStateAsync(this[i], state);
ioBroker.javascript/lib/sandbox.js:        setBinaryState: function (id, state, callback) {
ioBroker.javascript/lib/sandbox.js:        'setBinaryState',
ioBroker.sayit/lib/speech2device.js:        adapter.setBinaryState(`${adapter.namespace}.tts.${options.outFileExt}`, fileData, callback);
AlCalzone commented 2 years ago

ioBroker.javascript/lib/sandbox.js

Yeah this is going to break user scripts. Not sure how many are using this, but I'd expect at least some.

Apollon77 commented 2 years ago

Ok, but here it is simple ... we can leave the name as is in Javascrit sandbox and just use the "foreign" name regads adapter class ... we do not have "foreign" differentiation in Javascript-scripts

Apollon77 commented 2 years ago

TODOs:

Apollon77 commented 2 years ago

Related issues: