andrewaubury / tuya-client
Tuya的API客户端
dev-main
2021-03-20 20:22 UTC
Requires
- php: >=7.0
- ext-json: *
- guzzlehttp/guzzle: ^7.2
- webmozart/assert: ^1.3
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-21 04:07:49 UTC
README
一个用于控制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