Skip to content

Commit 4ef1be4

Browse files
committed
UPDATE add motion sensor
1 parent 56aaa30 commit 4ef1be4

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

src/Models/Cube.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@
88
* @package Aqara\Models
99
*
1010
* @property string $status
11-
* @property int $rotateDegrees
11+
* @property int $rotateDegrees
1212
*/
1313
class Cube extends Subdevice
1414
{
15+
const STATUS_MOVE = 'move';
16+
const STATUS_FLIP_90 = 'flip90';
17+
const STATUS_FLIP_180 = 'flip180';
18+
const STATUS_ROTATE = 'rotate';
19+
const STATUS_SHAKE_AIR = 'shake_air';
20+
const STATUS_TAP_TWICE = 'tap_twice';
21+
1522
public function __construct(array $attributes = [])
1623
{
1724
$this->type = 'cube';

src/Models/Gateway.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function handleMessage($response)
7979
break;
8080
case 'motion':
8181
case 'sensor_motion.aq2':
82-
// TODO: motion
82+
$subDevice = new Motion(['sid' => $response->sid]);
8383
break;
8484
case 'sensor_ht':
8585
case 'weather.v1':

src/Models/Motion.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Aqara\Models;
4+
5+
/**
6+
* Class Motion
7+
*
8+
* @package Aqara\Models
9+
*
10+
* @property string $status
11+
*/
12+
class Motion extends Subdevice
13+
{
14+
const MOTION = 'motion';
15+
16+
public function __construct(array $attributes = [])
17+
{
18+
$this->type = 'motion';
19+
parent::__construct($attributes);
20+
}
21+
22+
/**
23+
* @param array $state
24+
*/
25+
public function handleState($state)
26+
{
27+
if (!is_array($state)) {
28+
return;
29+
}
30+
31+
$this->status = $state['status'] ?? null;
32+
33+
$this->emit('update');
34+
}
35+
}

0 commit comments

Comments
 (0)