cozify.hub_api

Module for all Cozify Hub API 1:1 calls

cozify.hub_api.apiPath

Hub API endpoint path including version. Things may suddenly stop working if a software update increases the API version on the Hub. Incrementing this value until things work will get you by until a new version is published.

Type

str

Module Contents

Functions

_getBase(host, port=8893, **kwargs)

get(call, hub_token_header=True, base=apiPath, **kwargs)

GET method for calling hub API.

put(call, data, hub_token_header=True, base=apiPath, **kwargs)

PUT method for calling hub API. For rest of kwargs parameters see get()

_call(call, method, hub_token_header, data=None, **kwargs)

Backend for get & put

hub(**kwargs)

1:1 implementation of /hub API call. For kwargs see cozify.hub_api.get()

tz(**kwargs)

1:1 implementation of /hub/tz API call. For kwargs see cozify.hub_api.get()

devices(**kwargs)

1:1 implementation of /devices API call. For remaining kwargs see cozify.hub_api.get()

devices_command(command, **kwargs)

1:1 implementation of /devices/command. For kwargs see cozify.hub_api.put()

devices_command_generic(device_id, command=None, request_type, **kwargs)

Command helper for CMD type of actions.

devices_command_state(device_id, state, **kwargs)

Command helper for CMD type of actions.

devices_command_on(device_id, **kwargs)

Command helper for CMD_DEVICE_ON.

devices_command_off(device_id, **kwargs)

Command helper for CMD_DEVICE_OFF.

scenes(**kwargs)

Implementation of /scenes API call. For kwargs see cozify.hub_api.get()

scenes_command_state(scene_id, request_type, **kwargs)

Commands changing a scene's state. For kwargs see cozify.hub_api.put()

scenes_command_off(scene_id, **kwargs)

Command helper for CMD_SCENE_OFF.

scenes_command_on(scene_id, **kwargs)

Command helper for CMD_SCENE_ON.

Attributes

apiPath

cozify.hub_api.apiPath = /cc/1.14
cozify.hub_api._getBase(host, port=8893, **kwargs)
cozify.hub_api.get(call, hub_token_header=True, base=apiPath, **kwargs)

GET method for calling hub API.

Parameters
  • call (str) – API path to call after apiPath, needs to include leading /.

  • hub_token_header (bool) – Set to False to omit hub_token usage in call headers.

  • base (str) – Base path to call from API instead of global apiPath. Defaults to apiPath.

  • **host (str) – ip address or hostname of hub.

  • **hub_token (str) – Hub authentication token.

  • **remote (bool) – If call is to be local or remote (bounced via cloud).

  • **cloud_token (str) – Cloud authentication token. Only needed if remote = True.

cozify.hub_api.put(call, data, hub_token_header=True, base=apiPath, **kwargs)

PUT method for calling hub API. For rest of kwargs parameters see get()

Parameters
  • call (str) – API path to call after apiPath, needs to include leading /.

  • data (str) – json string to push out as the payload.

  • hub_token_header (bool) – Set to False to omit hub_token usage in call headers.

  • base (str) – Base path to call from API instead of global apiPath. Defaults to apiPath.

cozify.hub_api._call(call, method, hub_token_header, data=None, **kwargs)

Backend for get & put

Parameters
  • call (str) – Full API path to call.

  • method (function) – requests.get|put function to use for call.

cozify.hub_api.hub(**kwargs)

1:1 implementation of /hub API call. For kwargs see cozify.hub_api.get()

Returns

Hub state dict.

Return type

dict

cozify.hub_api.tz(**kwargs)

1:1 implementation of /hub/tz API call. For kwargs see cozify.hub_api.get()

Returns

Timezone of the hub, for example: ‘Europe/Helsinki’

Return type

str

cozify.hub_api.devices(**kwargs)

1:1 implementation of /devices API call. For remaining kwargs see cozify.hub_api.get()

Parameters

**mock_devices (dict) – If defined, returned as-is as if that were the result we received.

Returns

Full live device state as returned by the API

Return type

dict

cozify.hub_api.devices_command(command, **kwargs)

1:1 implementation of /devices/command. For kwargs see cozify.hub_api.put()

Parameters

command (dict) – dictionary of type DeviceData containing the changes wanted. Will be converted to json.

Returns

What ever the API replied or raises an APIEerror on failure.

Return type

str

cozify.hub_api.devices_command_generic(device_id, command=None, request_type, **kwargs)

Command helper for CMD type of actions. No checks are made wether the device supports the command or not. For kwargs see cozify.hub_api.put()

Parameters
  • device_id (str) – ID of the device to operate on.

  • request_type (str) – Type of CMD to run, e.g. CMD_DEVICE_OFF

  • command (dict) – Optional dictionary to override command sent. Defaults to None which is interpreted as { device_id, type }

Returns

What ever the API replied or raises an APIError on failure.

Return type

str

cozify.hub_api.devices_command_state(device_id, state, **kwargs)

Command helper for CMD type of actions. No checks are made wether the device supports the command or not. For kwargs see cozify.hub_api.put()

Parameters
  • device_id (str) – ID of the device to operate on.

  • state (dict) – New state dictionary containing changes.

Returns

What ever the API replied or raises an APIError on failure.

Return type

str

cozify.hub_api.devices_command_on(device_id, **kwargs)

Command helper for CMD_DEVICE_ON.

Parameters

device_id (str) – ID of the device to operate on.

Returns

What ever the API replied or raises an APIError on failure.

Return type

str

cozify.hub_api.devices_command_off(device_id, **kwargs)

Command helper for CMD_DEVICE_OFF.

Parameters

device_id (str) – ID of the device to operate on.

Returns

What ever the API replied or raises an APIException on failure.

Return type

str

cozify.hub_api.scenes(**kwargs)

Implementation of /scenes API call. For kwargs see cozify.hub_api.get()

Returns

Full scene state as returned by the API

Return type

dict

cozify.hub_api.scenes_command_state(scene_id, request_type, **kwargs)

Commands changing a scene’s state. For kwargs see cozify.hub_api.put()

Parameters
  • scene_id (str) – ID of the scene to operate on.

  • request_type (str) – the request type, i.e. CMD_SCENE_ON or CMD_SCENE_OFF.

Returns

Whatever the API replied or raises an APIError on failure.

Return type

str

cozify.hub_api.scenes_command_off(scene_id, **kwargs)

Command helper for CMD_SCENE_OFF.

Parameters

scene_id (str) – ID of the scene to operate on.

Returns

What ever the API replied or raises an APIException on failure.

Return type

str

cozify.hub_api.scenes_command_on(scene_id, **kwargs)

Command helper for CMD_SCENE_ON.

Parameters

scene_id (str) – ID of the scene to operate on.

Returns

What ever the API replied or raises an APIException on failure.

Return type

str