ugokukun.cannon_wrapper

Wrapper for Cannon camera.

class ugokukun.cannon_wrapper.CannonWrapper(wait_time: float = 3, max_attempts: int = 5, req_timeout: Tuple[float, float] = (3.0, 7.5), ip_port: str = '192.168.1.2:8080', auto_power_off: bool = False, sync_time: bool = True, log_path: str = 'log.txt')[source]

Bases: object

Wrapper for Cannon ccapi.

An instance of this class represents a single Cannon camera connection.

wait_time

Wait time between attempts.

Type:

float

req_timeout

Request timeout.

Type:

Tuple[float, float]

ip_port

IP address and port of the camera. Format is: {IP address}:{port}.

Type:

str

auto_power_off

Disables auto power off if False.

Type:

bool

log_path

Path of log file for logging.

Type:

str

logger

Logger for logging.

Type:

logging.Logger

api_url

List of API URLs.

Type:

List[str]

available_api

Available API.

Type:

Dict

device_info

Device information.

Type:

Dict

settings

Shooting parameters.

Type:

Dict

dump_attributes(ouput_path: str = 'camera_settings.json') None[source]

Dump all settings to JSON file.

Parameters:

ouput_path (str, optional) – Path to the output file., by default “camera_settings.json”

Returns:

Dumped settings.

Return type:

Dict

get_full_uri(api_str: str) str[source]

Get full URI. I was not sure if there would be different versions of the same API. If that is not the case, the function can be simplified.

I was not sure if there would be different versions of the same API command in different API versions. If that is not the case, the function can be simplified.

Parameters:

api_str (str) – API URL string after: “http://{self.ip_address}:{self.port}/ccapi/”version”. Example: “/shooting/control/shutterbutton”.

Returns:

Full API URL of the newest version of the input API. Example: “http://192.168.1.2:8080/ccapi/ver100/shooting/control/shutterbutton

Return type:

str

Notes

I was not sure if there would be different versions of the same API command in different API versions. If that is not the case, the function can be simplified.

get_shooting_param() Response[source]

Get all shooting parameters.

Returns:

Shooting parameters.

Return type:

req.models.Response

Notes

self.settings[“color_temperature”][“ability”] is changed to a list of available color temperatures. .. rubric:: Example

Before: {“min”: 2500, “max”: 10000, “step”: 100} After: [2500, 2600, 2700, …, 10000]

http_delete(api_str: str, *args, **kwargs) Response[source]

Wrapper to repeat HTTP requests until success or max_attempts is reached.

Repeat HTTP requests until success or max_attempts is reached. Only return when status_code is 200, raise error otherwise.

Returns:

Response of the request.

Return type:

req.models.Response

Raises:
  • timeout_err – timeout error

  • connection_err – network problems

  • http_err – invalid HTTP response

  • redirect_err – bad URL

  • req_err – all exceptions that requests can raise

  • ConnectionError – if failed to get response

http_get(api_str: str, *args, **kwargs) Response[source]

Wrapper to repeat HTTP requests until success or max_attempts is reached.

Repeat HTTP requests until success or max_attempts is reached. Only return when status_code is 200, raise error otherwise.

Returns:

Response of the request.

Return type:

req.models.Response

Raises:
  • timeout_err – timeout error

  • connection_err – network problems

  • http_err – invalid HTTP response

  • redirect_err – bad URL

  • req_err – all exceptions that requests can raise

  • ConnectionError – if failed to get response

http_post(api_str: str, *args, **kwargs) Response[source]

Wrapper to repeat HTTP requests until success or max_attempts is reached.

Repeat HTTP requests until success or max_attempts is reached. Only return when status_code is 200, raise error otherwise.

Returns:

Response of the request.

Return type:

req.models.Response

Raises:
  • timeout_err – timeout error

  • connection_err – network problems

  • http_err – invalid HTTP response

  • redirect_err – bad URL

  • req_err – all exceptions that requests can raise

  • ConnectionError – if failed to get response

http_put(api_str: str, *args, **kwargs) Response[source]

Wrapper to repeat HTTP requests until success or max_attempts is reached.

Repeat HTTP requests until success or max_attempts is reached. Only return when status_code is 200, raise error otherwise.

Returns:

Response of the request.

Return type:

req.models.Response

Raises:
  • timeout_err – timeout error

  • connection_err – network problems

  • http_err – invalid HTTP response

  • redirect_err – bad URL

  • req_err – all exceptions that requests can raise

  • ConnectionError – if failed to get response

kill_auto_power_off() Response[source]

Disable auto power off.

Returns:

Auto power off result.

Return type:

req.models.Response

set_aperture(aperture: str) Response[source]

Set aperture.

Payload example: {“value”: “f4.0”}

Parameters:

aperture (str) – Aperture. Example: “f4.0”

Returns:

Response of the request.

Return type:

req.models.Response

set_color_temp(color_temp: int) Response[source]

Set color temperature.

Payload example: {“value”: 4000}”

Parameters:

color_temp (int) – Color temperature. Example: 4000

Returns:

Response of the request.

Return type:

req.models.Response

set_exposure(exposure: str) Response[source]

Set exposure.

Payload example: {“value”: “-2_2/3”}

Parameters:

exposure (str) – Exposure. Example: “-2_2/3”

Returns:

Response of the request.

Return type:

req.models.Response

set_iso(iso: str) Response[source]

Set ISO value.

Payload example: {“value”: “3200”}

Parameters:

iso (str) – ISO. Example: “3200”

Returns:

Response of the request.

Return type:

req.models.Response

set_shooting_settings(param: str, value: str) Response[source]

Set shooting parameters.

Parameters:
  • param (str) – Parameter to be set, such as: - “shutter_speed” - “aperture” - “iso” - “exposure” - “whitebalance” - “colortemperature” Valid entries are hard coded in this method.

  • value (str) – Value of the parameter. Depends on the parameter. payload is {“value”: value}

Returns:

Response of the request.

Return type:

req.models.Response

Raises:

ValueError – If invalid param is provided.

set_shutter_speed(shutter_speed: str) Response[source]

Set shutter speed.

Payload example: {“value”: “5””} The backslash is an excape charactor.

Parameters:

shutter_speed (str) – Shutter speed. Example: “5””

Returns:

Response of the request.

Return type:

req.models.Response

set_white_balance(white_balance: str) Response[source]

Set white balance.

Payload example: {“value”: “auto”}

Parameters:

white_balance (str) – White balance. Example: “auto”

Returns:

Response of the request.

Return type:

req.models.Response

shutter(af: bool = False) Response[source]

Take a picture.

Payload example: {“af”: False}.”

Parameters:

af (bool, optional) – Auto focus. Key value for payload., by default False

Returns:

Shutter button response.

Return type:

req.models.Response

sync_time() Response[source]

Set camera time to current time (of the computer).

Returns:

Response of the request.

Return type:

req.models.Response

ugokukun.cannon_wrapper._req_handle(func: Callable[[Any, str, Any], Any]) Callable[[Any, str, Any], Any][source]