Skip to content

Commit

Permalink
[add] easy call
Browse files Browse the repository at this point in the history
  • Loading branch information
chanshige committed Jan 9, 2024
1 parent fa377fb commit bcb379c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Sesame3/4/5 SmartLock Api client.

[![Packagist](https://img.shields.io/badge/packagist-v1.0.0-blue.svg)](https://packagist.org/packages/chanshige/sesame)
[![Packagist](https://img.shields.io/badge/packagist-v2.0.0-blue.svg)](https://packagist.org/packages/chanshige/sesame)
[![CI](https://github.com/chanshige/sesame/actions/workflows/ci.yml/badge.svg)](https://github.com/chanshige/sesame/actions/workflows/ci.yml)

CandyHouseのSesameスマートロックAPIを利用するためのライブラリです。
Expand Down Expand Up @@ -35,6 +35,17 @@ $device = new Device(
### Sesameの状態を取得
```injectablephp
$response = $sesame(new Action\Status($device));
$response = >>>EOF
array (size=6)
'batteryPercentage' => int 100 // バッテリー残量
'batteryVoltage' => float 5.8627565982405 // バッテリー電圧(V)
'position' => int 256 //
'CHSesame2Status' => string 'locked' // locked | unlocked | moved
'timestamp' => int 1703000024 // Sesameの更新時間
'wm2State' => boolean true // wifiモジュールの状態
EOF;
```

### Sesameの履歴を取得
Expand All @@ -43,6 +54,8 @@ $response = $sesame(new Action\History($device, 1, 100));
```

### Sesameの施解錠
APIリクエスト成功は200を返す。bodyは空。(狙い通りに施解錠できたかはStatusで確認する)
WifiModuleが接続されていない場合は404エラーでThrowされます。
```injectablephp
// 鍵をかける
$response = $sesame(new Action\Lock($device, 'chanshigeが鍵かけた'));
Expand Down
26 changes: 26 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Chanshige\SmartLock\Sesame\Http\ResponseInterface;
use Chanshige\SmartLock\Sesame\Interface\ActionInterface;
use Chanshige\SmartLock\Sesame\Interface\ClientInterface;
use Chanshige\SmartLock\Sesame\Interface\DeviceInterface;
use Chanshige\SmartLock\Sesame\Interface\HttpInterface;

use function sprintf;
Expand All @@ -34,6 +35,31 @@ public function __invoke(ActionInterface $action): ResponseInterface
}
}

public function status(DeviceInterface $device): ResponseInterface
{
return $this(new Action\Status($device));
}

public function history(DeviceInterface $device, int $page = 0, int $lg = 50): ResponseInterface
{
return $this(new Action\History($device, $page, $lg));
}

public function lock(DeviceInterface $device, string $note = 'WebAPI'): ResponseInterface
{
return $this(new Action\Lock($device, $note));
}

public function unLock(DeviceInterface $device, string $note = 'WebAPI'): ResponseInterface
{
return $this(new Action\Unlock($device, $note));
}

public function toggle(DeviceInterface $device, string $note = 'WebAPI'): ResponseInterface
{
return $this(new Action\Toggle($device, $note));
}

/**
* @param array<string, mixed> $options
*
Expand Down

0 comments on commit bcb379c

Please sign in to comment.