Skip to content

Commit b88de1a

Browse files
committed
Fixed bug in Client::getDeviceByIdx. Added option to get available method for instantiated controller.
1 parent 2d4e73e commit b88de1a

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

src/Client.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,27 @@ public function getDeviceByIdx(int $idx) {
123123
switch ($receivedDevice->Type) {
124124

125125
case 'Light/Switch':
126-
return $this->getLightSwitch($receivedDevice)->get();
126+
return (new Factories\LightSwitchFactory($receivedDevice))->get();
127127
break;
128128

129129
case 'Lighting 2':
130-
return $this->getLighting2($receivedDevice)->get();
130+
return (new Lighting2Factory($receivedDevice))->get();
131131
break;
132132

133133
case 'Temp + Humidity':
134-
return $this->getTempAndHumidity($receivedDevice)->get();
134+
return (new TempAndHumidityFactory($receivedDevice))->get();
135135
break;
136136

137137
case 'Thermostat':
138-
return $this->getThermostat($receivedDevice)->get();
138+
return (new ThermostatFactory($receivedDevice))->get();
139+
break;
140+
141+
case 'Usage':
142+
return (new UsageFactory($receivedDevice))->get();
139143
break;
140144

141145
default:
146+
return null;
142147

143148
}
144149
}

src/Controllers/AbstractController.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ public function __construct(AbstractDevice $device)
2020
}
2121

2222
/**
23-
* @return string
23+
* @return array
2424
*/
25-
public function getStatus() {
26-
return $this->device->getStatus();
27-
}
28-
29-
/**
30-
* @return \DateTime
31-
*/
32-
public function getLastUpdate() {
33-
return $this->device->getLastUpdate();
25+
public function getMethods() {
26+
$class = new \ReflectionClass(get_class($this));
27+
$availableMethods = [];
28+
foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
29+
if ($method->name !== '__construct') {
30+
$availableMethods[] = $method->name;
31+
}
32+
}
33+
return $availableMethods;
3434
}
3535
}

src/Controllers/ControllerInterface.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@
88
*/
99
interface ControllerInterface
1010
{
11-
public function getStatus();
1211

1312
}

0 commit comments

Comments
 (0)