コード例 #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
ファイル: pyozw_check.py プロジェクト: jacKlinc/RPi_HEMS
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
ファイル: test_lib.py プロジェクト: whuji/python-openzwave
 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
ファイル: test_lib.py プロジェクト: whuji/python-openzwave
 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
ファイル: test_lib.py プロジェクト: whuji/python-openzwave
 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
ファイル: caravan_zwave.py プロジェクト: balek/caravan_zwave
    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
ファイル: wrapper.py プロジェクト: Bouhmarc/python-openzwave
 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
ファイル: common.py プロジェクト: whuji/python-openzwave
 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
ファイル: test_driver.py プロジェクト: b01t/openzwave-python
 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
ファイル: pyozw_check.py プロジェクト: jacKlinc/RPi_HEMS
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
ファイル: test_lib.py プロジェクト: Bouhmarc/python-openzwave
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(