inverse / tuya-client

此包已弃用且不再维护。未建议替代包。

Tuya 的 API 客户端

0.4.0-alpha 2021-01-14 20:27 UTC

This package is auto-updated.

Last update: 2023-11-12 19:02:19 UTC


README

CI codecov Author Software License Packagist Version Total Downloads

一个用于控制Tuya产品的 WIP API 客户端,深受tuyapy启发。

根据我的理解,这个库使用的 API 已不再支持,因此您可能会更幸运地利用如下包: https://github.com/ground-creative/tuyapiphp

目前支持

  • 开关设备

安装

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