sinverba/domoticz-php-api-wrapper

该软件包已被废弃且不再维护。未建议替代软件包。

Domoticz API 的简单 PHP 封装

v2.1.0 2019-03-12 16:55 UTC

README

V. 2.1.0 - 最后更新:2019/12/03

Scrutinizer Code Quality Code Coverage Build Status Build Status codecov StyleCI

Domoticz API 的简单 PHP 封装。

感谢 Domoticz 的出色工作。

使用这个库,您可以通过 API 连接到您的 Domoticz 服务器。

请查看兼容性表以确定您需要 V1 还是 V2。

V1 已不再维护。V2 正在开发中。

版本兼容性表

Domoticz API V 2

Domoticz 版本 稳定版 / 测试版 兼容 / 工作
4.9700 稳定
4.9788 测试版

3.9501 已不再测试,我在此问题后恢复到 3.8153。

Domoticz API V 1

Domoticz 版本 稳定版 / 测试版 兼容 / 工作
3.8153 稳定
3.9453 测试版
3.9458 测试版
3.9501 测试版 查看问题
3.9639 测试版
4.9700 稳定
4.9732 测试版
4.9763 测试版
4.9764 测试版

3.9501 已不再测试,我在此问题后恢复到 3.8153。

安装

版本 2.X

$ composer require sineverba/domoticz-php-api-wrapper "^2"

版本 1.7.1

$ composer require sineverba/domoticz-api "^1"

使用方法

版本 2

<?php

require_once ('vendor/autoload.php');

use \sineverba\domoticzapi\Auth\Auth;
use \sineverba\domoticzapi\Adapter\Adapter;
use \sineverba\domoticzapi\Client\Client;
use \sineverba\domoticzapi\Exceptions\AuthException;

// Required params
$data = [
    'username'=>'username',
    'password'=>'password'
];
$uri = 'http://www.example.com:8080'; // Uri of Domoticz server

// Initialize
$auth = new Auth($data);
$adapter = new Adapter($auth,$uri);
$client = new Client($adapter);

try {
    // Get Domoticz Version
    $domoticz_version = $client->getDomoticzVersion();
    // Get Devices
    $devices = $client->getDevices();
} catch (AuthException $e) {
    echo $e->getMessage();
}

版本 1

<?php

use \sineverba\domoticzapi;

//Instantiate an api Client to Domoticz
$api = new \sineverba\domoticzapi\Client( 'username' , 'password' );

//Default host is 127.0.0.1:8080, you can change it
$api = new \sineverba\domotizapi\Client ( 'username' , 'password' , 'http://www.example.com:1234' );

//Get list of devices
$devices = $api->getDevice();

//Get list of devices type filtered
$devices = $api->getDevice(null , 'temp');

//Get single device by idx
$device = $api->getDevice($idx);

// Get a single device by name
$device = $api->getDeviceByName($name);

// Get list of user variables
$user_variable = $api->getUserVariable();

// Power on a device. If the device is password-protected, set password as second parameter
$on = $api->powerOn($device , $pin = null);

// Power off a device. If the device is password-protected, set password as second parameter
$off = $api->powerOff($device , $pin = null);

// Toggle a device. If the device is password-protected, set password as second parameter
$toggle = $api->toggle($device , $pin = null);

// Write log
$log = $api->writeLog(string $log);

// Set a user variable
$api->setUserVariable ( $name , $value );

// Delete an user variable
$api->deleteUserVariable ( $idx );

// Set a reading for a counter
$api->setCounterReading($idx,$reading);

// Write text on sensors text
$api->writeText($idx,$text);