cozify.cloud

Module for handling Cozify Cloud highlevel operations.

Module Contents

Functions

authenticate(trustCloud=True, trustHub=True, remote=False, autoremote=True)

Authenticate with the Cozify Cloud and Hub.

resetState()

Reset stored cloud state.

update_hubs()

Fetch fresh hub ip addresses & names and update our local state.

ping(autorefresh=True, expiry=None)

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

refresh(force=False, expiry=datetime.timedelta(days=1))

Renew current cloud token and store new token in state.

_need_refresh(force, expiry)

Evaluate if refresh timer is already over or if forcing is valid.

_need_cloud_token(trust=True)

Validate current remote token and decide if we'll request it during authentication.

_need_hub_token(trust=True)

Validate current hub token and decide if we'll request it during authentication.

_getotp()

_getEmail()

_getAttr(attr)

Get cloud state attributes by attr name

_setAttr(attr, value, commit=True)

Set cloud state attributes by attr name

_isAttr(attr)

Check validity of attribute by attr name.

token(new_token=None)

Get currently used cloud_token or set a new one.

email(new_email=None)

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

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

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.resetState()

Reset stored cloud state.

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

cozify.cloud.update_hubs()

Fetch fresh hub ip addresses & names and update our local state.

cozify.cloud.ping(autorefresh=True, expiry=None)

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(days=1))

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._need_refresh(force, expiry)

Evaluate if refresh timer is already over or if forcing is valid.

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.

Returns

True if refresh should be done according to forcing and expiry.

Return type

bool

cozify.cloud._need_cloud_token(trust=True)

Validate current remote token and decide if we’ll request it during authentication.

Parameters

trust (bool) – Set to False to always decide to renew. Defaults to True.

Returns

True to indicate a need to request token.

Return type

bool

cozify.cloud._need_hub_token(trust=True)

Validate current hub token and decide if we’ll request it during authentication.

Parameters

trust (bool) – Set to False to always decide to renew. Defaults to True.

Returns

True to indicate a need to request token.

Return type

bool

cozify.cloud._getotp()
cozify.cloud._getEmail()
cozify.cloud._getAttr(attr)

Get cloud state attributes by attr name

Parameters

attr (str) – Name of cloud state attribute to retrieve

Returns

Value of attribute or exception on failure

Return type

str

cozify.cloud._setAttr(attr, value, commit=True)

Set cloud state attributes by attr name

Parameters
  • attr (str) – Name of cloud state attribute to overwrite. Attribute will be created if it doesn’t exist.

  • value (str) – Value to store

  • commit (bool) – True to commit state after set. Defaults to True.

cozify.cloud._isAttr(attr)

Check validity of attribute by attr name.

Returns

True if attribute exists

Return type

bool

cozify.cloud.token(new_token=None)

Get currently used cloud_token or set a new one.

Returns

Cloud remote authentication token.

Return type

str

cozify.cloud.email(new_email=None)

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

Returns

Cloud user account email address.

Return type

str