예제 #1
0
class FoscamCam(Camera):
    """An implementation of a Foscam IP camera."""
    def __init__(self, device_info):
        """Initialize a Foscam camera."""
        super(FoscamCam, self).__init__()

        ip_address = device_info.get(CONF_IP)
        port = device_info.get(CONF_PORT)
        self._username = device_info.get(CONF_USERNAME)
        self._password = device_info.get(CONF_PASSWORD)
        self._name = device_info.get(CONF_NAME)
        self._motion_status = False

        from foscam import FoscamCamera

        self._foscam_session = FoscamCamera(ip_address,
                                            port,
                                            self._username,
                                            self._password,
                                            verbose=False)

    def camera_image(self):
        """Return a still image reponse from the camera."""
        # Send the request to snap a picture and return raw jpg data
        # Handle exception if host is not reachable or url failed
        result, response = self._foscam_session.snap_picture_2()
        if result == FOSCAM_COMM_ERROR:
            return None

        return response

    @property
    def motion_detection_enabled(self):
        """Camera Motion Detection Status."""
        return self._motion_status

    def enable_motion_detection(self):
        """Enable motion detection in camera."""
        ret, err = self._foscam_session.enable_motion_detection()
        if ret == FOSCAM_COMM_ERROR:
            _LOGGER.debug("Unable to communicate with Foscam Camera: %s", err)
            self._motion_status = True
        else:
            self._motion_status = False

    def disable_motion_detection(self):
        """Disable motion detection."""
        ret, err = self._foscam_session.disable_motion_detection()
        if ret == FOSCAM_COMM_ERROR:
            _LOGGER.debug("Unable to communicate with Foscam Camera: %s", err)
            self._motion_status = True
        else:
            self._motion_status = False

    @property
    def name(self):
        """Return the name of this camera."""
        return self._name
예제 #2
0
class Foscam(HAInterface):
    MOTIONDETECTION_OFF = '0'
    MOTIONDETECTION_ON = '1'
    MOTIONDETECTION_ALERT = '2'

    _iteration = 0
    _poll_secs = 15

    def __init__(self, *args, **kwargs):
        super(Foscam, self).__init__(None, *args, **kwargs)

    def _init(self, *args, **kwargs):
        super(Foscam, self)._init(*args, **kwargs)
        self._host = kwargs.get('host', None)
        self._port = kwargs.get('port', None)
        self._username = kwargs.get('username', None)
        self._password = kwargs.get('password', None)
        self._interface = FoscamCamera(host=self._host,
                                       port=self._port,
                                       usr=self._username,
                                       pwd=self._password,
                                       verbose=False)

    def _readInterface(self, lastPacketHash):
        if not self._iteration < self._poll_secs:
            self._iteration = 0
            motion = self._interface.get_dev_state()[1]['motionDetectAlarm'][0]

            if motion == self.MOTIONDETECTION_ALERT:
                self._onCommand(command=Command.MOTION, address=self._host)

            if motion == self.MOTIONDETECTION_ON:
                self._onCommand(command=(Command.STILL))

            if motion == self.MOTIONDETECTION_OFF:
                self._onCommand(command=(Command.OFF))
        self._iteration += 1
        time.sleep(1)

    def activate(self, *args, **kwargs):
        self._interface.enable_motion_detection()

    def deactivate(self, *args, **kwargs):
        self._interface.disable_motion_detection()
예제 #3
0
class Foscam(HAInterface):
    MOTIONDETECTION_OFF = '0'
    MOTIONDETECTION_ON = '1'
    MOTIONDETECTION_ALERT = '2'

    _iteration = 0
    _poll_secs = 15

    def __init__(self, *args, **kwargs):
        super(Foscam, self).__init__(None, *args, **kwargs)

    def _init(self, *args, **kwargs):
        super(Foscam, self)._init(*args, **kwargs)
        self._host = kwargs.get('host', None)
        self._port = kwargs.get('port', None)
        self._username = kwargs.get('username', None)
        self._password = kwargs.get('password', None)
        self._interface = FoscamCamera(host=self._host, port=self._port, usr=self._username, pwd=self._password, verbose=False)

    def _readInterface(self, lastPacketHash):
	if not self._iteration < self._poll_secs:
		self._iteration = 0
		motion = self._interface.get_dev_state()[1]['motionDetectAlarm'][0]

		if motion == self.MOTIONDETECTION_ALERT:
		    self._onCommand(command=Command.MOTION, address=self._host)

		if motion == self.MOTIONDETECTION_ON:
		    self._onCommand(command=(Command.STILL))

		if motion == self.MOTIONDETECTION_OFF:
		    self._onCommand(command=(Command.OFF))
	self._iteration += 1
        time.sleep(1)

    def activate(self, *args, **kwargs):
        self._interface.enable_motion_detection()

    def deactivate(self, *args, **kwargs):
        self._interface.disable_motion_detection()