Toxblh / samsung-tv-control

📺 Remote control your TV via JS!
https://toxblh.github.io/samsung-tv-control/
MIT License
177 stars 34 forks source link

TypeError: control.isAvaliable is not a function #284

Open logan-kling opened 1 year ago

logan-kling commented 1 year ago

As you'll be able to tell, I have this package installed within a subdirectory of my automation directory called samsung-tv-control. This directory has the two JavaScript files I've been trying to run (SamsungOn.js and SamsungOff.js) as well as all those packages installed by npm install samsung-tv-control --save, which are within a directory called node_modules. I believe this is expected behavior.

Anyways, here's the command I've been using to try to run SamsungOff.js and its resulting error messages. I'll include SamsungOff.js at the end of this:

node SamsungOff.js
# [2022-10-11T08:56:54.168Z] #
FUNCTION: constructor
LOG config
{
  debug: true,
  ip: '192.168.0.93',
  mac: '543ad6badca9',
  name: 'NodeJS-Test',
  port: 8002,
  token: '12345678'
}
### ### ###

# [2022-10-11T08:56:54.196Z] #
FUNCTION: constructor
LOG internal config
{
  IP: '192.168.0.93',
  MAC: '543ad6badca9',
  NAME_APP: 'Tm9kZUpTIFJlbW90ZQ==',
  PORT: 8002,
  SAVE_TOKEN: false,
  TOKEN: '12345678',
  WS_URL: 'wss://192.168.0.93:8002/api/v2/channels/samsung.remote.control?name=Tm9kZUpTIFJlbW90ZQ==&token=12345678'
}
### ### ###

C:\Users\logan\Documents\Logan\Tech\Automation\samsung-tv-control\SamsungOff.js:18
  .isAvaliable()
   ^

TypeError: control.isAvaliable is not a function
    at Object.<anonymous> (C:\Users\logan\Documents\Logan\Tech\Automation\samsung-tv-control\SamsungOff.js:18:4)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47

And my SamsungOff.js file just so you can look for every potential cause of this error:

// import Samsung, { KEYS } from 'samsung-tv-control'
const Samsung = require('samsung-tv-control').default
const { KEYS } = require('samsung-tv-control/lib/keys')

const config = {
  debug: true, // Default: false
  ip: '192.168.0.93',
  mac: '543ad6badca9', //54:3a:d6:ba:dc:a9
  name: 'NodeJS-Test', // Default: NodeJS
  port: 8002, // Default: 8002
  token: '12345678',
}

const control = new Samsung(config)

control.turnOn()
control
  .isAvaliable()
  .then(() => {
    // Get token for API
    control.getToken(token => {
      console.info('# Response getToken:', token)
    })

    // Send key to turn TV off
    control.sendKey(KEYS.KEY_POWEROFF, function(err, res) {
      if (err) {
        throw new Error(err)
      } else {
        console.log(res)
      }
    })
  })
.catch(e => console.error(e))
Dwarf8 commented 11 months ago

Try isAvailable, instead of isAvaliable.

:D