コード例 #1
0
ファイル: SensorController.php プロジェクト: rybus/mogette-ui
 /**
  * Import a new Sensor after checking that this is a new one (sensor list page).
  *
  * @param string     $rom        the ROM address of the sensor
  * @param SensorType $sensorType the type of sensor (i.e : thermometer, humidity sensory, light sensor)
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function importSensorAction($rom, SensorType $sensorType)
 {
     $sensor = new Sensor();
     $sensor->setName("Sensor " . time());
     $sensor->setType($sensorType);
     $sensor->setRom($rom);
     $sensor->setLastSeen(new \DateTime());
     $entityManager = $this->getDoctrine()->getManager();
     $entityManager->persist($sensor);
     $entityManager->flush($sensor);
     return $this->redirect($this->generateUrl('weather_sensors_edit', ['id' => $sensor->getId()]));
 }
コード例 #2
0
ファイル: SensorManager.php プロジェクト: rybus/mogette-ui
 /**
  * Transform raw data from Arduino device into Sensor objects
  *
  * @param $json
  *
  * @return Sensor
  */
 public function transform($json)
 {
     $sensor = new Sensor();
     if ($json->type == 'thermometer') {
         $type = $this->getType(self::THERMOMETRE_TYPE);
     } else {
         if ($json->type == 'humidity_sensor') {
             $type = $this->getType(self::HUMIDITY_SENSOR_TYPE);
         }
     }
     $sensor->setType($type);
     $sensor->setRom($json->rom);
     $sensor->setLastSeen(new \DateTime());
     return $sensor;
 }