# Usage

<div style={{ display: 'flex', gap: '8px', marginBottom: '16px' }}>
  <span style={{ backgroundColor: '#52c41a', color: 'white', padding: '2px 8px', borderRadius: '4px', fontSize: '12px' }}>Device Support</span>
  <span style={{ backgroundColor: '#ff4d4f', color: 'white', padding: '2px 8px', borderRadius: '4px', fontSize: '12px' }}>Group Not Support</span>
</div>

## Getting Started

`SmartTapToRunAbility` is available from `@ray-js/panel-sdk@1.11.0`.

### Basic use

Here is an example of how to use SmartTapToRunAbility in JavaScript:

```ts
import { SmartTapToRunAbility } from '@ray-js/panel-sdk';

// Create an instance of SmartTapToRunAbility
const TapToRun = new SmartTapToRunAbility().init();

// Call the functions of TapToRunModel
TapToRun.getTapToRunRules()
  .then(result => {
    // Handle the returned result
  })
  .catch(error => {
    // Handle error cases
  });
```

### Ray & SDM

Here is an example of how to use SmartTapToRunAbility with Ray & SDM:

**src/devices/index.ts**

> Generate the wireless switch smart device model with the built-in tap-to-run ability

```ts
import { SmartDeviceModel, SmartTapToRunAbility } from '@ray-js/panel-sdk';

const options = {
  abilities: [new SmartTapToRunAbility()],
};

const devices = {
  wireless: new SmartDeviceModel<SmartDeviceSchema, { tapToRun: SmartTapToRunAbility }>(options)
};
```

**src/app.tsx**

> Integrate with the React ecosystem using SdmProvider

```tsx
import React from 'react';
import 'ray';
import '@/i18n';
import { kit, SdmProvider } from '@ray-js/panel-sdk';
import { devices } from '@/devices';

const { initPanelEnvironment } = kit;

interface Props {
  children: React.ReactNode;
}

initPanelEnvironment({ useDefaultOffline: true });

export default class App extends React.Component<Props> {
  onLaunch() {
    console.info('=== App onLaunch');
  }

  render() {
    return (
      <SdmProvider value={devices.sensor}>{this.props.children}</SdmProvider>
    );
  }
}
```

{/* ## Use Case */}

{/* The core functionality of the wireless switch product can be achieved through the `SmartTapToRunAbility`. It is recommended to read the [Wireless Switch Tap-to-run Template Codelab](https://developer.tuya.com/en/miniapp-codelabs/codelabs/panel-wireless-tap-to-run/index.html) for more information. */}

## Notes

The `SmartTapToRunAbility` is based on the following atomic APIs, so the `@ray-js/ray` version needs to be greater than `^1.5.15`:

- [getSceneListV2](/en/miniapp/develop/ray/api/scenes/query/getSceneListV2)
- [getBindRuleList](/en/miniapp/develop/ray/api/scenes/query/getBindRuleList)
- [bindRule](/en/miniapp/develop/ray/api/scenes/rule/bindRule)
- [unbindRule](/en/miniapp/develop/ray/api/scenes/rule/unbindRule)
- [triggerRule](/en/miniapp/develop/ray/api/scenes/rule/triggerRule)
