Skip to content

Commit

Permalink
Update, set minimum version php 7.4
Browse files Browse the repository at this point in the history
bugfixes get current state
split code to models, service and use client factory
  • Loading branch information
jpvdw86 committed Apr 10, 2023
1 parent 16c036f commit 3ee92d9
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 17 deletions.
44 changes: 42 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
# Balboa spa / Jacuzzi API wrapper

This is a reverse engineered PHP API of the balboa spa module.
This is a PHP Library for the Balboa SPA API. Its reverse engineered en converted to PHP library.
It is not an official API and no support on this library !

Project is still under development..
Example code

```php
$username = 'XXXX';
$password = 'XXXX';

$clientFactory = new \Jpvdw\Balboa\ClientFactory();
$client = $clientFactory->create($username,$password);

// Check capabilities
// Check Model/Device.php for all options
echo $device = $client->getDevice();
echo $device->hasPump0() ? 'Yes' : 'No'.PHP_EOL;
echo $device->hasPump1() ? 'Yes' : 'No'.PHP_EOL;
echo $device->hasLight1() ? 'Yes' : 'No'.PHP_EOL;
echo $device->hasBlower() ? 'Yes' : 'No'.PHP_EOL;


// Get current state data
// Check Model/Panel.php for all options
$panelData = $client->getPanel();
echo $panel->getTemperature().PHP_EOL;
echo $panel->getTargetTemperature().PHP_EOL;

// Control buttons
// Check Service/Buttons.php for al options
$buttons = $client->getButtonActions();
echo $buttons->toggleLights() ? 'done': 'error'.PHP_EOL;
echo $buttons->togglePump1() ? 'done': 'error'.PHP_EOL;
echo $buttons->toggleBlowers() ? 'done': 'error'.PHP_EOL;
echo $buttons->togglePump2() ? 'done': 'error'.PHP_EOL;


// Control Temperature
// Check Service/Temperature.php for al options
$temperature = $client->getTemperatureActions();
echo $temperature->setCelsius(35) ? 'done': 'error'.PHP_EOL;
echo $temperature->setFahrenheit(60) ? 'done': 'error'.PHP_EOL;

``
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"require": {
"php": ">=7.4",
"ext-curl": "*",
"ext-json": "*"
"ext-json": "*",
"ext-mbstring": "*"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Api {

public static function getBearerTokenAndDeviceId(string $userName, string $password): array
{
$postFields = json_encode(["username" => $userName, "password" => $password], JSON_THROW_ON_ERROR);
$postFields = json_encode(["username" => $userName, "password" => $password]);

$headers = [
'User-Agent: BWA/4.1 (com.createch-group.balboa; build:10; iOS 13.3.0) Alamofire/4.8.1',
Expand All @@ -27,7 +27,7 @@ public static function getBearerTokenAndDeviceId(string $userName, string $passw
}
curl_close($ch);

$result = json_decode($result, true, 512, JSON_THROW_ON_ERROR);
$result = json_decode($result, true);
if(!isset($result['token'], $result['device']['device_id'])){
throw new \RuntimeException('Login Failed');
}
Expand Down
7 changes: 5 additions & 2 deletions src/Helper/Decoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

class Decoder {

public static function decode($message){
$message = base64_decode(utf8_encode($message));
public static function decode($message): array
{
$message = mb_convert_encoding($message, 'UTF-8', 'ISO-8859-1');
$message = base64_decode($message);

$output = [];
$output[0] = 126;
$max = strlen($message);
Expand Down
4 changes: 0 additions & 4 deletions src/Model/Device.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ class Device
{
private array $deviceArray;

/**
* DeviceDecoder constructor.
* @param $message
*/
public function __construct($message)
{
$this->deviceArray = Decoder::decode($message);
Expand Down
7 changes: 1 addition & 6 deletions src/Model/Panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ public function getFilterMode(): string
}
}

/**
* function is not defined
*/
public function getAccessibilityType(): string
{
$modeCode = $this->panelArray[14] & 48;
Expand All @@ -91,8 +88,7 @@ public function getAccessibilityType(): string
}

/**
* Time scale on 24 hous or 12 hour scale
* @return bool
* Time scale on 24 hour or 12 hour scale
*/
public function is24TimeScale(): bool
{
Expand Down Expand Up @@ -272,6 +268,5 @@ public function getWifiState(): string
case 80:
return "panel";
}

}
}

0 comments on commit 3ee92d9

Please sign in to comment.