# Path: cozify/cloud.py
# def authenticate(trustCloud=True, trustHub=True, remote=False, autoremote=True):
# def resetState():
# def update_hubs():
# def ping(autorefresh=True, expiry=None):
# def refresh(force=False, expiry=datetime.timedelta(days=1)):
# def _need_refresh(force, expiry):
# def _need_cloud_token(trust=True):
# def _need_hub_token(trust=True):
# def _getotp():
# def _getEmail():  # pragma: no cover
# def _getAttr(attr):
# def _setAttr(attr, value, commit=True):
# def _isAttr(attr):
# def token(new_token=None):
# def email(new_email=None):  # pragma: no cover
# 
# Path: cozify/hub.py
# def devices(*, capabilities=None, and_filter=False, **kwargs):
# def device_reachable(device_id, **kwargs):
# def device_exists(device_id, devs=None, state=None, **kwargs):
# def device_eligible(device_id, capability_filter, devs=None, state=None, **kwargs):
# def device_toggle(device_id, **kwargs):
# def device_state_replace(device_id, state, **kwargs):
# def device_on(device_id, **kwargs):
# def device_off(device_id, **kwargs):
# def light_temperature(device_id, temperature=2700, transition=0, **kwargs):
# def light_color(device_id, hue, saturation=1.0, transition=0, **kwargs):
# def light_brightness(device_id, brightness, transition=0, **kwargs):
# def remote(hub_id, new_state=None):
# def autoremote(hub_id, new_state=None):
# def tz(**kwargs):
# def ping(autorefresh=True, **kwargs):
# def name(hub_id):
# def host(hub_id):
# def token(hub_id, new_token=None):
# def hub_id(hub_name):
# def exists(hub_id):
# def default():
# def _getAttr(hub_id, attr, default=None, boolean=False):
# def _setAttr(hub_id, attr, value, commit=True):
# def _get_id(**kwargs):
# def _fill_kwargs(kwargs):
# def _clean_state(state):
# def _in_range(value, low, high, description='undefined'):
# def getDevices(**kwargs):  # pragma: no cover
# def getDefaultHub():  # pragma: no cover
# def getHubId(hub_name):  # pragma: no cover
# 
# Path: cozify/hub_api.py
# def _getBase(host, port=8893, **kwargs):
# def get(call, hub_token_header=True, base=apiPath, **kwargs):
# def put(call, data, hub_token_header=True, base=apiPath, **kwargs):
# def _call(*, call, method, hub_token_header, data=None, **kwargs):
# def hub(**kwargs):
# def tz(**kwargs):
# def devices(**kwargs):
# def devices_command(command, **kwargs):
# def devices_command_generic(*, device_id, command=None, request_type, **kwargs):
# def devices_command_state(*, device_id, state, **kwargs):
# def devices_command_on(device_id, **kwargs):
# def devices_command_off(device_id, **kwargs):
# 
# Path: cozify/config.py
# def _initXDG():
# def stateWrite(tmpstate=None):
# def setStatePath(filepath=_initXDG(), copy_current=False):
# def dump_state():
# def _initState(state_file):
# 
# Path: cozify/test/debug.py

# 
# Path: cozify/Error.py
# class AuthenticationError(Exception):
#     """Error raised for nonrecoverable authentication failures.
# 
#     Args:
#         message(str): Human readable error description
#     
#     Attributes:
#         message(str): Human readable error description
#     """
# 
#     def __init__(self, message):
#         self.message = message
# 
#     def __str__(self):
#         return 'Authentication error: {}'.format(self.message)
# 
# class APIError(Exception):
#     """Error raised for non-200 API return codes
# 
#     Args:
#         status_code(int): HTTP status code returned by the API
#         message(str): Potential error message returned by the API
#     
#     Attributes:
#         status_code(int): HTTP status code returned by the API
#         message(str): Potential error message returned by the API
#     """
# 
#     def __init__(self, status_code, message):
#         self.status_code = status_code
#         self.message = message
# 
#     def __str__(self):
#         return 'API error, {code}: {message}'.format(code=self.status_code, message=self.message)
# 
# class ConnectionError(ConnectionError):
#     """Error raised for connection level failures,
#     such as a lost internet connection.
# 
#     Args:
#         message(str): Potential error message returned by the requests library
# 
#     Attributes:
#         message(str): Potential error message returned by the requests library
#     """
# 
#     def __init__(self, message):
#         self.message = message
# 
#     def __str__(self):
#         return 'Connection error: {}'.format(self.message)


import pytest
from cozify import cloud, hub, hub_api, config
from cozify.test import debug
from cozify.test.fixtures import *
from cozify.Error import AuthenticationError, APIError, ConnectionError
from mbtest.imposters import Imposter, Predicate, Stub, Response
#!/usr/bin/env python3




@pytest.mark.live
def test_hub(live_cloud, live_hub):
    assert live_hub.ping()
    hub_id = live_hub.default()
    assert hub_api.hub(
        hub_id=hub_id,
        host=live_hub.host(hub_id),
        remote=live_hub.remote(hub_id),
        cloud_token=live_cloud.token(),
        hub_token=live_hub.token(hub_id))


@pytest.mark.mbtest
def test_hub_api_timeout(mock_server, tmp_hub):
    imposter = Imposter(
        Stub(Predicate(path="/hub/tz"), Response(body='Europe/Helsinki', wait=6000)))

# Path: cozify/cloud.py
# def authenticate(trustCloud=True, trustHub=True, remote=False, autoremote=True):
# def resetState():
# def update_hubs():
# def ping(autorefresh=True, expiry=None):
# def refresh(force=False, expiry=datetime.timedelta(days=1)):
# def _need_refresh(force, expiry):
# def _need_cloud_token(trust=True):
# def _need_hub_token(trust=True):
# def _getotp():
# def _getEmail():  # pragma: no cover
# def _getAttr(attr):
# def _setAttr(attr, value, commit=True):
# def _isAttr(attr):
# def token(new_token=None):
# def email(new_email=None):  # pragma: no cover
# 
# Path: cozify/hub.py
# def devices(*, capabilities=None, and_filter=False, **kwargs):
# def device_reachable(device_id, **kwargs):
# def device_exists(device_id, devs=None, state=None, **kwargs):
# def device_eligible(device_id, capability_filter, devs=None, state=None, **kwargs):
# def device_toggle(device_id, **kwargs):
# def device_state_replace(device_id, state, **kwargs):
# def device_on(device_id, **kwargs):
# def device_off(device_id, **kwargs):
# def light_temperature(device_id, temperature=2700, transition=0, **kwargs):
# def light_color(device_id, hue, saturation=1.0, transition=0, **kwargs):
# def light_brightness(device_id, brightness, transition=0, **kwargs):
# def remote(hub_id, new_state=None):
# def autoremote(hub_id, new_state=None):
# def tz(**kwargs):
# def ping(autorefresh=True, **kwargs):
# def name(hub_id):
# def host(hub_id):
# def token(hub_id, new_token=None):
# def hub_id(hub_name):
# def exists(hub_id):
# def default():
# def _getAttr(hub_id, attr, default=None, boolean=False):
# def _setAttr(hub_id, attr, value, commit=True):
# def _get_id(**kwargs):
# def _fill_kwargs(kwargs):
# def _clean_state(state):
# def _in_range(value, low, high, description='undefined'):
# def getDevices(**kwargs):  # pragma: no cover
# def getDefaultHub():  # pragma: no cover
# def getHubId(hub_name):  # pragma: no cover
# 
# Path: cozify/hub_api.py
# def _getBase(host, port=8893, **kwargs):
# def get(call, hub_token_header=True, base=apiPath, **kwargs):
# def put(call, data, hub_token_header=True, base=apiPath, **kwargs):
# def _call(*, call, method, hub_token_header, data=None, **kwargs):
# def hub(**kwargs):
# def tz(**kwargs):
# def devices(**kwargs):
# def devices_command(command, **kwargs):
# def devices_command_generic(*, device_id, command=None, request_type, **kwargs):
# def devices_command_state(*, device_id, state, **kwargs):
# def devices_command_on(device_id, **kwargs):
# def devices_command_off(device_id, **kwargs):
# 
# Path: cozify/config.py
# def _initXDG():
# def stateWrite(tmpstate=None):
# def setStatePath(filepath=_initXDG(), copy_current=False):
# def dump_state():
# def _initState(state_file):
# 
# Path: cozify/test/debug.py

# 
# Path: cozify/Error.py
# class AuthenticationError(Exception):
#     """Error raised for nonrecoverable authentication failures.
# 
#     Args:
#         message(str): Human readable error description
#     
#     Attributes:
#         message(str): Human readable error description
#     """
# 
#     def __init__(self, message):
#         self.message = message
# 
#     def __str__(self):
#         return 'Authentication error: {}'.format(self.message)
# 
# class APIError(Exception):
#     """Error raised for non-200 API return codes
# 
#     Args:
#         status_code(int): HTTP status code returned by the API
#         message(str): Potential error message returned by the API
#     
#     Attributes:
#         status_code(int): HTTP status code returned by the API
#         message(str): Potential error message returned by the API
#     """
# 
#     def __init__(self, status_code, message):
#         self.status_code = status_code
#         self.message = message
# 
#     def __str__(self):
#         return 'API error, {code}: {message}'.format(code=self.status_code, message=self.message)
# 
# class ConnectionError(ConnectionError):
#     """Error raised for connection level failures,
#     such as a lost internet connection.
# 
#     Args:
#         message(str): Potential error message returned by the requests library
# 
#     Attributes:
#         message(str): Potential error message returned by the requests library
#     """
# 
#     def __init__(self, message):
#         self.message = message
# 
#     def __str__(self):
#         return 'Connection error: {}'.format(self.message)


# Path: cozify/test/test_hub_api.py
import pytest
from cozify import cloud, hub, hub_api, config
from cozify.test import debug
from cozify.test.fixtures import *
from cozify.Error import AuthenticationError, APIError, ConnectionError
from mbtest.imposters import Imposter, Predicate, Stub, Response

#!/usr/bin/env python3




@pytest.mark.live
def test_hub(live_cloud, live_hub):
    assert live_hub.ping()
    hub_id = live_hub.default()
    assert hub_api.hub(
        hub_id=hub_id,
        host=live_hub.host(hub_id),
        remote=live_hub.remote(hub_id),
        cloud_token=live_cloud.token(),
        hub_token=live_hub.token(hub_id))


@pytest.mark.mbtest
def test_hub_api_timeout(mock_server, tmp_hub):
    imposter = Imposter(
        Stub(Predicate(path="/hub/tz"), Response(body='Europe/Helsinki', wait=6000)))

    with pytest.raises(ConnectionError) as e_info: