@tuya-miniapp/sdm
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

English | 简体中文

@tuya-miniapp/sdm

latest download

Smart Device Model

Installation

$ npm install @tuya-miniapp/sdm
# or
$ yarn add @tuya-miniapp/sdm
# or
$ pnpm add @tuya-miniapp/sdm

Usage

import { SmartDeviceModel } from '@tuya-miniapp/sdm';

// SmartDevices comes from typings/sdm.d.ts,negligible for non Typescript developers
export const devices = {} as SmartDevices;

SmartDeviceModel.init<SmartDeviceSchema>().then(device => {
  /**
   * It is recommended that the name of the smart device be used as the key name for assignment
   */
  devices.robot = device;
});

devices.robot.model.actions.power.toggle()

Ray / React Project

// src/app.tsx
import React from 'react';
import 'ray';
import '@/i18n';
import { kit } from '@ray-js/panel-sdk';
import { SdmProvider } from '@ray-js/sdm-react';
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.robot}>{this.props.children}</SdmProvider>
    );
  }
}
// src/pages/home/index.tsx
import React from 'react';
import { Button, View } from '@ray-js/components';
import { devices } from '@/devices';

export default function Home() {
  const device = devices.robot;
  return (
    <View>
      <Button onClick={() => device.model.actions.power.toggle()}>
        Click me toggle power
      </Button>
    </View>
  );
}

Readme

Keywords

none

Package Sidebar

Install

npm i @tuya-miniapp/sdm

Weekly Downloads

0

Version

1.0.5

License

MIT

Unpacked Size

87.1 kB

Total Files

50

Last publish

Collaborators

  • tuyafe