High-level Cloud functions

Module for handling Cozify Cloud highlevel operations.

cozify.cloud.authenticate(trustCloud=True, trustHub=True, remote=False, autoremote=True)[source]

Authenticate with the Cozify Cloud and Hub.

Interactive only when absolutely needed, mostly on the first run. By default authentication is run selectively only for the portions needed. Hub authentication lives in the Cloud module since the authentication is obtained from the cloud.

Authentication is a multistep process:
  • trigger sending OTP to email address
  • perform email login with OTP to acquire cloud token
  • acquire hub information and authenticate with hub with cloud token
  • store hub token for further use
Parameters:
  • trustCloud (bool) – Trust current stored state of cloud auth. Default True.
  • trustHub (bool) – Trust current stored state of hub auth. Default True.
  • remote (bool) – Treat a hub as being outside the LAN, i.e. calls will be routed via the Cozify Cloud remote call system. Defaults to False.
  • autoremote (bool) – Autodetect hub LAN presence and flip to remote mode if needed. Defaults to True.
Returns:

True on authentication success. Failure will result in an exception.

Return type:

bool

cozify.cloud.email(new_email=None)[source]

Get currently used cloud account email or set a new one.

Returns:Cloud user account email address.
Return type:str
cozify.cloud.ping(autorefresh=True, expiry=None)[source]

Test cloud token validity. On success will also trigger a refresh if it’s needed by the current key expiry.

Parameters:
  • refresh (bool) – Wether to perform a autorefresh check after a successful ping. Defaults to True.
  • expiry (datetime.timedelta) – timedelta object for duration how often cloud_token will be auto-refreshed when cloud.ping() is called. If not set, cloud.refresh() defaults are used.
Returns:

validity of stored token.

Return type:

bool

cozify.cloud.refresh(force=False, expiry=datetime.timedelta(1))[source]

Renew current cloud token and store new token in state.

This call will only succeed if the current cloud token is still valid. A new refreshed token is requested from the API only if sufficient time has passed since the previous refresh.

Parameters:
  • force (bool) – Set to True to always perform a refresh regardless of time passed since previous refresh.
  • expiry (datetime.timedelta) – timedelta object for duration of refresh expiry. Defaults to one day.
Returns:

Success of refresh attempt, True also when expiry wasn’t over yet even though no refresh was performed.

Return type:

bool

cozify.cloud.resetState()[source]

Reset stored cloud state.

Any further authentication flow will start from a clean slate. Hub state is left intact.

cozify.cloud.token(new_token=None)[source]

Get currently used cloud_token or set a new one.

Returns:Cloud remote authentication token.
Return type:str