| Conditions | 4 |
| Paths | 6 |
| Total Lines | 23 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 20 |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 9 | public function toggle(Action $action) |
||
| 10 | { |
||
| 11 | $device = $action->getDevice(); |
||
| 12 | |||
| 13 | $deviceParams = $device->getParams(); |
||
| 14 | $ch = 0; |
||
| 15 | foreach ($deviceParams as $deviceParam) { |
||
| 16 | list($param,$value) = explode(':', $deviceParam); |
||
| 17 | if ($param == 'channel') { |
||
| 18 | $ch = $value; |
||
| 19 | break; |
||
| 20 | } |
||
| 21 | } |
||
| 22 | |||
| 23 | if (!$ch) { |
||
| 24 | throw new \Exception("Found device with undefined param!"); |
||
| 25 | } |
||
| 26 | |||
| 27 | $actionArgs = json_decode($action->getArguments(), true); |
||
| 28 | exec('/usr/local/bin/noolite -api -'.$actionArgs['state'].'_ch '.$ch); |
||
| 29 | |||
| 30 | return "Switched device ".$actionArgs['state'].', channel '.$ch; |
||
| 31 | } |
||
| 32 | } |
||
| 33 |