-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiCube.php
More file actions
83 lines (76 loc) · 2.46 KB
/
MiCube.php
File metadata and controls
83 lines (76 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/*
* Homegear Xiaomi Smarthome for Homegear with PHP 7.4
* (c) Frank Motzkau 2020
*/
include_once 'MiConstants.php';
include_once 'MiBaseDevice.php';
class MiCube extends MiBaseDevice
{
const TYPE_ID = 0x28bc;
public function __construct($config)
{
$this->_model = MiConstants::MODEL_CUBE;
parent::__construct($config);
}
public function getTypeId() { return MiCube::TYPE_ID; }
public function updateData($hg, $data)
{
parent::updateData($hg, $data);
if (property_exists($data, 'rotate'))
{
$args = explode(',', $data->rotate);
$angle = $args[0];
$hg->setValue($this->_peerId, 2, 'ROTATE', intval($angle));
if (intval($angle) < 0)
{
$hg->setValue($this->_peerId, 2, 'ROTATE_LEFT', TRUE);
}
else
{
$hg->setValue($this->_peerId, 2, 'ROTATE_RIGHT', TRUE);
}
if (count($args)>1)
{
$hg->setValue($this->_peerId, 2, 'TIME', intval($args[1]));
}
}
if (property_exists($data, 'status'))
{
switch ($data->status)
{
case 'flip90':
$hg->setValue($this->_peerId, 1, 'FLIP90', TRUE);
break;
case 'flip180':
$hg->setValue($this->_peerId, 1, 'FLIP180', TRUE);
break;
case 'move':
$hg->setValue($this->_peerId, 1, 'MOVE', TRUE);
break;
case 'tap_twice':
$hg->setValue($this->_peerId, 1, 'TAP_TWICE', TRUE);
break;
case 'shake_air':
$hg->setValue($this->_peerId, 1, 'SHAKE_AIR', TRUE);
break;
case 'swing':
$hg->setValue($this->_peerId, 1, 'SWING', TRUE);
break;
case 'alert':
$hg->setValue($this->_peerId, 1, 'SHAKE_AIR', TRUE);
break;
case 'free_fall':
$hg->setValue($this->_peerId, 1, 'SWING', TRUE);
break;
default:
break;
}
}
}
public function updateEvent($hg, $event)
{
parent::updateEvent($hg, $event);
return FALSE;
}
}