def switch(command, i=0):

    try:
        arlo = Arlo(ArloLogin, ArloPassword)
        base = arlo.GetDevices('basestation')[
            0]  # get base station info, assuming only 1 is available
        camera = arlo.GetDevices('camera')[
            0]  # get camera info, assuming only 1 is available

        print("Command: " + command)

        if command == "status":
            print("ARLO -- Camera current mode: " + get_current_state(arlo))

        elif command == "armed":
            #print("ARLO -- Camera old mode: " + get_current_state(arlo))
            arlo.Arm(base)
            print("ARLO -- Camera new mode: " + get_current_state(arlo))

        else:
            #print("ARLO -- Camera old mode: " + get_current_state(arlo))
            arlo.Disarm(base)
            print("ARLO -- Camera new mode: " + get_current_state(arlo))

    # On tente d'exécuter la commande 8 fois maximum
    except Exception as e:
        print(e)
        if i < 8:
            print("ARLO -- Connexion Error - new try ... (" + str(i + 1) +
                  "/8)")
            switch(command, i + 1)
            return
        else:
            print("ARLO -- Connexion Errors -- command failed " + str(i) +
                  " times. Exit")
            raise SystemExit(1)  # Return failure

    # Enregistre l'état de la batterie (pour lecture dans Domoticz)
    time.sleep(1)
    cam_battery_level = arlo.GetCameraState(
        base)["properties"][0]["batteryLevel"]
    print("ARLO -- Camera Battery: " + str(cam_battery_level) +
          " % -> into file /tmp/arlo_cam1.txt")
    with open('/tmp/arlo_cam1.txt', 'w') as f:
        f.write(str(cam_battery_level))
示例#2
0
try:
    # Instantiating the Arlo object automatically calls Login(), which returns an oAuth token that gets cached.
    # Subsequent successful calls to login will update the oAuth token.
    arlo = Arlo(USERNAME, PASSWORD)
    # At this point you're logged into Arlo.

    # Get the list of devices and filter on device type to only get the basestation.
    # This will return an array which includes all of the basestation's associated metadata.
    basestations = arlo.GetDevices('basestation')

    # Get the list of devices and filter on device type to only get the camera.
    # This will return an array which includes all of the camera's associated metadata.
    cameras = arlo.GetDevices('camera')

    # Get current state payload
    state = arlo.GetCameraState(cameras[0])
    print(state["properties"][0]["nightLight"])

    # night light on
    arlo.SetNightLightOn(cameras[0])

    # night light timer on
    arlo.SetNightLightTimerOn(cameras[0], 500)

    # night light color mode
    arlo.SetNightLightMode(cameras[0],
                           mode={
                               "blue": 255,
                               "green": 255,
                               "red": 255
                           })  # or mode="rainbow"
示例#3
0
class ArloMqtt:
    def __init__(self, args):
        self.log = logging.getLogger(type(self).__name__)
        if args.debug:
            self.log.setLevel(logging.DEBUG)

        self.report_interval = args.report_interval

        self.report_thread = threading.Thread(target=self.report_thread_fn,
                                              daemon=True)
        self.stop = threading.Event()
        self.last_reported_ts = time.time()

        self.arlo_user = args.arlo_user
        self.arlo_pass = args.arlo_pass

        self.mqtt_settings = {
            'MQTT_BROKER': args.broker,
            'MQTT_PORT': args.port,
            'MQTT_USERNAME': args.mqtt_user,
            'MQTT_PASSWORD': args.mqtt_pass,
        }

    def report_thread_fn(self):
        try:
            while True:
                self.report()
                self.last_reported_ts = time.time()

                if self.stop.wait(self.report_interval):
                    break
        except Exception:
            self.log.exception('Report thread failed')
        finally:
            self.log.info('Report thread stopped')
            self.stop.set()

    def run(self):
        self.log.info('Connecting to Arlo')
        self.arlo = Arlo(self.arlo_user, self.arlo_pass)
        self.arlo_bases = {}
        self.arlo_cams = {}

        self.report_thread.start()

        try:
            while True:
                if self.stop.wait(self.report_interval * 2):
                    break

                if time.time(
                ) - self.last_reported_ts > self.report_interval * 2:
                    self.log.error('Report timeout')
                    break
        finally:
            self.log.info('Main thread stopped')
            self.stop.set()

    def report(self):
        self.log.info('Reporting status')

        # Fetching devices and states from Arlo
        devices = [
            dev for dev in self.arlo.GetDevices() if dev['state'] != 'removed'
        ]

        bases = {
            dev['deviceId']: dev
            for dev in devices if dev['deviceType'] == 'basestation'
        }

        cams = {
            dev['deviceId']: dev
            for dev in devices if dev['deviceType'] == 'camera'
        }

        for mode in self.arlo.GetModesV2():
            id = mode['gatewayId']
            if id in bases:
                bases[id]['modeState'] = mode

        for base in bases.values():
            for state in self.arlo.GetCameraState(base)['properties']:
                id = state['serialNumber']
                if id in cams:
                    cams[id]['cameraState'] = state

        # Syncing devices and states to MQTT Homie
        for id, base in bases.items():
            if id not in self.arlo_bases:
                self.arlo_bases[id] = HomieArloBaseStation(
                    id=id,
                    name=base['deviceName'],
                    mqtt_settings=self.mqtt_settings,
                    arlo=self.arlo,
                    base_station=base,
                    log=self.log.getChild('homie'),
                )

            self.arlo_bases[id].node.active_modes = ','.join(
                base['modeState']['activeModes'])

        for id in [id for id in self.arlo_bases if id not in bases]:
            del self.arlo_bases[id]

        for id, cam in cams.items():
            if id not in self.arlo_cams:
                self.arlo_cams[id] = HomieArloCamera(
                    id=id,
                    name=cam['deviceName'],
                    mqtt_settings=self.mqtt_settings,
                    arlo=self.arlo,
                    base_station=bases[cam['parentId']],
                    log=self.log.getChild('homie'),
                )

            self.arlo_cams[id].node.privacy_active = cam['cameraState'][
                'privacyActive']
            self.arlo_cams[id].node.battery_level = cam['cameraState'][
                'batteryLevel']
            self.arlo_cams[id].node.charging_state = cam['cameraState'][
                'chargingState']
            self.arlo_cams[id].node.connection_state = cam['cameraState'][
                'connectionState']
            self.arlo_cams[id].node.signal_strength = cam['cameraState'][
                'signalStrength']
            self.arlo_cams[id].node.last_image = cam['presignedLastImageUrl']

        for id in [id for id in self.arlo_cams if id not in cams]:
            del self.arlo_cams[id]
示例#4
0
    devices = arlo.GetDevices()
    for d in devices:
        _deviceId = d['deviceId']
        device_map[_deviceId] = {}
        device_map[_deviceId]['name'] = d['deviceName']

    # fetch basestations
    if args.verbose:
        print(sys.argv[0] + ": Fetching basestations")
    basestations = arlo.GetDevices('basestation')

    for station in basestations:
        if station['connectivity']['connected'] == True:
            if args.verbose:
                print(sys.argv[0] + ": Fetching cameras attached to basestation", station['deviceName'])
            stationcameras = arlo.GetCameraState(station)
            for camera in stationcameras['properties']:
                _serialNumber = camera['serialNumber']
                _batteryLevel = camera['batteryLevel']
                device_map[_serialNumber]['batteryLevel'] = camera['batteryLevel']
                device_map[_serialNumber]['connectionState'] = camera['connectionState']
                device_map[_serialNumber]['signalStrength'] = camera['signalStrength']
                device_map[_serialNumber]['baseStation'] = station['deviceName']


    # logout
    if args.verbose:
        print(sys.argv[0] + ": Logging out")
    arlo.Logout()

except Exception as e: