Skip to content

Commit

Permalink
1.28.28
Browse files Browse the repository at this point in the history
- updated Devices class to use the same helper method: getDeviceIdByIdentifier
- updated README and removed content which exists in wiki
- updated wiki pages
- put into next release
  • Loading branch information
PJanisio committed Jun 24, 2024
1 parent 961ee63 commit b8bbbf4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 47 deletions.
47 changes: 8 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@ eWeLink API PHP is a connector for Sonoff / eWeLink devices. This library allows

## Current features

- log-in and authorization to ewelink APP via web or websockets
- get devices list with all or chosen parameters
- saving devices and other outputs from API to .json
- search for any value of parameter for each device (f.e switch status, productName, MAC etc.)
- set any parameter/state of device
- check if device has MultiChannel support
- set parameter for Multichannel devices
- check if device is Online
- get all devices list with their parameters using **deviceId** or **deviceName** from ewelink app
- saving devices data and other outputs from API to **.json**
- search for **any value** of each device (f.e switch status, productName, MAC etc.)
- set any parameter/state of device using **HTTP gateway** or **websockets**
- set parameter for **multi-channel** devices (like 4CH Pro)
- debug all requests and responses to debug.log
- use Websocket connection to get and update parameters

## Documentation

Go to [Wiki Pages](https://github.com/PJanisio/ewelinkApiPhp/wiki) to install and use methods.
Go to [Wiki Pages](https://github.com/PJanisio/ewelinkApiPhp/wiki) to get started read about possible methods.

## Example

Expand Down Expand Up @@ -63,33 +59,6 @@ $token = new Token($httpClient);

```

## Structure

``` rust
ewelinkApiPhp/
├── src/
│ ├── Constants.php
│ ├── Devices.php
│ ├── Home.php
│ ├── HttpClient.php
│ ├── Token.php
│ └── Utils.php
│ └── WebSocketsClient.php
├── autoloader.php
└── index.php
```

All classes are located in src directory.

Index.php works as a gateway to API and also as a debug for all available methods.

.json files outputs will be saved by default in project_root. You can define directory in Constants.php

## More inside info about current development
## Tech info

- main branch when commited used to be operative.
- enable DEBUG = 1; in Constants to log every get and postRequest with output and parameters to **debug.log**
- branch **websockets** will be not maintened anymore
- index.php is a quasi-test file which helps me to check all methods and it is also a great example
Visit wiki page for devs: [devs-wiki](https://github.com/PJanisio/ewelinkApiPhp/wiki/Developers)
17 changes: 9 additions & 8 deletions src/Devices.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,17 @@ public function setDeviceStatus($identifier, $params) {
* @return bool True if the device is online, false otherwise.
*/
public function isOnline($identifier) {
$this->fetchDevicesData();
$deviceList = $this->getDevicesList();

foreach ($deviceList as $name => $device) {
if ($device['deviceid'] === $identifier or $name === $identifier) {
return $device['online'];
$deviceId = $this->getDeviceIdByIdentifier($identifier);
if (!$deviceId) {
return false;
}
if ($this->devicesData && isset($this->devicesData['thingList'])) {
foreach ($this->devicesData['thingList'] as $device) {
if ($device['itemData']['deviceid'] === $deviceId) {
return $device['itemData']['online'] == 1;
}
}
}

return false;
}

Expand Down Expand Up @@ -514,4 +516,3 @@ public function forceUpdateDevice($identifier, $params, $sleepSec = 3) {
return $updatedParams;
}
}
?>

0 comments on commit b8bbbf4

Please sign in to comment.