andrewaubury/tuya-client

Tuya的API客户端

dev-main 2021-03-20 20:22 UTC

This package is auto-updated.

Last update: 2024-09-21 04:07:49 UTC


README

CI codecov Author Software License Packagist Version Total Downloads

一个用于控制Tuya产品的待完成API客户端,灵感主要来自tuyapy

当前支持

  • 开关设备

安装

composer require inverse/tuya-client

示例

<?php

require __DIR__ . '/vendor/autoload.php';

use Inverse\TuyaClient\Session;
use Inverse\TuyaClient\ApiClient;
use Inverse\TuyaClient\Device\SwitchDevice;
use Inverse\TuyaClient\BizType;

// Setup credentials
$username = getenv('TUYA_USERNAME');
$password = getenv('TUYA_PASSWORD');
$countryCode = getenv('TUYA_COUNTRYCODE');
$bizType = new BizType(BizType::TUYA);

// Make client
$session = new Session($username, $password, $countryCode, $bizType);
$apiClient = new ApiClient($session);

// Get all devices
$devices = $apiClient->discoverDevices();

// Switch on all switches
foreach ($devices as $device) {
    if ($device instanceOf SwitchDevice) {
        if (!$device->isOn()) {
            $apiClient->sendEvent($device->getOnEvent());
        }
    }
}

测试

phpunit.xml.dist复制到phpunit.xml,并将服务器变量替换为您的凭据。

许可证

MIT