| Conditions | 4 |
| Paths | 6 |
| Total Lines | 26 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 20 |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | public function analyze(Action $action) |
||
| 11 | { |
||
| 12 | $varService = $this->getContainer()->get('vars'); |
||
| 13 | |||
| 14 | $params = $action->getDevice()->getParams(); |
||
| 15 | |||
| 16 | /** @var Variable $variable */ |
||
| 17 | $variable = false; |
||
| 18 | |||
| 19 | foreach ($params as $param) { |
||
| 20 | list($p,$v) = explode(':', $param); |
||
| 21 | if ($p=='variable') { |
||
| 22 | $variable = $this->getDoctrine()->getManager()->getRepository('AppBundle:Variable')->findOneBy(['name'=>$v]); |
||
| 23 | break; |
||
| 24 | } |
||
| 25 | } |
||
| 26 | |||
| 27 | if (!$variable) { |
||
| 28 | throw new \Exception("Sensor variable for device '".$action->getDevice()->getName()."' not found :("); |
||
| 29 | } |
||
| 30 | |||
| 31 | $lastValue = $varService->getLastValue($variable); |
||
| 32 | /** @var \DateTime $lastPresence */ |
||
| 33 | $lastPresence = $lastValue['df']; |
||
| 34 | $varService->set('room.lastPresence', time() - $lastPresence->getTimestamp()); |
||
| 35 | } |
||
| 36 | } |
||
| 37 |