andrewaubury / tuya-client
API client for Tuya
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: 2025-02-21 05:01:10 UTC
README
An WIP API Client for controlling Tuya products, heavily inspired by tuyapy.
Currently Supporting
- Switch devices
Installation
composer require inverse/tuya-client
Example
<?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()); } } }
Testing
Copy phpunit.xml.dist
to phpunit.xml
and replace the server variables with your credentials.
Licence
MIT