Skip to content

Commit e9f5a33

Browse files
committed
Added Thermostat Setpoint device. Added NEST thermostat hardware with get and set heating temperature
1 parent 44cf6af commit e9f5a33

File tree

8 files changed

+301
-10
lines changed

8 files changed

+301
-10
lines changed

src/Client.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,15 @@ public function getHardware() {
219219
return $returnData;
220220
}
221221

222+
public function getHardwareById(int $id) {
223+
foreach ($this->getHardware() as $hardware) {
224+
if ($hardware->getId() === $id) {
225+
return $hardware;
226+
}
227+
}
228+
return false;
229+
}
230+
222231
protected function getLightSwitch(object $deviceData) {
223232
return new Factories\LightSwitchFactory($deviceData);
224233
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace rutgerkirkels\DomoticzPHP\Controllers\Thermostat;
4+
5+
use rutgerkirkels\DomoticzPHP\Controllers\AbstractController;
6+
7+
class Setpoint extends AbstractController
8+
{
9+
/**
10+
* @var \rutgerkirkels\DomoticzPHP\Devices\Thermostat\SetPoint
11+
*/
12+
protected $device;
13+
14+
protected $connector;
15+
16+
public function __construct(\rutgerkirkels\DomoticzPHP\Devices\Thermostat\SetPoint $device)
17+
{
18+
parent::__construct($device);
19+
}
20+
21+
public function set(float $data) {
22+
$set = $this->connector->executeCommand([
23+
'param' => 'udevice',
24+
'idx' => $this->device->getIdx(),
25+
'nvalue' => 0,
26+
'svalue' => $data
27+
]);
28+
29+
if ($set) {
30+
return true;
31+
}
32+
33+
return false;
34+
}
35+
}

src/Devices/AbstractDevice.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Device class
3+
* AbstractDevice class
44
*
55
* @package rutgerkirkels\domoticz_php
66
* @author Rutger Kirkels <rutger@kirkels.nl>a
@@ -39,10 +39,10 @@ abstract class AbstractDevice
3939
protected $protected;
4040
// protected $ShowNotifications;
4141
protected $signalLevel;
42-
// protected $SubType;
42+
protected $subType;
4343
// protected $Temp;
4444
protected $timers;
45-
// protected $Type;
45+
protected $type;
4646
// protected $TypeImg;
4747
// protected $Unit;
4848
protected $used;
@@ -69,11 +69,15 @@ public function __construct(object $deviceData) {
6969
$this->hardwareName = $deviceData->HardwareName;
7070
$this->hardwareType = $deviceData->HardwareType;
7171
$this->hardwareId = $deviceData->HardwareID;
72-
$this->status = $deviceData->Status;
72+
if (property_exists($deviceData,'Status')) {
73+
$this->status = $deviceData->Status;
74+
}
7375
$this->favorite = $deviceData->Favorite == 1 ? true : false;
7476
$this->data = $deviceData->Data;
7577
$this->signalLevel = $deviceData->SignalLevel;
7678
$this->batteryLevel = $deviceData->BatteryLevel;
79+
$this->type = $deviceData->Type;
80+
$this->subType = $deviceData->SubType;
7781
}
7882

7983
/**
@@ -132,5 +136,22 @@ public function getHardwareType()
132136
return $this->hardwareType;
133137
}
134138

139+
/**
140+
* @return mixed
141+
*/
142+
public function getSubType()
143+
{
144+
return $this->subType;
145+
}
146+
147+
/**
148+
* @return mixed
149+
*/
150+
public function getType()
151+
{
152+
return $this->type;
153+
}
154+
155+
135156

136157
}

src/Factories/ControllerFactory.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
use rutgerkirkels\DomoticzPHP\Controllers\Switches\OnOff;
66
use rutgerkirkels\DomoticzPHP\Controllers\Switches\Selector;
7+
use rutgerkirkels\DomoticzPHP\Devices\AbstractDevice;
78
use rutgerkirkels\DomoticzPHP\Devices\Switches\AbstractSwitch;
89
use rutgerkirkels\DomoticzPHP\Controllers\Switches\Dimmer;
10+
use rutgerkirkels\DomoticzPHP\Controllers\Thermostat\SetPoint;
911

1012
/**
1113
* Class ControllerFactory
@@ -18,7 +20,7 @@ class ControllerFactory
1820
*/
1921
protected $device;
2022

21-
public function __construct(AbstractSwitch $device)
23+
public function __construct(AbstractDevice $device)
2224
{
2325
$this->device = $device;
2426
}
@@ -39,6 +41,10 @@ public function get() {
3941
case 'rutgerkirkels\\DomoticzPHP\\Devices\\Switches\\Selector':
4042
return new Selector($this->device);
4143
break;
44+
45+
case 'rutgerkirkels\\DomoticzPHP\\Devices\\Thermostat\\SetPoint':
46+
return new SetPoint($this->device);
47+
break;
4248
}
4349
}
4450
}

src/Factories/HardwareFactory.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44

55

66
use rutgerkirkels\DomoticzPHP\Hardware\General;
7+
use rutgerkirkels\DomoticzPHP\Hardware\Nest;
78

9+
/**
10+
* Class HardwareFactory
11+
* @package rutgerkirkels\DomoticzPHP\Factories
12+
*/
813
class HardwareFactory
914
{
1015
/**
@@ -26,6 +31,12 @@ class HardwareFactory
2631
*/
2732
protected $devices;
2833

34+
/**
35+
* HardwareFactory constructor.
36+
* @param int $id
37+
* @param string $name
38+
* @param string|null $type
39+
*/
2940
public function __construct(int $id, string $name, string $type = null)
3041
{
3142
$this->id = $id;
@@ -40,9 +51,13 @@ public function addDevice($device) {
4051
public function get() {
4152
switch ($this->type) {
4253

54+
case 'Nest Thermostat/Protect':
55+
$hardware = new Nest($this->id, $this->name, $this->devices, $this->type);
56+
break;
57+
4358
default:
44-
$hardware = new General($this->id, $this->name, $this->type);
45-
$hardware->setDevices($this->devices);
59+
$hardware = new General($this->id, $this->name, $this->devices, $this->type);
60+
4661
}
4762

4863
return $hardware;

src/Hardware/AbstractHardware.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ abstract class AbstractHardware
2424
*/
2525
protected $devices;
2626

27-
public function __construct(int $id, string $name, string $type = null)
27+
public function __construct(int $id, string $name, array $devices, string $type = null)
2828
{
2929
$this->id = $id;
3030
$this->name =$name;
31+
$this->devices = $devices;
3132
$this->type = $type;
3233
}
3334

@@ -95,5 +96,12 @@ public function setDevices(array $devices): void
9596
$this->devices = $devices;
9697
}
9798

98-
99+
public function getDeviceByIdx(int $idx) {
100+
foreach ($this->devices as $key => $device) {
101+
if ($device->getIdx() === $idx) {
102+
return $this->devices[$key];
103+
}
104+
}
105+
return false;
106+
}
99107
}

src/Hardware/General.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
namespace rutgerkirkels\DomoticzPHP\Hardware;
44

5-
5+
/**
6+
* General Hardware class
7+
* @package rutgerkirkels\DomoticzPHP\Hardware
8+
*/
69
class General extends AbstractHardware implements HardwareInterface
710
{
811

0 commit comments

Comments
 (0)