ioBroker.js-controller
ioBroker.js-controller copied to clipboard
setBinaryState requires namespace?
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?
- Function name should be
setForeignBinaryState
if it behaves like this or -
_fixId
should be called inside the function
https://github.com/ioBroker/ioBroker.js-controller/blob/adbf47e986cc9568187ab6953df3d37f2b5c6e41/packages/adapter/lib/adapter/adapter.js#L6583
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.
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);
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.
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
TODOs:
- Create issues and monitor all adapters that need to adjust the used method
- Adjust the method in controller 4.1
Related issues:
- https://github.com/ioBroker/ioBroker.cameras/issues/14
- https://github.com/ioBroker/ioBroker.phantomjs/issues/26
- https://github.com/iobroker-community-adapters/ioBroker.ring/issues/200
- https://github.com/ioBroker/ioBroker.sonos/issues/129
- https://github.com/ioBroker/ioBroker.admin/issues/1297
- https://github.com/ioBroker/ioBroker.javascript/issues/947
- https://github.com/iobroker-community-adapters/ioBroker.chromecast/issues/107
- https://github.com/ioBroker/ioBroker.sayit/issues/185