1.0.5 • Published 3 years ago
@tuya-miniapp/sdm v1.0.5
English | 简体中文
@tuya-miniapp/sdm
Smart Device Model
Installation
$ npm install @tuya-miniapp/sdm
# or
$ yarn add @tuya-miniapp/sdm
# or
$ pnpm add @tuya-miniapp/sdmUsage
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>
  );
}1.1.0-beta.0
3 years ago
1.0.5
3 years ago
1.0.4
3 years ago
1.0.3
3 years ago
1.0.2
3 years ago
1.0.1
3 years ago
1.0.0
3 years ago
1.0.0-beta.1
3 years ago