예제 #1
0
    def test_010_options_exceptions(self):
        fake_config_dir = os.path.join(self.userpath,'fake_config_dir')
        fake_user_dir = os.path.join(self.userpath,'fake_user_dir')
        with self.assertRaises(libopenzwave.LibZWaveException):
            options = libopenzwave.PyOptions(config_path="non_exisitng_dir", user_path=None, cmd_line=None)
        try:
            shutil.rmtree(self.userpath)
        except:
            pass
        os.makedirs(self.userpath)
        os.makedirs(fake_config_dir)
        os.chmod(fake_config_dir, stat.S_IREAD|stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH)
        with self.assertRaises(libopenzwave.LibZWaveException):
            options = libopenzwave.PyOptions(config_path=fake_config_dir, user_path=None, cmd_line=None)

        try:
            shutil.rmtree(self.userpath)
        except:
            pass
        os.makedirs(self.userpath)
        os.makedirs(fake_config_dir)
        os.chmod(fake_config_dir, stat.S_IREAD|stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH|stat.S_IWRITE|stat.S_IWUSR|stat.S_IWGRP|stat.S_IWOTH)
        with self.assertRaises(libopenzwave.LibZWaveException):
            options = libopenzwave.PyOptions(config_path=fake_config_dir, user_path=None, cmd_line=None)

        options = libopenzwave.PyOptions(config_path=None, user_path=None, cmd_line="")
예제 #2
0
def imports(args):
    if args.timeout is None:
        args.timeout = 2
    if args.output == 'txt':
        print(
            "-------------------------------------------------------------------------------"
        )
        print("Import libs")
        print("Try to import libopenzwave")
        import libopenzwave
        print("Try to import libopenzwave.PyLogLevels")
        from libopenzwave import PyLogLevels
        print("Try to get options")
        options = libopenzwave.PyOptions(user_path=".",
                                         cmd_line="--logging false")
        options.lock()
        time.sleep(0.5)
        print("Try to get manager")
        manager = libopenzwave.PyManager()
        manager.create()
        print("Try to get python_openzwave version")
        print(manager.getPythonLibraryVersionNumber())
        print("Try to get python_openzwave full version")
        print(manager.getPythonLibraryVersion())
        print("Try to get openzwave version")
        print(manager.getPythonLibraryVersion())
        print("Try to get openzwave version")
        print(manager.getOzwLibraryVersion())
        print("Try to get default config path")
        print(libopenzwave.configPath())
        print("Try to destroy manager")
        manager.destroy()
        print("Try to destroy options")
        options.destroy()
        time.sleep(0.5)
        print("Try to import openzwave (API)")
        import openzwave

    elif args.output == 'raw':
        import libopenzwave
        from libopenzwave import PyLogLevels
        options = libopenzwave.PyOptions(user_path=".",
                                         cmd_line="--logging false")
        options.lock()
        time.sleep(0.5)
        manager = libopenzwave.PyManager()
        manager.create()
        print("{0}|{1}|{2}|{3}".format(manager.getOzwLibraryVersion(),
                                       manager.getPythonLibraryVersionNumber(),
                                       manager.getPythonLibraryVersion(),
                                       libopenzwave.configPath()))
        manager.destroy()
        options.destroy()
        time.sleep(0.5)
        import openzwave
예제 #3
0
 def test_060_options_lock(self):
     options = libopenzwave.PyOptions(user_path=self.userpath)
     self.assertTrue(options.lock())
     self.assertTrue(options.areLocked())
     self.assertTrue(
         os.path.isfile(os.path.join(self.userpath, 'options.xml')))
     self.assertTrue(options.destroy())
예제 #4
0
 def test_030_options_with_command_line(self):
     self._options = libopenzwave.PyOptions(cmd_line='--LogFileName ozwlog.log --Logging --SaveLogLevel 1')
     self.assertTrue(self._options.lock())
     self.assertTrue(self._options.areLocked())
     self.assertEqual(True, self._options.getOptionAsBool("Logging"))
     self.assertEqual('ozwlog.log', self._options.getOptionAsString("LogFileName"))
     self.assertEqual(1, self._options.getOptionAsInt("SaveLogLevel"))
     self.assertTrue(self._options.destroy())
예제 #5
0
 def test_020_options_bool(self):
     _options = libopenzwave.PyOptions()
     _configpath = _options.getConfigPath()
     _options.create(_configpath, self.userpath, '')
     self.assertTrue(_options.addOptionBool("Logging", True))
     self.assertEqual(True, _options.getOptionAsBool("Logging"))
     _options.destroy()
     _configpath = None
     _options = None
예제 #6
0
 def test_030_options_int(self):
     _options = libopenzwave.PyOptions()
     _configpath = _options.getConfigPath()
     _options.create(_configpath, self.userpath, '')
     self.assertTrue(_options.addOptionInt("SaveLogLevel", libopenzwave.PyLogLevels['Always']['value']))
     self.assertEqual(libopenzwave.PyLogLevels['Always']['value'], _options.getOptionAsInt("SaveLogLevel"))
     _options.destroy()
     _configpath = None
     _options = None
예제 #7
0
 def test_010_options_string(self):
     _options = libopenzwave.PyOptions()
     _configpath = _options.getConfigPath()
     _options.create(_configpath, self.userpath, '')
     self.assertTrue(_options.addOptionString("LogFileName", 'ozwlog.log', False))
     self.assertEqual('ozwlog.log', _options.getOptionAsString("LogFileName"))
     _options.destroy()
     _configpath = None
     _options = None
예제 #8
0
 def test_040_options_generic(self):
     _options = libopenzwave.PyOptions()
     _configpath = _options.getConfigPath()
     _options.create(_configpath, self.userpath, '')
     self.assertTrue(_options.addOption("LogFileName", 'ozwlog.log'))
     self.assertEqual('ozwlog.log', _options.getOption("LogFileName"))
     self.assertTrue(_options.addOption("Logging", True))
     self.assertEqual(True, _options.getOption("Logging"))
     self.assertTrue(_options.addOption("SaveLogLevel", libopenzwave.PyLogLevels['Always']['value']))
     self.assertEqual(libopenzwave.PyLogLevels['Always']['value'], _options.getOption("SaveLogLevel"))
     _options.destroy()
     _configpath = None
     _options = None
예제 #9
0
    def start(self):
        global manager
        manager = self

        options = libopenzwave.PyOptions()
        options.create('/etc/openzwave/', '/root/zwave/', '')
        #        options.addOptionBool('ConsoleOutput', False)
        options.addOptionBool('Logging', False)
        #        options.addOptionBool('SaveConfiguration', True)
        options.lock()

        manager = ZWaveManager(self)
        manager.create()
        manager.addWatcher(handleNotification)
        manager.addDriver('/dev/usbzwave')
예제 #10
0
 def __init__(self, device, config, log=None):
     self._log = log
     if self._log is None:
         self._log = logging.getLogger(__name__)
         self._log.addHandler(NullHandler())
     self._initialized = False
     self.home_id = None
     self._controllerNodeId = None
     self._controller = None
     self._nodes = dict()
     self._library_type_name = 'Unknown'
     self._library_version = 'Unknown'
     self._device = device
     options = libopenzwave.PyOptions()
     options.create(config, '', '--logging false')
     options.lock()
     self._manager = libopenzwave.PyManager()
     self._manager.create()
     self._manager.addWatcher(self.zwcallback)
     self._manager.addDriver(device)
예제 #11
0
 def start_lib(self):
     if self.options is None:
         self.options = libopenzwave.PyOptions(config_path="openzwave/config", \
             user_path=self.userpath, cmd_line="--logging false")
         self.options.lock()
     if self.manager is None:
         self.homeid = None
         self.nodes = {}
         self.ready = False
         self.driver_state = None
         self.driver_ready = None
         self.driver_removed = None
         self.driver_failed = None
         self.driver_reset = None
         self.network_state = None
         self.network_ready = None
         self.network_awake = None
         self.manager = libopenzwave.PyManager()
         self.manager.create()
         self.manager.addWatcher(self.zwcallback)
         time.sleep(1.0)
         self.manager.addDriver(self.device)
         time.sleep(5.0)
예제 #12
0
 def setUp(self):
     self.options = libopenzwave.PyOptions(config_path="openzwave/config", \
         user_path=self.userpath, cmd_line="--logging false")
     self.options.lock()
예제 #13
0
for arg in sys.argv:
    if arg.startswith("--device"):
        temp, device = arg.split("=")
    elif arg.startswith("--log"):
        temp, log = arg.split("=")
    elif arg.startswith("--sniff"):
        temp, sniff = arg.split("=")
        sniff = float(sniff)
    if arg.startswith("--help"):
        print("help : ")
        print("  --device=/dev/yourdevice ")
        print("  --log=Info|Debug")
        print("  --sniff=0 : sniff for zwave messages a number of seconds")
        exit(0)

options = libopenzwave.PyOptions(config_path="../openzwave/config", \
  user_path=".", cmd_line="--logging true")

# Specify the open-zwave config path here
options.lock()
manager = libopenzwave.PyManager()
manager.create()


# callback order: (notificationtype, homeid, nodeid, ValueID, groupidx, event)
def callback(args):
    print('\n-------------------------------------------------')
    print('\n[{}]:\n'.format(args['notificationType']))
    if args:
        print('homeId: 0x{0:08x}'.format(args['homeId']))
        print('nodeId: {}'.format(args['nodeId']))
        if 'valueId' in args:
예제 #14
0
def init_device(args):
    global home_id
    if args.timeout is None:
        args.timeout = 15
    if args.output == 'txt':
        print(
            "-------------------------------------------------------------------------------"
        )
        print("Intialize device {0}".format(args.device))
        import libopenzwave
        print("Try to get options")
        options = libopenzwave.PyOptions(config_path=args.config_path,
                                         user_path=args.user_path,
                                         cmd_line="--logging true")
        options.lock()
        time.sleep(1.0)
        print("Try to get manager")
        manager = libopenzwave.PyManager()
        manager.create()
        print("Try to get python_openzwave version")
        print(manager.getPythonLibraryVersionNumber())
        print("Try to get python_openzwave full version")
        print(manager.getPythonLibraryVersion())
        print("Try to get openzwave version")
        print(manager.getOzwLibraryVersion())
        print("Try to get default config path")
        print(libopenzwave.configPath())
        print("Try to add watcher")
        manager.addWatcher(zwcallback)
        time.sleep(1.0)
        manager.addDriver(args.device)
        print("Wait for notifications ({0}s)".format(args.timeout))
        next_print = args.timeout / 10
        delta = 0.1
        for i in range(0, int(args.timeout / delta)):
            time.sleep(delta)
            next_print -= delta
            if next_print < 0:
                next_print = args.timeout / 10
                print('.')
        print("Try to remove driver")
        manager.removeDriver(args.device)
        time.sleep(3.0)
        print("Try to remove watcher")
        manager.removeWatcher(zwcallback)
        print("Try to destroy manager")
        manager.destroy()
        time.sleep(0.2)
        print("Try to destroy options")
        options.destroy()
        time.sleep(1.0)
        print("Retrieve HomeID")
        print("{0:08x}".format(home_id))
    elif args.output == 'raw':
        import libopenzwave
        options = libopenzwave.PyOptions(config_path=args.config_path,
                                         user_path=args.user_path,
                                         cmd_line="--logging false")
        options.lock()
        time.sleep(1.0)
        manager = libopenzwave.PyManager()
        manager.create()
        manager.addWatcher(zwcallback)
        time.sleep(1.0)
        manager.addDriver(args.device)
        next_print = args.timeout / 10
        delta = 0.1
        for i in range(0, int(args.timeout / delta)):
            time.sleep(delta)
        print("{0}|{1}|{2}|{3}|{4:08x}".format(
            manager.getOzwLibraryVersion(),
            manager.getPythonLibraryVersionNumber(),
            manager.getPythonLibraryVersion(),
            libopenzwave.configPath(),
            home_id,
        ))
        manager.removeDriver(args.device)
        time.sleep(0.5)
        manager.removeWatcher(zwcallback)
        manager.destroy()
        time.sleep(0.2)
        options.destroy()
예제 #15
0
 def setUp(self):
     self._options = libopenzwave.PyOptions()
     self._configpath = self._options.getConfigPath()
     self._options.create(self._configpath, self.userpath, '')
예제 #16
0
for arg in sys.argv:
    if arg.startswith("--device"):
        temp, device = arg.split("=")
    elif arg.startswith("--log"):
        temp, log = arg.split("=")
    elif arg.startswith("--sniff"):
        temp, sniff = arg.split("=")
        sniff = float(sniff)
    if arg.startswith("--help"):
        print("help : ")
        print("  --device=/dev/yourdevice ")
        print("  --log=Info|Debug")
        print("  --sniff=0 : sniff for zwave messages a number of seconds")
        exit(0)

options = libopenzwave.PyOptions()

# Specify the open-zwave config path here
options.create("../openzwave/config/", "", "--logging true")
options.lock()
manager = libopenzwave.PyManager()
manager.create()


# callback order: (notificationtype, homeid, nodeid, ValueID, groupidx, event)
def callback(args):
    print('\n%s\n[%s]:\n' % ('-' * 20, args['notificationType']))
    if args:
        print('homeId: 0x%.8x' % args['homeId'])
        print('nodeId: %d' % args['nodeId'])
        v = args['valueId']
예제 #17
0
 def test_020_options_without_command_line(self):
     self._options = libopenzwave.PyOptions()
     self._configpath = self._options.getConfigPath()
     self.assertNotEqual(self._configpath, None)
     self.assertTrue(os.path.exists(os.path.join(self._configpath, "zwcfg.xsd")))
     self.assertTrue(self._options.destroy())
예제 #18
0
import logging
import signal
import sqlite3
import libopenzwave

DATABASE = '/home/pi/lunares_hab/sensors-data.sqlite3'
ALLOWED_MEASUREMENTS = [
    'Battery Level', 'Powerlevel', 'Temperature', 'Luminance',
    'Relative Humidity', 'Ultraviolet'
]  # 'Burglar'
device = '/dev/ttyACM0'
log = 'Info'
sniff = 60.0

options = libopenzwave.PyOptions(config_path='/usr/local/etc/openzwave/',
                                 user_path='/home/pi/lunares_hab/',
                                 cmd_line='--logging false')

options.lock()
manager = libopenzwave.PyManager()
manager.create()

with sqlite3.connect(DATABASE) as db:
    db.execute("""CREATE TABLE IF NOT EXISTS sensor_data (
        datetime DATETIME PRIMARY KEY,
        sync_datetime DATETIME DEFAULT NULL,
        device VARCHAR(255),
        type VARCHAR(255),
        value VARCHAR(255),
        unit VARCHAR(255));""")
    db.execute(