Exemple #1
0
 def get(self, port=None, cfg=None, timeout=0):
     bus = owfs.get_bus(self.owfs_bus)
     if not bus: return None
     try:
         value = bus.read(self.path, 'temperature')
         if not value:
             raise Exception('can not obtain value')
         return {'temperature': value}
     except:
         return None
     finally:
         bus.release()
Exemple #2
0
 def set(self, port=None, data=None, cfg=None, timeout=0):
     owfs_bus = self.owfs_bus
     path = self.path
     if cfg:
         if 'owfs' in cfg: owfs_bus = cfg['owfs']
         if 'path' in cfg: path = cfg['path']
     bus = owfs.get_bus(owfs_bus)
     if not bus: return False
     try:
         return bus.write(path, 'PIO', data)
     except:
         return False
     finally:
         bus.release()
Exemple #3
0
 def get(self, port=None, cfg=None, timeout=0):
     owfs_bus = self.owfs_bus
     path = self.path
     if cfg:
         if 'owfs' in cfg: owfs_bus = cfg['owfs']
         if 'path' in cfg: path = cfg['path']
     bus = owfs.get_bus(owfs_bus)
     if not bus: return None
     try:
         return int(bus.read(path, 'PIO'))
     except:
         return None
     finally:
         bus.release()
Exemple #4
0
 def __init__(self, **kwargs):
     self.owfs_bus = self.phi_cfg.get('owfs')
     self.path = self.phi_cfg.get('path')
     if not self.owfs_bus or not self.path:
         self.log_error('owfs/path not specified')
         self.ready = False
     else:
         bus = owfs.get_bus(self.owfs_bus)
         if bus:
             bus.release()
         else:
             self.log_error('unable to get owfs bus {}'.format(
                 self.owfs_bus))
             self.ready = False
Exemple #5
0
 def test(self, cmd=None):
     if cmd == 'self':
         bus = owfs.get_bus(self.owfs_bus)
         if not bus: return 'FAILED'
         try:
             s = bus.read(self.path, 'temperature')
             if not s: return 'FAILED'
         except:
             return 'FAILED'
         finally:
             bus.release()
         return 'OK'
     elif cmd == 'get':
         return self.get()
     else:
         return {'get': 'Get value'}
Exemple #6
0
 def get(self, port=None, cfg=None, timeout=0):
     owfs_bus = self.owfs_bus
     path = self.path
     attr = self.attr
     if cfg:
         if 'owfs' in cfg: owfs_bus = cfg['owfs']
         if 'path' in cfg: path = cfg['path']
         if 'attr' in cfg: attr = cfg['attr']
     bus = owfs.get_bus(owfs_bus)
     if not bus: return None
     try:
         value = bus.read(path, attr)
         if not value:
             raise Exception('can not obtain value')
         return {attr: value}
     except:
         return None
     finally:
         bus.release()
Exemple #7
0
 def test(self, cmd=None):
     if cmd == 'self':
         if self.owfs_bus:
             bus = owfs.get_bus(self.owfs_bus)
             if not bus: return 'FAILED'
             try:
                 if self.path:
                     if not bus.read(self.path, 'PIO'): return 'FAILED'
             except:
                 return 'FAILED'
             finally:
                 bus.release()
         return 'OK'
     elif cmd == 'get':
         return str(self.get())
     else:
         return {
             'get': 'Get value (if owfs and path are defined in PHI config)'
         }
Exemple #8
0
 def test(self, cmd=None):
     if cmd == 'self':
         if self.owfs_bus:
             bus = owfs.get_bus(self.owfs_bus)
             if not bus: return 'FAILED'
             try:
                 if self.path:
                     a = self.attr if self.attr else 'type'
                     s = bus.read(self.path, a)
                     if not s: return 'FAILED'
             except:
                 return 'FAILED'
             finally:
                 bus.release()
         return 'OK'
     elif cmd == 'get':
         return self.get()
     else:
         return {
             'get':
             'Get value (if owfs, path and attr are defined in PHI config)'
         }
Exemple #9
0
 def set(self, port=None, data=None, cfg=None, timeout=0):
     if port:
         try:
             _port = int(port)
         except:
             return False
     owfs_bus = self.owfs_bus
     path = self.path
     if cfg:
         if 'owfs' in cfg: owfs_bus = cfg['owfs']
         if 'path' in cfg: path = cfg['path']
     bus = owfs.get_bus(owfs_bus)
     if not bus: return False
     try:
         if port:
             return bus.write(path, 'PIO.{}'.format(_port - 1), data)
         else:
             return bus.write(path, 'PIO.ALL',
                              ','.join([str(x) for x in data]))
     except:
         return False
     finally:
         bus.release()
Exemple #10
0
 def get(self, port=None, cfg=None, timeout=0):
     if port:
         try:
             _port = int(port)
         except:
             return False
     owfs_bus = self.owfs_bus
     path = self.path
     if cfg:
         if 'owfs' in cfg: owfs_bus = cfg['owfs']
         if 'path' in cfg: path = cfg['path']
     bus = owfs.get_bus(owfs_bus)
     if not bus: return None
     try:
         if port:
             return int(bus.read(path, 'PIO.{}'.format(_port - 1)))
         else:
             v = bus.read(path, 'PIO.ALL').split(',')
             return {str(a + 1): int(v[a]) for a in range(8)}
     except:
         return None
     finally:
         bus.release()