How to use the pyvera.init_controller function in pyvera

To help you get started, we’ve selected a few pyvera examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pavoni / pyvera / examples / device-listener.py View on Github external
parser = argparse.ArgumentParser(description='device-listener')
parser.add_argument('-u', '--url', help="Vera URL, e.g. http://192.168.1.161:3480", required=True)
group = parser.add_mutually_exclusive_group(required=True)
# Pass in either the vera id of the device or the name
group.add_argument('-i', '--id', type=int, help="The Vera Device ID for subscription")
group.add_argument('-n', '--name', help="The Vera Device name string for subscription")
args = parser.parse_args()

# Define a callback that runs each time a device changes state
def device_info_callback(vera_device):
    # Do what we want with the changed device information
    print('{}_{} values: {}'.format(vera_device.name, vera_device.device_id, vera_device.get_all_values()))
    print('{}_{} alerts: {}'.format(vera_device.name, vera_device.device_id, vera_device.get_alerts()))

# Start the controller
controller, _ = pyvera.init_controller(args.url)

try:
    # Get the requested device on the vera controller
    found_device = None
    if args.name is not None:
        found_device = controller.get_device_by_name(args.name)
    elif args.id is not None:
        found_device = controller.get_device_by_id(args.id)

    if found_device is None:
        raise Exception('Did not find  device with {} or {}'.format(args.name, args.id))

    print('Listening for changes to {}: {}_{}'.format(type(found_device).__name__, found_device.name, found_device.device_id))

    # Register a callback that runs when the info for that device is updated
    controller.register(found_device, device_info_callback)
github pavoni / pyvera / examples / garage_door.py View on Github external
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), '..'))

# Import pyvera
import pyvera

# Parse Arguments
import argparse
parser = argparse.ArgumentParser(description='list-devices')
parser.add_argument('-u', '--url', help="Vera URL, e.g. http://192.168.1.161:3480", required=True)
parser.add_argument('--close', help="Close garage door(s)", action="store_true")
args = parser.parse_args()

# Start the controller
controller, _ = pyvera.init_controller(args.url)

try:
    # Get a list of all the devices on the vera controller
    all_devices = controller.get_devices()

    # Open/close all garage doors.
    for device in all_devices:
        if isinstance(device, pyvera.VeraGarageDoor):
            if args.close:
                device.switch_off()
            else:
                device.switch_on()

finally:
    # Stop the subscription listening thread so we can quit
    controller.stop()
github pavoni / pyvera / examples / list-devices.py View on Github external
# Import project path
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), '..'))

# Import pyvera
import pyvera

# Parse Arguments
import argparse
parser = argparse.ArgumentParser(description='list-devices')
parser.add_argument('-u', '--url', help="Vera URL, e.g. http://192.168.1.161:3480", required=True)
args = parser.parse_args()

# Start the controller
controller, _ = pyvera.init_controller(args.url)

try:
    # Get a list of all the devices on the vera controller
    all_devices = controller.get_devices()

    # Print the devices out
    for device in all_devices:
        print('{} {} ({})'.format(type(device).__name__, device.name, device.device_id))

finally:
    # Stop the subscription listening thread so we can quit
    controller.stop()
github pavoni / pyvera / examples / lock-all-doors-with-status.py View on Github external
import time

# Parse Arguments
import argparse
parser = argparse.ArgumentParser(description='lock-all-doors-with-status')
parser.add_argument('-u', '--url', help="Vera URL, e.g. http://192.168.1.161:3480", required=True)
args = parser.parse_args()

# Define a callback that runs each time a device changes state
def device_info_callback(vera_device):
    # Do what we want with the changed device information
    print('{}_{}: locked={}'.format(vera_device.name, vera_device.device_id, vera_device.is_locked()))

# Start the controller
controller, _ = pyvera.init_controller(args.url)

try:
    # Get a list of all the devices on the vera controller
    all_devices = controller.get_devices()

    # Look over the list and find the lock devices
    lock_devices = []
    for device in all_devices:
        if isinstance(device, pyvera.VeraLock):
            # Register a callback that runs when the info for that device is updated
            controller.register(device, device_info_callback)
            print('Initially, {}_{}: locked={}'.format(device.name, device.device_id, device.is_locked()))
            lock_devices.append(device)
            if not device.is_locked():
                device.lock()
github home-assistant / home-assistant / homeassistant / components / vera.py View on Github external
import pyvera as veraApi

    def stop_subscription(event):
        """Shutdown Vera subscriptions and subscription thread on exit."""
        _LOGGER.info("Shutting down subscriptions")
        hass.data[VERA_CONTROLLER].stop()

    config = base_config.get(DOMAIN)

    # Get Vera specific configuration.
    base_url = config.get(CONF_CONTROLLER)
    light_ids = config.get(CONF_LIGHTS)
    exclude_ids = config.get(CONF_EXCLUDE)

    # Initialize the Vera controller.
    controller, _ = veraApi.init_controller(base_url)
    hass.data[VERA_CONTROLLER] = controller
    hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_subscription)

    try:
        all_devices = controller.get_devices()

        all_scenes = controller.get_scenes()
    except RequestException:
        # There was a network related error connecting to the Vera controller.
        _LOGGER.exception("Error communicating with Vera API")
        return False

    # Exclude devices unwanted by user.
    devices = [device for device in all_devices
               if device.device_id not in exclude_ids]
github home-assistant / home-assistant / homeassistant / components / vera / __init__.py View on Github external
import pyvera as veraApi

    def stop_subscription(event):
        """Shutdown Vera subscriptions and subscription thread on exit."""
        _LOGGER.info("Shutting down subscriptions")
        hass.data[VERA_CONTROLLER].stop()

    config = base_config.get(DOMAIN)

    # Get Vera specific configuration.
    base_url = config.get(CONF_CONTROLLER)
    light_ids = config.get(CONF_LIGHTS)
    exclude_ids = config.get(CONF_EXCLUDE)

    # Initialize the Vera controller.
    controller, _ = veraApi.init_controller(base_url)
    hass.data[VERA_CONTROLLER] = controller
    hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_subscription)

    try:
        all_devices = controller.get_devices()

        all_scenes = controller.get_scenes()
    except RequestException:
        # There was a network related error connecting to the Vera controller.
        _LOGGER.exception("Error communicating with Vera API")
        return False

    # Exclude devices unwanted by user.
    devices = [device for device in all_devices if device.device_id not in exclude_ids]

    vera_devices = defaultdict(list)