Ejemplo n.º 1
0
 def __init__(self,
              event_callback=None,
              persistence=False,
              persistence_file='mysensors.pickle',
              protocol_version='1.4'):
     """Setup Gateway."""
     self.queue = Queue()
     self.lock = threading.Lock()
     self.event_callback = event_callback
     self.sensors = {}
     self.metric = True  # if true - use metric, if false - use imperial
     self.debug = False  # if true - print all received messages
     self.persistence = persistence  # if true - save sensors to disk
     self.persistence_file = persistence_file  # path to persistence file
     self.persistence_bak = '{}.bak'.format(self.persistence_file)
     if persistence:
         self._safe_load_sensors()
     self.protocol_version = float(protocol_version)
     if 1.5 <= self.protocol_version < 2.0:
         _const = import_module('mysensors.const_15')
     elif self.protocol_version >= 2.0:
         _const = import_module('mysensors.const_20')
     else:
         _const = import_module('mysensors.const_14')
     self.const = _const
     self.ota = OTAFirmware(self.sensors, self.const)