1.0.5 • Published 2 years ago

@tuya-miniapp/sdm v1.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

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>
  );
}
1.1.0-beta.0

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.0.0-beta.1

2 years ago