Exemplo n.º 1
0
def setup(hass, base_config):
    """Common setup for Vera devices."""
    global VERA_CONTROLLER
    import pyvera as veraApi

    config = base_config.get(DOMAIN)
    base_url = config.get('vera_controller_url')
    if not base_url:
        _LOGGER.error("The required parameter 'vera_controller_url'"
                      " was not found in config")
        return False

    VERA_CONTROLLER, _ = veraApi.init_controller(base_url)

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

    hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_subscription)

    try:
        all_devices = VERA_CONTROLLER.get_devices(
            list(DEVICE_CATEGORIES.keys()))
    except RequestException:
        # There was a network related error connecting to the vera controller.
        _LOGGER.exception("Error communicating with Vera API")
        return False

    exclude = config.get(CONF_EXCLUDE, [])
    if not isinstance(exclude, list):
        _LOGGER.error("'exclude' must be a list of device_ids")
        return False

    lights_ids = config.get(CONF_LIGHTS, [])
    if not isinstance(lights_ids, list):
        _LOGGER.error("'lights' must be a list of device_ids")
        return False

    for device in all_devices:
        if device.device_id in exclude:
            continue
        dev_type = DEVICE_CATEGORIES.get(device.category)
        if dev_type is None:
            continue
        if dev_type == SWITCH and device.device_id in lights_ids:
            dev_type = LIGHT
        VERA_DEVICES[dev_type].append(device)

    for comp_name, discovery in (((BINARY_SENSOR, DISCOVER_BINARY_SENSORS),
                                  (SENSOR,
                                   DISCOVER_SENSORS), (LIGHT, DISCOVER_LIGHTS),
                                  (SWITCH, DISCOVER_SWITCHES))):
        component = get_component(comp_name)
        bootstrap.setup_component(hass, component.DOMAIN, config)
        hass.bus.fire(EVENT_PLATFORM_DISCOVERED, {
            ATTR_SERVICE: discovery,
            ATTR_DISCOVERED: {}
        })
    return True
Exemplo n.º 2
0
def setup(hass, base_config):
    """Common setup for Vera devices."""
    global VERA_CONTROLLER
    import pyvera as veraApi

    config = base_config.get(DOMAIN)
    base_url = config.get("vera_controller_url")
    if not base_url:
        _LOGGER.error("The required parameter 'vera_controller_url'" " was not found in config")
        return False

    VERA_CONTROLLER, _ = veraApi.init_controller(base_url)

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

    hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_subscription)

    try:
        all_devices = VERA_CONTROLLER.get_devices(list(DEVICE_CATEGORIES.keys()))
    except RequestException:
        # There was a network related error connecting to the vera controller.
        _LOGGER.exception("Error communicating with Vera API")
        return False

    exclude = config.get(CONF_EXCLUDE, [])
    if not isinstance(exclude, list):
        _LOGGER.error("'exclude' must be a list of device_ids")
        return False

    lights_ids = config.get(CONF_LIGHTS, [])
    if not isinstance(lights_ids, list):
        _LOGGER.error("'lights' must be a list of device_ids")
        return False

    for device in all_devices:
        if device.device_id in exclude:
            continue
        dev_type = DEVICE_CATEGORIES.get(device.category)
        if dev_type is None:
            continue
        if dev_type == SWITCH and device.device_id in lights_ids:
            dev_type = LIGHT
        VERA_DEVICES[dev_type].append(device)

    for comp_name, discovery in (
        (BINARY_SENSOR, DISCOVER_BINARY_SENSORS),
        (SENSOR, DISCOVER_SENSORS),
        (LIGHT, DISCOVER_LIGHTS),
        (SWITCH, DISCOVER_SWITCHES),
    ):
        component = get_component(comp_name)
        bootstrap.setup_component(hass, component.DOMAIN, base_config)
        hass.bus.fire(EVENT_PLATFORM_DISCOVERED, {ATTR_SERVICE: discovery, ATTR_DISCOVERED: {}})
    return True
Exemplo n.º 3
0
def setup(hass, base_config):
    """Common setup for Vera devices."""
    global VERA_CONTROLLER
    import pyvera as veraApi

    config = base_config.get(DOMAIN)
    base_url = config.get('vera_controller_url')
    if not base_url:
        _LOGGER.error(
            "The required parameter 'vera_controller_url'"
            " was not found in config"
        )
        return False

    VERA_CONTROLLER, _ = veraApi.init_controller(base_url)

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

    hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_subscription)

    try:
        all_devices = VERA_CONTROLLER.get_devices(
            list(DEVICE_CATEGORIES.keys()))
    except RequestException:
        # There was a network related error connecting to the vera controller.
        _LOGGER.exception("Error communicating with Vera API")
        return False

    exclude = config.get(CONF_EXCLUDE, [])
    if not isinstance(exclude, list):
        _LOGGER.error("'exclude' must be a list of device_ids")
        return False

    lights_ids = config.get(CONF_LIGHTS, [])
    if not isinstance(lights_ids, list):
        _LOGGER.error("'lights' must be a list of device_ids")
        return False

    for device in all_devices:
        if device.device_id in exclude:
            continue
        dev_type = DEVICE_CATEGORIES.get(device.category)
        if dev_type is None:
            continue
        if dev_type == 'switch' and device.device_id in lights_ids:
            dev_type = 'light'
        VERA_DEVICES[dev_type].append(device)

    for component in 'binary_sensor', 'sensor', 'light', 'switch', 'lock':
        discovery.load_platform(hass, component, DOMAIN, {}, base_config)

    return True
Exemplo n.º 4
0
def setup(hass, base_config):
    """Set up for Vera devices."""
    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)
    for device in devices:
        device_type = map_vera_device(device, light_ids)
        if device_type is None:
            continue

        vera_devices[device_type].append(device)
    hass.data[VERA_DEVICES] = vera_devices

    vera_scenes = []
    for scene in all_scenes:
        vera_scenes.append(scene)
    hass.data[VERA_SCENES] = vera_scenes

    for component in VERA_COMPONENTS:
        discovery.load_platform(hass, component, DOMAIN, {}, base_config)

    return True
Exemplo n.º 5
0
def setup(hass, base_config):
    """Common setup for Vera devices."""
    global VERA_CONTROLLER
    import pyvera as veraApi

    config = base_config.get(DOMAIN)
    base_url = config.get('vera_controller_url')
    if not base_url:
        _LOGGER.error("The required parameter 'vera_controller_url'"
                      " was not found in config")
        return False

    VERA_CONTROLLER, _ = veraApi.init_controller(base_url)

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

    hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_subscription)

    try:
        all_devices = VERA_CONTROLLER.get_devices(
            list(DEVICE_CATEGORIES.keys()))
    except RequestException:
        # There was a network related error connecting to the vera controller.
        _LOGGER.exception("Error communicating with Vera API")
        return False

    exclude = config.get(CONF_EXCLUDE, [])
    if not isinstance(exclude, list):
        _LOGGER.error("'exclude' must be a list of device_ids")
        return False

    lights_ids = config.get(CONF_LIGHTS, [])
    if not isinstance(lights_ids, list):
        _LOGGER.error("'lights' must be a list of device_ids")
        return False

    for device in all_devices:
        if device.device_id in exclude:
            continue
        dev_type = DEVICE_CATEGORIES.get(device.category)
        if dev_type is None:
            continue
        if dev_type == 'switch' and device.device_id in lights_ids:
            dev_type = 'light'
        VERA_DEVICES[dev_type].append(device)

    for component in 'binary_sensor', 'sensor', 'light', 'switch':
        discovery.load_platform(hass, component, DOMAIN, {}, base_config)

    return True
Exemplo n.º 6
0
def setup(hass, base_config):
    """Set up for Vera devices."""
    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)
    for device in devices:
        device_type = map_vera_device(device, light_ids)
        if device_type is None:
            continue

        vera_devices[device_type].append(device)
    hass.data[VERA_DEVICES] = vera_devices

    vera_scenes = []
    for scene in all_scenes:
        vera_scenes.append(scene)
    hass.data[VERA_SCENES] = vera_scenes

    for component in VERA_COMPONENTS:
        discovery.load_platform(hass, component, DOMAIN, {}, base_config)

    return True
Exemplo n.º 7
0
def get_devices(hass, config):
    """ Find and return Vera Sensors. """
    import pyvera as veraApi

    base_url = config.get('vera_controller_url')
    if not base_url:
        _LOGGER.error(
            "The required parameter 'vera_controller_url'"
            " was not found in config"
        )
        return False

    device_data = config.get('device_data', {})

    vera_controller, created = veraApi.init_controller(base_url)

    if created:
        def stop_subscription(event):
            """ Shutdown Vera subscriptions and subscription thread on exit"""
            _LOGGER.info("Shutting down subscriptions.")
            vera_controller.stop()

        hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_subscription)

    categories = ['Temperature Sensor',
                  'Light Sensor',
                  'Humidity Sensor',
                  'Sensor']
    devices = []
    try:
        devices = vera_controller.get_devices(categories)
    except RequestException:
        # There was a network related error connecting to the vera controller
        _LOGGER.exception("Error communicating with Vera API")
        return False

    vera_sensors = []
    for device in devices:
        extra_data = device_data.get(device.device_id, {})
        exclude = extra_data.get('exclude', False)

        if exclude is not True:
            vera_sensors.append(
                VeraSensor(device, vera_controller, extra_data))

    return vera_sensors
Exemplo n.º 8
0
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
    """ Find and return Vera lights. """
    import pyvera as veraApi

    base_url = config.get('vera_controller_url')
    if not base_url:
        _LOGGER.error(
            "The required parameter 'vera_controller_url'"
            " was not found in config"
        )
        return False

    device_data = config.get('device_data', {})

    vera_controller, created = veraApi.init_controller(base_url)

    if created:
        def stop_subscription(event):
            """ Shutdown Vera subscriptions and subscription thread on exit"""
            _LOGGER.info("Shutting down subscriptions.")
            vera_controller.stop()

        hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_subscription)

    devices = []
    try:
        devices = vera_controller.get_devices([
            'Switch',
            'On/Off Switch',
            'Dimmable Switch'])
    except RequestException:
        # There was a network related error connecting to the vera controller
        _LOGGER.exception("Error communicating with Vera API")
        return False

    lights = []
    for device in devices:
        extra_data = device_data.get(device.device_id, {})
        exclude = extra_data.get('exclude', False)

        if exclude is not True:
            lights.append(VeraLight(device, vera_controller, extra_data))

    add_devices_callback(lights)
Exemplo n.º 9
0
def get_devices(hass, config):
    """Setup the Vera Sensors."""
    import pyvera as veraApi

    base_url = config.get('vera_controller_url')
    if not base_url:
        _LOGGER.error("The required parameter 'vera_controller_url'"
                      " was not found in config")
        return False

    device_data = config.get('device_data', {})

    vera_controller, created = veraApi.init_controller(base_url)

    if created:

        def stop_subscription(event):
            """Shutdown Vera subscriptions and subscription thread on exit."""
            _LOGGER.info("Shutting down subscriptions.")
            vera_controller.stop()

        hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_subscription)

    categories = [
        'Temperature Sensor', 'Light Sensor', 'Humidity Sensor', 'Sensor'
    ]
    devices = []
    try:
        devices = vera_controller.get_devices(categories)
    except RequestException:
        # There was a network related error connecting to the vera controller.
        _LOGGER.exception("Error communicating with Vera API")
        return False

    vera_sensors = []
    for device in devices:
        extra_data = device_data.get(device.device_id, {})
        exclude = extra_data.get('exclude', False)

        if exclude is not True:
            vera_sensors.append(VeraSensor(device, vera_controller,
                                           extra_data))

    return vera_sensors
Exemplo n.º 10
0
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
    """ Find and return Vera lights. """
    import pyvera as veraApi

    base_url = config.get('vera_controller_url')
    if not base_url:
        _LOGGER.error("The required parameter 'vera_controller_url'"
                      " was not found in config")
        return False

    device_data = config.get('device_data', {})

    vera_controller, created = veraApi.init_controller(base_url)

    if created:

        def stop_subscription(event):
            """ Shutdown Vera subscriptions and subscription thread on exit"""
            _LOGGER.info("Shutting down subscriptions.")
            vera_controller.stop()

        hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_subscription)

    devices = []
    try:
        devices = vera_controller.get_devices(
            ['Switch', 'On/Off Switch', 'Dimmable Switch'])
    except RequestException:
        # There was a network related error connecting to the vera controller
        _LOGGER.exception("Error communicating with Vera API")
        return False

    lights = []
    for device in devices:
        extra_data = device_data.get(device.device_id, {})
        exclude = extra_data.get('exclude', False)

        if exclude is not True:
            lights.append(VeraLight(device, vera_controller, extra_data))

    add_devices_callback(lights)
Exemplo n.º 11
0
def setup(hass, base_config):
    """Common setup for Vera devices."""
    global VERA_CONTROLLER
    import pyvera as veraApi

    config = base_config.get(DOMAIN)
    base_url = config.get(CONF_CONTROLLER)
    VERA_CONTROLLER, _ = veraApi.init_controller(base_url)

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

    hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_subscription)

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

    exclude = config.get(CONF_EXCLUDE)

    lights_ids = config.get(CONF_LIGHTS)

    for device in all_devices:
        if device.device_id in exclude:
            continue
        dev_type = map_vera_device(device, lights_ids)
        if dev_type is None:
            continue
        VERA_DEVICES[dev_type].append(device)

    for component in 'binary_sensor', 'sensor', 'light', 'switch', 'lock':
        discovery.load_platform(hass, component, DOMAIN, {}, base_config)

    return True
Exemplo n.º 12
0
def setup(hass, base_config):
    """Common setup for Vera devices."""
    global VERA_CONTROLLER
    import pyvera as veraApi

    config = base_config.get(DOMAIN)
    base_url = config.get(CONF_CONTROLLER)
    VERA_CONTROLLER, _ = veraApi.init_controller(base_url)

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

    hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_subscription)

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

    exclude = config.get(CONF_EXCLUDE)

    lights_ids = config.get(CONF_LIGHTS)

    for device in all_devices:
        if device.device_id in exclude:
            continue
        dev_type = map_vera_device(device, lights_ids)
        if dev_type is None:
            continue
        VERA_DEVICES[dev_type].append(device)

    for component in VERA_COMPONENTS:
        discovery.load_platform(hass, component, DOMAIN, {}, base_config)

    return True
Exemplo n.º 13
0
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)