(Translated by https://www.hiragana.jp/)
TypeError: Cannot read properties of undefined (reading 'indexOf') · Issue #18 · hobbyquaker/lgtv2mqtt · GitHub
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read properties of undefined (reading 'indexOf') #18

Open
michelscholte opened this issue Aug 24, 2023 · 1 comment
Open

Comments

@michelscholte
Copy link

I'm getting this error. Is there a solution for it?
Thank you

/usr/lib/node_modules/lgtv2mqtt/index.js:137
if (res.changed.indexOf('volume') !== -1) {
^

TypeError: Cannot read properties of undefined (reading 'indexOf')
at Object.bed14b150001 (/usr/lib/node_modules/lgtv2mqtt/index.js:137:25)
at WebSocketConnection. (/usr/lib/node_modules/lgtv2mqtt/node_modules/lgtv2/index.js:149:48)
at WebSocketConnection.emit (node:events:513:28)
at WebSocketConnection.processFrame (/usr/lib/node_modules/lgtv2mqtt/node_modules/websocket/lib/WebSocketConnection.js:554:26)
at /usr/lib/node_modules/lgtv2mqtt/node_modules/websocket/lib/WebSocketConnection.js:323:40
at processTicksAndRejections (node:internal/process/task_queues:78:11)

@Rybun
Copy link

Rybun commented Sep 30, 2023

Hi, I changed the following from the 137 line of file /usr/lib/node_modules/lgtv2mqtt/index.js :

From:

        if (res.changed.indexOf('volume') !== -1) {
            mqtt.publish(config.name + '/status/volume', String(res.volume), {retain: true});
        }
        if (res.changed.indexOf('muted') !== -1) {
            mqtt.publish(config.name + '/status/mute', res.muted ? '1' : '0', {retain: true});
        }
    });

To:

        if (res && res.changed && res.changed.indexOf('volume') !== -1) {
            mqtt.publish(config.name + '/status/volume', String(res.volume), {retain: true});
        }
        if (res && res.changed && res.changed.indexOf('muted') !== -1) {
            mqtt.publish(config.name + '/status/mute', res.muted ? '1' : '0', {retain: true});
        }
    });

After that, It seems to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants