-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiGenericSwitch.php
More file actions
127 lines (118 loc) · 4.34 KB
/
MiGenericSwitch.php
File metadata and controls
127 lines (118 loc) · 4.34 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/*
* Homegear Xiaomi Smarthome for Homegear with PHP 7.4
* (c) Frank Motzkau 2020
*/
include_once 'MiConstants.php';
include_once 'MiBaseDevice.php';
class MiGenericSwitch extends MiBaseDevice
{
private $_channels;
private $_type_id;
public function __construct($config, $model)
{
$this->_model = $model;
switch ($model)
{
case MiConstants::MODEL_CTRL_NEUTRAL1:
case MiConstants::MODEL_CTRL_NEUTRAL1_AQ1:
$this->_type_id = 0x28c0;
$this->_channels = 1;
break;
case MiConstants::MODEL_86SW1:
case MiConstants::MODEL_SENSOR_86SW1:
case MiConstants::MODEL_SENSOR_86SW1_AQ1:
$this->_type_id = 0x28c1;
$this->_channels = 1;
break;
case MiConstants::MODEL_CTRL_LN1:
case MiConstants::MODEL_CTRL_LN1_AQ1:
$this->_type_id = 0x28c2;
$this->_channels = 1;
break;
case MiConstants::MODEL_CTRL_NEUTRAL2:
case MiConstants::MODEL_CTRL_NEUTRAL2_AQ1:
$this->_type_id = 0x28d0;
$this->_channels = 2;
break;
case MiConstants::MODEL_86SW2:
case MiConstants::MODEL_SENSOR_86SW2:
case MiConstants::MODEL_SENSOR_86SW2_AQ1:
case MiConstants::MODEL_REMOTE_B286ACN01:
$this->_type_id = 0x28d1;
$this->_channels = 2;
break;
case MiConstants::MODEL_CTRL_LN2:
case MiConstants::MODEL_CTRL_LN2_AQ1:
$this->_type_id = 0x28d2;
$this->_channels = 2;
break;
default:
$this->_model = MiConstants::MODEL_UNKNOWN;
$this->_channels = 0;
$this->_type_id = 0x0000;
}
parent::__construct($config);
}
public function getTypeId() { return $this->_type_id; }
public function updateData($hg, $data)
{
parent::updateData($hg, $data);
if (property_exists($data, 'dual_channel'))
{
if ($data->dual_channel == 'both_click')
{
$hg->setValue($this->_peerId, $this->_channels+1, 'PRESS_BOTH', TRUE);
}
}
else
{
for ($i=0; $i<$this->_channels; $i++)
{
$channel = 'channel_'.$i;
if (property_exists($data, $channel))
{
switch ($data->{$channel})
{
case 'click':
$hg->setValue($this->_peerId, $i+1, 'PRESS_SHORT', TRUE);
break;
case 'long_click_press':
$hg->setValue($this->_peerId, $i+1, 'PRESS_LONG', TRUE);
break;
case 'long_click_release':
$hg->setValue($this->_peerId, $i+1, 'PRESS_LONG_RELEASE', TRUE);
break;
case 'double_click':
$hg->setValue($this->_peerId, $i+1, 'PRESS_DOUBLE', TRUE);
break;
case 'both_click':
$hg->setValue($this->_peerId, $i+1, 'PRESS_BOTH', TRUE);
break;
case 'on':
$hg->setValue($this->_peerId, $i+1, 'STATE', TRUE);
break;
case 'off':
$hg->setValue($this->_peerId, $i+1, 'STATE', FALSE);
break;
default:
break;
}
}
}
}
}
public function updateEvent($hg, $event)
{
$result = FALSE;
if (($event['TYPE'] == 'event')
&& ($event['PEERID'] == $this->_peerId)
&& ($event['VARIABLE'] == 'STATE'))
{
$result = parent::updateEvent($hg, $event);
$channel = 'channel_'.(intval(event['PEERCHANNEL'])-1);
$result->data->{$channel} = boolval($event['VALUE']) ? 'on' : 'off';
}
return $result;
}
}