Beispiel #1
0
def main() -> None:
    """Run main code entrypoint."""
    sys.path.insert(
        0, os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))

    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 = VeraController(args.url)
    controller.start()

    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))

        dv = controller.get_device_by_id(39)
        print("device")
        print(dv)
        dv.set_switch_state(1)

    finally:
        # Stop the subscription listening thread so we can quit
        controller.stop()
Beispiel #2
0
def main() -> None:
    """Run main code entrypoint."""
    sys.path.insert(
        0, os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))

    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 = VeraController(args.url)
    controller.start()

    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, VeraGarageDoor):
                if args.close:
                    device.switch_off()
                else:
                    device.switch_on()

    finally:
        # Stop the subscription listening thread so we can quit
        controller.stop()
Beispiel #3
0
def test_controller_custom_subscription_registry() -> None:
    """Test function."""
    class CustomSubscriptionRegistry(pyvera.AbstractSubscriptionRegistry):
        """Test registry."""
        def start(self) -> None:
            """Start the polling."""

        def stop(self) -> None:
            """Stop the polling."""

    controller = VeraController("URL", CustomSubscriptionRegistry())
    assert controller.subscription_registry.get_controller() == controller
Beispiel #4
0
def test_controller_custom_subscription_registry() -> None:
    """Test function."""
    class CustomSubscriptionRegistry(pyvera.AbstractSubscriptionRegistry):
        """Test registry."""
        def __init__(self, controller: VeraController) -> None:
            """Init the object."""
            super(CustomSubscriptionRegistry, self).__init__(controller)
            self.my_controller = controller

        def start(self) -> None:
            """Start the polling."""

        def stop(self) -> None:
            """Stop the polling."""

    controller = VeraController("URL", CustomSubscriptionRegistry)
    subscription_registry = cast(CustomSubscriptionRegistry,
                                 controller.subscription_registry)
    assert subscription_registry.my_controller == controller
Beispiel #5
0
def main() -> None:
    """Run main code entrypoint."""
    sys.path.insert(
        0, os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))

    parser = argparse.ArgumentParser(description="set-and-delete-door-code")
    parser.add_argument("-u",
                        "--url",
                        help="Vera URL, e.g. http://192.168.1.161:3480;",
                        required=True)
    parser.add_argument("-n",
                        "--name",
                        help='Name eg: "John Doe"',
                        required=True)
    parser.add_argument("-i", "--id", help='Device ID: "123"', required=True)
    args = parser.parse_args()

    # Start the controller
    controller = VeraController(args.url)
    controller.start()

    try:
        device = controller.get_device_by_id(int(args.id))

        if isinstance(device, VeraLock):
            pins = device.get_pin_codes()
            found_slot = None
            for slot, name, _ in pins:
                if name == args.name:
                    found_slot = slot
            if found_slot is None:
                print("No matching slot found\n")
                return
            result = device.clear_slot_pin(slot=int(found_slot))
            if result.status_code == 200:
                print("\nCommand succesfully sent to Lock \
                \nWait for the lock to process the request")
            else:
                print("\nLock command " + result.text)

    finally:
        # Stop the subscription listening thread so we can quit
        controller.stop()
Beispiel #6
0
def main() -> None:
    """Run main code entrypoint."""
    sys.path.insert(
        0, os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))

    parser = argparse.ArgumentParser(description="set-and-delete-door-code")
    parser.add_argument("-u",
                        "--url",
                        help="Vera URL, e.g. http://192.168.1.161:3480;",
                        required=True)
    parser.add_argument("-n",
                        "--name",
                        help='Name eg: "John Doe"',
                        required=True)
    parser.add_argument("-p", "--pin", help='Pin eg: "5678"', required=True)
    parser.add_argument("-i", "--id", help='Device ID: "123"', required=True)
    args = parser.parse_args()

    # Start the controller
    controller = VeraController(args.url)
    controller.start()

    try:
        device = controller.get_device_by_id(int(args.id))

        if isinstance(device, VeraLock):
            # show exisiting door codes
            print("Existing door codes:\n {}".format(device.get_pin_codes()))

            # set a new door code
            result = device.set_new_pin(name=args.name, pin=args.pin)

            # printing the status code and error if any for debug logs
            # print("status:"+str(result.status_code), result.text)

            if result.status_code == 200:
                print("\nCommand succesfully sent to Lock \
                \nWait for the lock to process the request")
            else:
                print("\nLock command " + result.text)
    finally:
        # Stop the subscription listening thread so we can quit
        controller.stop()
Beispiel #7
0
def main() -> None:
    """Run main code entrypoint."""
    sys.path.insert(
        0, os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))

    parser = argparse.ArgumentParser(description="show-lock-info")
    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 = VeraController(args.url)
    controller.start()

    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
        for device in all_devices:
            if isinstance(device, VeraLock):
                print("{} {} ({})".format(
                    type(device).__name__, device.name, device.device_id))
                print("    comm_failure: {}".format(device.comm_failure))
                print("    room_id: {}".format(device.room_id))
                print("    is_locked(): {}".format(device.is_locked()))
                print("    get_pin_failed(): {}".format(
                    device.get_pin_failed()))
                print("    get_unauth_user(): {}".format(
                    device.get_unauth_user()))
                print("    get_lock_failed(): {}".format(
                    device.get_lock_failed()))
                print("    get_last_user(): {}".format(device.get_last_user()))
                print("    get_pin_codes(): {}".format(device.get_pin_codes()))

    finally:
        # Stop the subscription listening thread so we can quit
        controller.stop()
Beispiel #8
0
    def new_instance(self, api_data: VeraApiData) -> VeraControllerData:
        """Create new instance of controller."""
        base_url = "http://127.0.0.1:123"

        def callback(req: requests.PreparedRequest) -> ResponsesResponse:
            nonlocal api_data
            return handle_request(req, api_data)

        self.rsps.add_callback(
            method=responses.GET,
            url=re.compile(f"{base_url}/data_request?.*"),
            callback=callback,
            content_type="application/json",
        )

        controller = VeraController("http://127.0.0.1:123")
        controller.data_request({"id": "sdata"})
        controller.start()

        # Stop the controller after the test stops and fixture is torn down.
        self.pytest_req.addfinalizer(controller.stop)

        return VeraControllerData(api_data=api_data, controller=controller)
Beispiel #9
0
 def setup_callback(controller: pv.VeraController) -> None:
     controller.temperature_units = "F"
Beispiel #10
0
 def setup_callback(controller: pv.VeraController) -> None:
     controller.get_devices()[0].is_trippable = False
Beispiel #11
0
 def setup_callback(controller: VeraController, hass_config: dict) -> None:
     controller.temperature_units = "F"
Beispiel #12
0
 def setup_callback(controller: VeraController, hass_config: dict) -> None:
     controller.get_devices()[0].is_trippable = False
def main() -> None:
    """Run main code entrypoint."""
    sys.path.insert(
        0, os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))

    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()

    # Start the controller
    controller = VeraController(args.url)
    controller.start()

    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, 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()

        # Loop until someone hits Ctrl-C to interrupt the listener
        try:
            all_locked = False
            while not all_locked:
                time.sleep(1)
                all_locked = True
                for device in lock_devices:
                    if not device.is_locked():
                        all_locked = False
            print("All doors are now locked")

        except KeyboardInterrupt:
            print("Got interrupted by user")

        # Unregister our callback
        for device in lock_devices:
            controller.unregister(device, device_info_callback)

    finally:
        # Stop the subscription listening thread so we can quit
        controller.stop()
Beispiel #14
0
def main() -> None:
    """Run main code entrypoint."""
    sys.path.insert(
        0, os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))

    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()

    # Start the controller
    controller = VeraController(args.url)
    controller.start()

    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)
        print("Initial values: {}".format(found_device.get_all_values()))
        print("Initial alerts: {}".format(found_device.get_alerts()))

        # Loop until someone hits Ctrl-C to interrupt the listener
        try:
            while True:
                time.sleep(1)
        except KeyboardInterrupt:
            print("Got interrupted by user")

        # Unregister our callback
        controller.unregister(found_device, device_info_callback)

    finally:
        # Stop the subscription listening thread so we can quit
        controller.stop()