Device.class.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * When devices (captors, interruptors...) and their values are declared here
  4. * they can be used by all plugins of yana (maps, aggregators...)
  5. * @author Idleman
  6. * @category Hardware
  7. * @license cc by nc sa
  8. */
  9. class Device extends SQLiteEntity{
  10. const CAPTOR = 1;
  11. const ACTUATOR = 2;
  12. const BOTH = 3;
  13. public $id,$label,$icon,$display,$state,$values,$location,$plugin,$actions,$type,$uid;
  14. protected $TABLE_NAME = 'device';
  15. protected $CLASS_NAME = 'Device';
  16. protected $object_fields =
  17. array(
  18. 'id'=>'key',
  19. 'label'=>'string',
  20. 'icon'=>'string',
  21. 'display'=>'longstring',
  22. 'state'=>'int',
  23. 'values'=>'longstring',
  24. 'location'=>'int',
  25. 'plugin'=>'string',
  26. 'actions'=>'longstring',
  27. 'type'=>'int',
  28. 'uid'=>'int'
  29. );
  30. function __contruct(){
  31. $this->setValues(array());
  32. }
  33. public function setValue($key,$value){
  34. $values = $this->getValues();
  35. $values[$key] = $value;
  36. $this->setValues($values);
  37. }
  38. public function setValues($values){
  39. $this->values = json_encode($values);
  40. }
  41. public function getValues(){
  42. $values = json_decode($this->values,true);
  43. return is_array($values) ? $values : array();
  44. }
  45. public function getValue($key){
  46. $values = $this->getValues();
  47. return $values[$key];
  48. }
  49. }
  50. ?>