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

Subscription not working #262

Closed
parthparekh3 opened this issue Apr 22, 2024 · 3 comments
Closed

Subscription not working #262

parthparekh3 opened this issue Apr 22, 2024 · 3 comments
Labels
bug Something isn't working reviewed wip Being worked on

Comments

@parthparekh3
Copy link

parthparekh3 commented Apr 22, 2024

Describe the bug
Calling await context.api.subscriptions.delete() is giving 500

To Reproduce

import {Page, SmartApp, SmartAppContext} from '@smartthings/smartapp';
import{ InstalledAppConfiguration } from "@smartthings/core-sdk"
import express from 'express';
import { AppEvent } from '@smartthings/smartapp/lib/lifecycle-events';
const server = express();
const PORT = 3000;


const appID = "c0c4806c-d6cb-4966-b1c2-21a2b883b01b"

/* Define the SmartApp */
const smartapp = new SmartApp()
    .enableEventLogging(2) // logs all lifecycle event requests and responses as pretty-printed JSON. Omit in production
    .appId(appID)
    .permissions(['r:devices:*'])
    .page('mainPage', (context:SmartAppContext, page:Page, configData?:InstalledAppConfiguration  ) => {
        page.section('settings', section => {
            section
                .deviceSetting('lock')
                .capabilities(['lock'])
                .permissions('rwxi')
            console.log("settings",section);
        });
    })
    // Called for both INSTALLED and UPDATED lifecycle events if there is no separate installed() handler
    .updated(async (context:SmartAppContext, updateData:AppEvent.UpdateData) => {
        // console.log(context.api.subscriptions.delete())
        console.log(JSON.stringify(context.config))
        // let currentTemp = await context.api.devices.getCapabilityStatus(context.config.lock[0].deviceConfig.deviceId,'main','lock')
        // console.log(currentTemp.coolingSetpoint.value)
        await context.api.subscriptions.delete() // clear any existing configuration
        // await context.api.subscriptions.unsubscribeAll();
        await context.api.subscriptions.subscribeToDevices(context.config.lock, '*', '*', 'myDeviceEventHandler');
        await context.api.devices.sendCommands(context.config.lock, 'perfectnumber12833.lock', "lock");
        // await context.api.devices.sendCommands(context.config.lock, 'perfectnumber12833.lock', "unlock");
        console.log("updated data",JSON.stringify(updateData));
        console.log(context.config,"req sent1")
    })
    .subscribedEventHandler('myDeviceEventHandler', async (context, event) => {
        // await context.api.devices.sendCommands(context.config.main, 'lock', "locked");

    });

server.use(express.json());

/* Handle POST requests */
server.post('/', function (req, res, next) {
    console.log(req.body)
    smartapp.handleHttpCallback(req, res);
});

/* Start listening at your defined PORT */
server.listen(PORT, () => console.log(`Server is up and running on port ${PORT}`));

When i use below code
await context.api.subscriptions.delete() // clear any existing configuration

I get this error

2024-04-22T10:47:20.392Z error: AxiosError: options must be an object
    at Object.assertOptions (D:\Work\krishworks\smartlock\node_modules\@smartthings\core-sdk\node_modules\axios\lib\helpers\validator.js:62:11)
    at Axios.request (D:\Work\krishworks\smartlock\node_modules\@smartthings\core-sdk\node_modules\axios\lib\core\Axios.js:65:15)
    at Function.wrap [as request] (D:\Work\krishworks\smartlock\node_modules\@smartthings\core-sdk\node_modules\axios\lib\helpers\bind.js:5:15)
    at EndpointClient.<anonymous> (D:\Work\krishworks\smartlock\node_modules\@smartthings\core-sdk\dist\endpoint-client.js:136:56)
    at Generator.next (<anonymous>)
    at fulfilled (D:\Work\krishworks\smartlock\node_modules\@smartthings\core-sdk\dist\endpoint-client.js:5:58)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
2024-04-22T10:47:20.393Z debug: RESPONSE: {
  "statusCode": 500,
  "message": "Server error: 'AxiosError: options must be an object'"
}

Expected behavior
It should delete the subscriptions

Actual behavior
It gives throws a 500 error

@parthparekh3 parthparekh3 added the bug Something isn't working label Apr 22, 2024
@parthparekh3
Copy link
Author

parthparekh3 commented Apr 23, 2024

@rossiam this works when the sdk is "@smartthings/core-sdk": "8.0.1",

@bflorian bflorian added the wip Being worked on label Apr 24, 2024
@bflorian
Copy link
Contributor

This issue was introduced with a new version of Axis 0.x that is not really backward compatible despite its version number. We are working on a solution.

@rossiam
Copy link
Contributor

rossiam commented Apr 25, 2024

New version 4.3.4 depends on new core SDK that uses Axios 0.28.1 now should fix this.

@rossiam rossiam closed this as completed Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working reviewed wip Being worked on
Projects
None yet
Development

No branches or pull requests

3 participants