Low-level Hub API calls

Module for all Cozify Hub API 1:1 calls

cozify.hub_api.apiPath

str – 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.

cozify.hub_api.devices(**kwargs)[source]

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)[source]

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)[source]

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_off(device_id, **kwargs)[source]

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.devices_command_on(device_id, **kwargs)[source]

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_state(*, device_id, state, **kwargs)[source]

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.get(call, hub_token_header=True, base='/cc/1.8', **kwargs)[source]

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.hub(**kwargs)[source]

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

Returns:Hub state dict.
Return type:dict
cozify.hub_api.put(call, payload, hub_token_header=True, base='/cc/1.8', **kwargs)[source]

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 /.
  • payload (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.tz(**kwargs)[source]

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