Esempio n. 1
0
def createNetwork(options, log=None, autostart=True, kvals=True):
    network = ZWaveNetwork(options, log=None)
    time_started = 0
    for i in range(0, 100):
        if network.state >= network.STATE_AWAKED:
            break
        else:
            time_started += 1
            time.sleep(1.0)
    if network.state < network.STATE_AWAKED:
        print("Network is not awake but continue anyway")

    for i in range(0, 300):
        if network.state >= network.STATE_READY:
            print("home ID {}".format(home_id))
            break
        else:
            sys.stdout.write(".")
            time_started += 1
            #sys.stdout.write(network.state_str)
            #sys.stdout.write("(")
            #sys.stdout.write(str(network.nodes_count))
            #sys.stdout.write(")")
            #sys.stdout.write(".")
            sys.stdout.flush()
            time.sleep(1.0)

    if not network.is_ready:
        print("network is not ready but start anyway")
    network.start()
    return network
Esempio n. 2
0
def init_zwave_network(device=None,
                       config_path=None,
                       user_path=None,
                       debug=False):
    options = ZWaveOption(device,
                          config_path=config_path,
                          user_path=user_path,
                          cmd_line="")
    options.set_log_file(os.path.join(user_path, "OZW_Log.log"))
    options.set_append_log_file(False)
    options.set_console_output(False)
    options.set_save_log_level('Info')  # ('Info' if debug else 'Warning')
    options.set_logging(True)
    options.lock()

    zwave_network = ZWaveNetwork(options, autostart=False)

    # We connect to the louie dispatcher
    dispatcher.connect(zwave_network_started,
                       ZWaveNetwork.SIGNAL_NETWORK_STARTED)
    dispatcher.connect(zwave_network_failed,
                       ZWaveNetwork.SIGNAL_NETWORK_FAILED)
    dispatcher.connect(zwave_network_ready, ZWaveNetwork.SIGNAL_NETWORK_READY)

    return zwave_network
Esempio n. 3
0
    def setup(self, updateCallback):
        dispatcher.connect(self.onNetworkReady, ZWaveNetwork.SIGNAL_NETWORK_READY)
        dispatcher.connect(self.onNetworkStart, ZWaveNetwork.SIGNAL_NETWORK_STARTED)
        dispatcher.connect(self.onNetworkFailed, ZWaveNetwork.SIGNAL_NETWORK_FAILED)

        # TODO: make udev.symlink rule to a specific port (USB0/1)
        # Uncomment this to run on PC (remember to update the zwave config path)
        #options = ZWaveOption("/dev/ttyUSB0", \
        #  config_path="/home/<USER>/software/python-openzwave-0.2.6/openzwave/config", \
        options = ZWaveOption("/dev/serial/by-path/platform-bcm2708_usb-usb-0:1.2:1.0-port0", \
          config_path="/home/pi/software/python-openzwave-0.2.6/openzwave/config", \
          user_path=".", cmd_line="")
        options.set_append_log_file(False)
        options.set_console_output(False)
        options.set_save_log_level('Debug')
        options.set_poll_interval(30);
        options.set_suppress_value_refresh(False)
        options.addOptionBool("AssumeAwake", True)
        options.set_logging(False)
        options.lock()
        self.network = ZWaveNetwork(options, autostart=False)
        self.onDeviceUpdateCallback = updateCallback
        self.network.start()
        self.addedConnections = False
        Timer(2*60, self.setupConnections).start()
Esempio n. 4
0
    def network_init(self):
        """
            Zwave network initialization.
            Terminate program if initialization failed.
        """
        logging.basicConfig(level=logging.INFO)
        logger = logging.getLogger('openzwave')

        # option initialization, abort if initialization failed
        try:
            options = ZWaveOption(self.device, \
             config_path="../openzwave/config", \
             user_path=".", cmd_line="")
            options.set_log_file(self.log_file)
            options.set_append_log_file(self.write_file)
            options.set_console_output(self.output_console)
            options.set_save_log_level(self.log)
            options.set_logging(False)
            options.lock()
        except Exception as e:
            print(
                "Zwave initialization failed! \nPlease listen the USB port of zwave stick!"
            )
            print(e)
            sys.exit(-1)

        # create a network instance
        self.network = ZWaveNetwork(options, log=None)
 def test_000_network_start_stop(self):
     self.driver_ready = False
     self.driver_removed = False
     self.options = ZWaveOption(device=self.device, user_path=self.userpath)
     self.options.set_log_file("OZW_Log.log")
     self.options.set_append_log_file(False)
     self.options.set_console_output(False)
     self.options.set_save_log_level("Debug")
     self.options.set_logging(True)
     self.options.lock()
     dispatcher.connect(self.driver_ready_message,
                        ZWaveNetwork.SIGNAL_DRIVER_READY)
     dispatcher.connect(self.driver_removed_message,
                        ZWaveNetwork.SIGNAL_DRIVER_REMOVED)
     self.network = ZWaveNetwork(self.options)
     for i in range(0, SLEEP):
         if self.network.state >= self.network.STATE_AWAKED:
             break
         else:
             time.sleep(1.0)
     self.assertTrue(self.driver_ready)
     self.network.stop()
     for i in range(0, SLEEP):
         if self.network.state == self.network.STATE_STOPPED:
             break
         else:
             time.sleep(1.0)
     self.assertEqual(self.network.state, self.network.STATE_STOPPED)
Esempio n. 6
0
  def startup_zwave(self, args={}):
    ffEvent(self._id,{'zwave':'starting_up'})
    zwaveSetup = ZWaveOption(self._port, self._configFile)
    zwaveSetup.set_console_output(False)
    zwaveSetup.lock()
    network = ZWaveNetwork(zwaveSetup, autostart=False)
    network.start()

    stdout.write("Waking up Zwave (This can take up to 5 minutes)")
    for i in xrange(3):
      if network.state >= network.STATE_AWAKED:
        logging.info('Zwave Network Awake')
        break
      else:
        stdout.write(".")
        stdout.flush()
        sleep(1)

    for x in xrange(3):
      if network.state >= network.STATE_READY:
        ffEvent(self._id,{'zwave':'network_ready'})
      else:
        stdout.write(".")
        stdout.flush()
        sleep(.5)

    return network
Esempio n. 7
0
def start_zwave():
    network = ZWaveNetwork(options, log=None)
    print("Starting event registration:")
    dispatcher.connect(louie_network_started,
                       ZWaveNetwork.SIGNAL_NETWORK_STARTED)
    print("First evenbt registered")
    dispatcher.connect(louie_network_resetted,
                       ZWaveNetwork.SIGNAL_NETWORK_RESETTED)
    print("Second evenbt registered")
    dispatcher.connect(louie_network_ready, ZWaveNetwork.SIGNAL_NETWORK_READY)
    print("Event registration done")

    time_started = 0
    print("------------------------------------------------------------")
    print("Waiting for network awaked : ")
    print("------------------------------------------------------------")
    for i in range(0, 300):
        if network.state >= network.STATE_AWAKED:
            print("Network initialization done")
            print("Memory use : {} Mo".format(
                (resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1024.0)))
            break
        else:
            sys.stdout.write(".")
            sys.stdout.flush()
            time_started += 1
            time.sleep(1.0)
            print("Network is not awake " + str(i))
    if network.state < network.STATE_AWAKED:
        print(".")
        print("Network is not awake but continue anyway")
    print("End of start")
    return network
Esempio n. 8
0
    def start(self,
              controllerDevice,
              config_path="./config",
              user_path=".",
              cmd_line=""):
        self.options = ZWaveOption(controllerDevice, config_path, user_path,
                                   cmd_line)
        self.options.set_log_file("OZW_Log.log")
        self.options.set_append_log_file(False)
        self.options.set_console_output(False)
        self.options.set_save_log_level("None")
        self.options.set_logging(True)
        self.options.lock()

        dispatcher.connect(self.zwave_network_ready,
                           ZWaveNetwork.SIGNAL_NETWORK_READY)
        dispatcher.connect(self.zwave_network_started,
                           ZWaveNetwork.SIGNAL_NETWORK_STARTED)
        dispatcher.connect(self.zwave_network_failed,
                           ZWaveNetwork.SIGNAL_NETWORK_FAILED)
        dispatcher.connect(self.zwave_node_update, ZWaveNetwork.SIGNAL_NODE)
        dispatcher.connect(self.zwave_value_update, ZWaveNetwork.SIGNAL_VALUE)

        self.network = ZWaveNetwork(self.options, autostart=False)
        self.network.start()
Esempio n. 9
0
    def run(self):
        # Connect to mqtt
        self.setup_mqtt()

        # Create a network object
        self.network = ZWaveNetwork(options, autostart=False)

        # Hook Ctrl-C to cleanly shutdown.
        # This ensures openzwave persists its state to the zwcfg xml file.
        def signal_handler(signal, frame):
            default_logger.info("Stopping zwave network")
            self.network.stop()
            default_logger.info("Stopping mqtt client")
            self.client.disconnect()

        signal.signal(signal.SIGINT, signal_handler)
        signal.signal(signal.SIGTERM, signal_handler)

        dispatcher.connect(self.network_started,
                           ZWaveNetwork.SIGNAL_NETWORK_STARTED)
        dispatcher.connect(self.network_failed,
                           ZWaveNetwork.SIGNAL_NETWORK_FAILED)
        dispatcher.connect(self.network_ready,
                           ZWaveNetwork.SIGNAL_AWAKE_NODES_QUERIED)

        self.network.start()

        self.client.loop_forever()
        default_logger.info("Finished")
Esempio n. 10
0
    def __init__(self):
        ###### options needed for python openzwave library like config files path, logging,
        device = configpi.interface
        options = ZWaveOption(
            device,
            config_path="/home/pi/IoTLab/python-openzwave/openzwave/config",
            user_path=".",
            cmd_line="")
        options.set_log_file("OZW.log")
        options.set_append_log_file(False)
        options.set_console_output(False)
        options.set_save_log_level('Warning')
        options.set_logging(True)
        options.lock()

        # creation of the object network using the options entity already created
        self.network = ZWaveNetwork(options, autostart=False)

        ###### 	 These dispatchers associate a method to a signal. the signals are generated by the library python-openzwave.
        ######   Once the signal is received. It's associated method is executed (see "_node_added" example below in "_network_started" method)
        dispatcher.connect(self._network_started,
                           ZWaveNetwork.SIGNAL_NETWORK_STARTED)
        dispatcher.connect(self._network_ready,
                           ZWaveNetwork.SIGNAL_NETWORK_READY)

        ###### backend object attributes
        #        self.devices = OrderedDict()  ### will contain the list of nodes in the network
        #        self.sensors = OrderedDict()  ### will contain the list of sensors (only) in the network
        self.node_added = False
        self.node_removed = False
        self.timestamps = {
        }  ### will contain the time of the last values' update for each sensor
        self.queryStages = {  ### the diffrent stages that a node object gets through before being ready
            "None": 1,  # Query process hasn't started for this node
            "ProtocolInfo": 2,  # Retrieve protocol information
            "Probe": 3,  # Ping device to see if alive
            "WakeUp": 4,  # Start wake up process if a sleeping node
            "ManufacturerSpecific1":
            5,  # Retrieve manufacturer name and product ids if ProtocolInfo lets us
            "NodeInfo":
            6,  # Retrieve info about supported, controlled command classes
            "SecurityReport":
            7,  # Retrieve a list of Command Classes that require Security
            "ManufacturerSpecific2":
            8,  # Retrieve manufacturer name and product ids
            "Versions": 9,  # Retrieve version information
            "Instances":
            10,  # Retrieve information about multiple command class instances
            "Static": 11,  # Retrieve static information (doesn't change)
            "Probe1": 12,  # Ping a device upon starting with configuration
            "Associations": 13,  # Retrieve information about associations
            "Neighbors": 14,  # Retrieve node neighbor list
            "Session":
            15,  # Retrieve session information (changes infrequently)
            "Dynamic": 16,  # Retrieve dynamic information (changes frequently)
            "Configuration":
            17,  # Retrieve configurable parameter information (only done on request)
            "Complete": 18  # Query process is completed for this node
        }
Esempio n. 11
0
    def run(self):
        """
        Run method for the plugin
        """
        self.logger.debug('zwave: run method called')
        self.alive = True

        try:
            options = ZWaveOption(self._device, config_path=self._config_path, user_path='.', cmd_line='')
        except Exception as e:
            self.logger.error('zwave: error on create ZWaveOption - {}'.format(e))
            self.alive = False
            return

        try:
            options.set_log_file(self._logfile)
            options.set_save_log_level(self._loglevel)
            options.set_logging(self._logging)
            options.set_append_log_file(False)
            options.set_console_output(False)
            options.set_security_strategy(self._sec_strategy)
            options.lock()
        except Exception as e:
            self.logger.error('zwave: error on option.set_* - {}'.format(e))

        self.logger.debug('zwave: run -> create network')
        try:
            self._network = ZWaveNetwork(options, autostart=False)
        except Exception as e:
            self.logger.error('zwave: error on create Network Object - {}'.format(e))

        self.logger.debug('zwave: run -> connect event handler')
        try:
            dispatcher.connect(self.zwave_value_update, ZWaveNetwork.SIGNAL_VALUE_CHANGED)
        except Exception as e:
            self.logger.error('zwave: error on connect event handler - {}'.format(e))

        self.logger.debug('zwave: run -> start network')
        try:
            self._network.start()
        except Exception as e:
            self.logger.error('zwave: error on start network - {}'.format(e))

        self.logger.info('zwave: use openzwave library: {}'.format(self._network.controller.ozw_library_version))
        self.logger.info('zwave: use python library: {}'.format(self._network.controller.python_library_version))
        self.logger.info('zwave: use ZWave library: {}'.format(self._network.controller.library_description))
        while 1:
            if self.alive and self._network.state < self._network.STATE_READY:
                self.logger.debug('zwave: wait until network is ready... current state is: {}'.format(self._network.state_str))
                time.sleep(3.0)
                if self._network.state == self._network.STATE_FAILED:
                    self.alive = false
                    return

        self.logger.info('zwave: controller ready : {} nodes were found.'.format(self._network.nodes_count))
        self.logger.info('zwave: controller node id : {}'.format(self._network.controller.node.node_id))
        self.logger.info('zwave: controller node version : {}'.format(self._network.controller.node.version))
        self.logger.info('zwave: Network home id : {}'.format(self._network.home_id_str))
        self.logger.info('zwave: Nodes in network : {}'.format(self._network.nodes_count))
Esempio n. 12
0
    def start(self):
        if not self.opts_locked:
            raise ZWaveCentralException("ZWave options not locked")
        self.net = ZWaveNetwork(self.opts, autostart=False)
        self.ctrl.append(self.net.controller)

        self.home_id = self.net.home_id
        self.net.start()
Esempio n. 13
0
    def __init__(self, object_group, config):
        Plugin.__init__(self,
                        config=config,
                        object_group=object_group,
                        plugin_name=PLUGIN_NAME)

        # Get parameters from the config file

        if not self.is_enabled():
            return

        # Initialize zwave library
        # Options
        try:
            opts = ZWaveOption(
                device="/dev/ttyUSB0",
                config_path=
                "/home/mlamonta/git/python-openzwave/openzwave/config/",
                user_path="logs")
            opts.set_log_file("./logs/zwave.log")
            opts.set_save_log_level("Alert")
            opts.set_append_log_file(False)
            opts.set_console_output(False)
            opts.set_logging(True)
            opts.lock()
        except ZWaveException as e:
            self.logger.error(str(e))
            return

        # Network
        self.net = ZWaveNetwork(opts)

        self.logger.info(
            "------------------------------------------------------------")
        self.logger.info("Waiting for network awake : ")
        self.logger.info(
            "------------------------------------------------------------")
        for i in range(0, 300):
            if self.net.state >= self.net.STATE_AWAKED:
                self.logger.info("done")
                break
            else:
                time.sleep(1.0)

        if self.net.state < self.net.STATE_AWAKED:
            self.logger.warning("Network is not awake")
            return

        self.logger.info(
            "------------------------------------------------------------")

        for node in self.net.nodes:
            self.logger.info("%s - %s / %s" %
                             (self.net.nodes[node].node_id,
                              self.net.nodes[node].manufacturer_name,
                              self.net.nodes[node].product_name))

        self._initialized = True
Esempio n. 14
0
 def run(self):
     self.isRunning = True
     #Create a network object
     self.network = ZWaveNetwork(self.zwaveOptions, autostart=False)
     #and connect our above handlers to respective events
     dispatcher.connect(self.networkStarted, ZWaveNetwork.SIGNAL_NETWORK_STARTED)
     dispatcher.connect(self.networkFailed, ZWaveNetwork.SIGNAL_NETWORK_FAILED)
     dispatcher.connect(self.networkReady, ZWaveNetwork.SIGNAL_NETWORK_READY)
     self.network.start()
Esempio n. 15
0
def start_zwnetwork(app):
    options = ZWaveOption(device=app.config['ZWAVE_DEVICE'], config_path=app.config['ZWAVE_DIR'], user_path=app.config['USER_DIR'])
    options.set_log_file("OZW_Log.log")
    options.set_append_log_file(False)
    options.set_console_output(False)
    options.set_save_log_level(app.config['ZWAVE_DEBUG'])
    options.set_logging(app.config['ZWAVE_LOGGING'])
    options.lock()
    zwnetwork = ZWaveNetwork(options)
    return zwnetwork
Esempio n. 16
0
 def test_000_api_network(self):
     self.touchFile('ttyUSBO_fake')
     self.options = ZWaveOption(device='ttyUSBO_fake', user_path=self.userpath)
     self.options.set_log_file("OZW_Log.log")
     self.options.set_append_log_file(False)
     self.options.set_console_output(False)
     self.options.set_save_log_level("Debug")
     self.options.set_logging(True)
     self.options.lock()
     self.network = ZWaveNetwork(self.options, autostart=False)
     self.rmFile('ttyUSBO_fake')
Esempio n. 17
0
 def _start_network(self):
     #Define some manager options
     self.options = ZWaveOption(self.device, \
       config_path="openzwave/config", \
       user_path=".", cmd_line="")
     self.options.set_log_file("OZW_Log.log")
     self.options.set_append_log_file(False)
     self.options.set_console_output(False)
     self.options.set_save_log_level("Internal")
     self.options.set_logging(True)
     self.options.lock()
     self.network = ZWaveNetwork(self.options, self.log)
     self.status_bar.update(status='Start Network')
Esempio n. 18
0
 def _start_network(self):
     #Define some manager options
     self.options = ZWaveOption(self.device, \
       config_path=self.config_path, \
       user_path=self.user_path, cmd_line="")
     self.options.set_log_file("OZW_Log.log")
     self.options.set_append_log_file(False)
     self.options.set_console_output(False)
     self.options.set_save_log_level(self.loglevel_ow)
     self.options.set_logging(True)
     self.options.lock()
     self.network = ZWaveNetwork(self.options, self.log, kvals=False)
     self.status_bar.update(status='Start Network')
Esempio n. 19
0
 def setUpClass(self):
     super(TestApi, self).setUpClass()
     self.options = ZWaveOption(device=self.device, user_path=self.userpath)
     self.options.set_log_file("OZW_Log.log")
     self.options.set_append_log_file(False)
     self.options.set_console_output(self.ozwout)
     self.options.set_save_log_level(self.ozwlog)
     self.options.set_logging(True)
     self.options.lock()
     self.network = ZWaveNetwork(self.options)
     self.node_result = None
     self.ctrl_command_result = None
     self.ctrl_command_signal = None
     #dispatcher.connect(self.ctrl_message, ZWaveNetwork.SIGNAL_CONTROLLER_COMMAND)
     time.sleep(1.0)
Esempio n. 20
0
 def setUpClass(self):
     super(TestApi, self).setUpClass()
     self.options = ZWaveOption(device=self.device, user_path=self.userpath)
     self.options.set_log_file("OZW_Log.log")
     self.options.set_append_log_file(False)
     self.options.set_console_output(False)
     self.options.set_save_log_level("Debug")
     self.options.set_logging(True)
     self.options.lock()
     self.network = ZWaveNetwork(self.options)
     self.ctrl_command_result = None
     dispatcher.connect(self.ctrl_message,
                        ZWaveController.SIGNAL_CONTROLLER)
     self.node_result = None
     dispatcher.connect(self.node_update, ZWaveNetwork.SIGNAL_NODE)
Esempio n. 21
0
    def __init__(self, device_path, ozw_log_level, logger):
        self.logger = logger

        options = ZWaveOption(device_path,
                              config_path="./venv/lib/python3.6/site-packages/python_openzwave/ozw_config",
                              user_path=".", cmd_line="")
        options.set_log_file("OZW.log")
        options.set_append_log_file(False)
        options.set_save_log_level(ozw_log_level)
        options.set_console_output(False)
        options.set_logging(True)
        options.lock()
        self.options = options
        self.network = ZWaveNetwork(options, log=None, autostart=False)
        self.client = InfluxDBClient(database=DATABASE)
 def log_level(self):
     self.logger.info("Performing log level entries")
     options = ZWaveOption(
         device,
         config_path="/home/riaps/python-openzwave/openzwave/config",
         user_path=".",
         cmd_line="")
     options.set_log_file("OZW.log")
     options.set_append_log_file(False)
     options.set_save_log_level("Info")
     options.set_console_output(False)
     options.set_logging(True)
     options.lock()
     self.ZWaveOption = options
     self.network = ZWaveNetwork(options, log=None, autostart=False)
     self.logger.info("log level entries done")
Esempio n. 23
0
    def _init_openzwave(self, zwave_device, zwave_config_path,
                        zwave_user_path):
        """Initialise the OpenZWave client, leaving it ready to start."""
        # Configure OpenZWave
        options = ZWaveOption(zwave_device,
                              config_path=zwave_config_path,
                              user_path=zwave_user_path,
                              cmd_line="")
        options.set_log_file(os.path.join(zwave_user_path, "zwave.log"))
        options.set_append_log_file(True)
        options.set_console_output(True)
        options.set_save_log_level("Warning")
        options.set_logging(True)
        options.lock()

        self._ozw_network = ZWaveNetwork(options, autostart=False)
Esempio n. 24
0
def init():
    log.info("initializing...")
    global _network
    #Define some manager options
    options = ZWaveOption(config.ZWAVE_DEVICE,
                          config_path=config.OPENZWAVE_CONFIG_FILE,
                          user_path=".",
                          cmd_line="")
    options.set_log_file(config.OPENZWAVE_LOG_FILE)
    options.set_append_log_file(False)
    options.set_console_output(False)
    options.set_save_log_level(config.OPENZWAVE_LOG_LEVEL)
    #options.set_save_log_level('Info')
    options.set_logging(True)
    options.lock()
    #Create a network object
    _network = ZWaveNetwork(options)
Esempio n. 25
0
 def connect(self) -> None:
     options = ZWaveOption(
         self.__zwave_config.port,
         config_path=self.__zwave_config.openzwave_config_path,
         user_path=".",
         cmd_line="")
     options.set_console_output(False)
     options.set_save_log_level("None")
     options.set_logging(False)
     options.lock()
     self.__network = ZWaveNetwork(options, autostart=False)
     dispatcher.connect(self.__network_failed,
                        ZWaveNetwork.SIGNAL_NETWORK_FAILED)
     dispatcher.connect(self.__network_ready,
                        ZWaveNetwork.SIGNAL_NETWORK_READY)
     dispatcher.connect(self.__value_update, ZWaveNetwork.SIGNAL_VALUE)
     self.__network.start()
Esempio n. 26
0
    def __init__(self, *args, **kwargs):
        self._serialDevicePath = kwargs.get('serialDevicePath', None)
        self._options = ZWaveOption(self._serialDevicePath, \
          config_path="/usr/local/etc/openzwave/", \
          user_path=".", cmd_line="")
        self._options.set_log_file("OZW_Log.log")
        self._options.set_append_log_file(False)
        self._options.set_console_output(False)
        #self._options.set_save_log_level(log)
        self._options.set_save_log_level('Info')
        self._options.set_logging(True)
	self._options.set_notify_transactions(True)
        self._options.lock()

        self._network = ZWaveNetwork(self._options, log=None,autostart=False)
	dispatcher.connect(self.louie_network_ready, ZWaveNetwork.SIGNAL_NETWORK_READY)
	self._network.start()
        super(Open_zwave, self).__init__(self, *args, **kwargs)
Esempio n. 27
0
def main():
    global LIGHT, PUSHOVER

    logging.basicConfig(level=logging.INFO,
                        format="%(asctime)-15s %(levelno)d %(message)s")

    # TODO: Put in argparse
    device = None
    if device is None:
        device = discover_device()
    check_device(device)

    CONFIG = read_config("config.json")
    if CONFIG.pushover.apikey is not None:
        logging.info("Setting up Pushover")
        PUSHOVER = Pushover(CONFIG.pushover.apikey, CONFIG.pushover.userkeys)

    connect_signals()

    options = create_zwave_options(device=device)
    network = ZWaveNetwork(options, log=None, autostart=False)

    queue = threading.Thread(target=DataQueue.worker,
                             kwargs={"location": "home.db"},
                             name="db")
    queue.start()

    try:
        network.start()

        # Start REPL with a union where globals override locals
        local = locals().copy()
        local.update(globals())
        code.interact(local=local)
    except KeyboardInterrupt:
        pass
    finally:
        logging.info("\nStopping network ...")
        network.stop()

        logging.info("Stopping data queue ...")
        DataQueue.stop()
        queue.join()
Esempio n. 28
0
def main():

    term = Terminal()

    options = ZWaveOption(device='/dev/ttyACM0')
    options.set_log_file('test.log')
    options.set_append_log_file(True)
    options.set_console_output(False)
    options.set_logging(True)
    options.lock()

    network = ZWaveNetwork(options)
    event_handler = EventHandler()

    start_time = dt.utcnow()

    composer: Composer
    with ComposerContext(term) as composer:

        sb = StatusBuffer(term)
        help_dialog = HelpDialog(term)

        composer.add_widget(sb)
        composer.add_widget(help_dialog.dialog)

        sb.set_buffer_behavior(StatusBuffer.BEHAVIOR_TOP)
        controller = BufferController(sb, network)
        event_handler.register(controller)
        print("> {}".format(controller.handled_buffer_events()))
        sb.set_trigger(controller.handled_buffer_events(),
                       controller.handle_buffer_event)

        starting_spinner = 0
        available_since = None

        last_known_state = None
        while True:
            ch = term.inkey(timeout=0.25)
            if ch:
                composer.handle_inkey(ch)
            controller.update()
            composer.refresh()
            time.sleep(0.25)
    def __init__(self):
        #super(, self).__init__()
        options = ZWaveOption(device, \
          user_path=".", cmd_line="")
        options.set_log_file("OZW_Log.log")
        options.set_append_log_file(False)
        options.set_console_output(True)
        options.set_save_log_level(log)
        #options.set_save_log_level('Info')
        options.set_logging(False)
        options.lock()
        self._optiton = options
        self.network = ZWaveNetwork(options, log=None)
        time_started = 0
        for i in range(0,100):
            if self.network.state>=self.network.STATE_AWAKED:
                break
            else:
                time_started += 1
                time.sleep(1.0)
        if self.network.state<self.network.STATE_AWAKED:
            print("Network is not awake but continue anyway")

        for i in range(0,300):
            if self.network.state>=self.network.STATE_READY:
                print("home ID {}".format(home_id))
                break
            else:
                sys.stdout.write(".")
                time_started += 1
                #sys.stdout.write(network.state_str)
                #sys.stdout.write("(")
                #sys.stdout.write(str(network.nodes_count))
                #sys.stdout.write(")")
                #sys.stdout.write(".")
                sys.stdout.flush()
                time.sleep(1.0)
        if not network.is_ready:
            print("network is not ready but start anyway")
        network.start()
        self.controller = network.controller
    def __init__(self, device_path, ozw_log_level, logger):
        self.logger = logger

        options = ZWaveOption(
            device_path,
            config_path=
            "./venv/lib/python3.%d/site-packages/python_openzwave/ozw_config" %
            sys.version_info[1],
            user_path=".",
            cmd_line="")
        options.set_log_file("OZW.log")
        options.set_append_log_file(False)
        options.set_save_log_level(ozw_log_level)
        options.set_console_output(False)
        options.set_logging(True)
        options.lock()
        self.options = options
        self.network = ZWaveNetwork(options, log=None, autostart=False)
        self.csvfile = open('output.csv', 'a')
        self.writer = csv.writer(self.csvfile)
        self.stopping = False