-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMiBaseDevice.php
More file actions
89 lines (77 loc) · 2.32 KB
/
Copy pathMiBaseDevice.php
File metadata and controls
89 lines (77 loc) · 2.32 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
<?php
/*
* Homegear Xiaomi Smarthome V0.1 for homegear 0.7.x
* (c) Frank Motzkau 2017
*/
include_once 'MiLogger.php';
abstract class MiBaseDevice extends Threaded
{
protected $_sid;
public $_peerId;
protected $_model;
protected $_voltage;
protected $_heartbeat_timeout = 60 * 60;
public function __construct($data)
{
$this->setProperty($data, 'voltage');
}
public abstract function getTypeId();
public function getPeerId() { return $this->_peerId; }
public function setPeerId($peerId) { $this->_peerId = $peerId; }
public function getSid() { return $this->_sid; }
public function getModel() { return $this->_model; }
public function updateData($hg, $data)
{
try
{
// update heartbeat timestamp
$hg->setValue($this->_peerId, 0, 'HEARTBEAT', time());
if ($this->setProperty($data, 'voltage'))
{
$this->_voltage = intval($data->voltage);
$hg->setValue($this->_peerId, 0, 'VOLTAGE', $this->_voltage);
$hg->setValue($this->_peerId, 0, 'LOWBAT', $this->_voltage<2800);
}
}
catch (\Homegear\HomegearException $e)
{
MiLogger::Instance()->exception_log($e, $this->_model);
}
catch (Exception $e)
{
MiLogger::Instance()->exception_log($e, $this->_model);
}
}
public function updateEvent($hg, $event)
{
$result = new stdClass();
$result->cmd = MiConstants::CMD_WRITE;
$result->model = $this->_model;
$result->sid = $this->_sid;
$result->short_id = 0;
$result->data = new stdClass();
return $result;
}
protected function setProperty($mixed, $property)
{
$result = FALSE;
try
{
if (property_exists($mixed, $property))
{
$this->{'_'.$property} = $mixed->$property;
$result = TRUE;
}
}
catch (\Homegear\HomegearException $e)
{
MiLogger::Instance()->exception_log($e);
}
catch (Exception $e)
{
MiLogger::Instance()->exception_log($e);
}
return $result;
}
public function run() { }
}