def main(): import os import logging from tion import TionApi, Breezer, Zone, MagicAir logging.basicConfig(level=logging.INFO) # initialization api email, password = os.environ.get("TION_AUTH").split(',') api = TionApi(email, password, save_auth=False) # getting current co2 level from magicair magicair = api.get_devices(name_part="magic")[0] print(f"magicair.co2: {magicair.co2}") # getting breezer breezer = api.get_devices(name_part="breezer")[0] # setting manual mode for breezer zone breezer.zone.mode = "manual" assert breezer.zone.send() is True, "Failed to send zone data" print(f"breezer.zone.mode: {breezer.zone.mode}") # setting breezer speed manually breezer.speed = 3 assert breezer.send() is True, "Failed to send breezer data" print(f"breezer.is_on: {breezer.is_on} breezer.speed: {breezer.speed}") # setting auto mode for breezer's zone breezer.zone.mode = "auto" assert breezer.zone.send() is True, "Failed to send zone data" print(f"breezer.zone.mode: {breezer.zone.mode}") # setting breezer minimum speed to 3 and maximum to 6 breezer.speed_min_set = 3 breezer.speed_max_set = 6 assert breezer.send() is True, "Failed to send breezer data" print(f"breezer.speed_min_set: {breezer.speed_min_set} breezer.speed_max_set: {breezer.speed_max_set}")
def setup(hass, config): """Set up Tion Component.""" from tion import TionApi, Breezer, MagicAir auth_fname = hass.config.path( "tion_auth" ) if config[DOMAIN][CONF_FILE_PATH] == DEFAULT_AUTH_FNAME else config[ DOMAIN][CONF_FILE_PATH] api = TionApi( config[DOMAIN][CONF_USERNAME], config[DOMAIN][CONF_PASSWORD], min_update_interval_sec=(config[DOMAIN][CONF_SCAN_INTERVAL]).seconds, auth_fname=auth_fname) assert api.authorization, "Couldn't get authorisation data!" _LOGGER.info(f"Api initialized with authorization {api.authorization}") hass.data[TION_API] = api discovery_info = {} for device in api.get_devices(): if device.valid: device_type = BREEZER_DEVICE if type(device) == Breezer else ( MAGICAIR_DEVICE if type(device) == MagicAir else None) if device_type: if "sensor" not in discovery_info: discovery_info["sensor"] = [] discovery_info["sensor"].append({ "type": device_type, "guid": device.guid }) if device_type == BREEZER_DEVICE: if "climate" not in discovery_info: discovery_info["climate"] = [] discovery_info["climate"].append({ "type": device_type, "guid": device.guid }) else: _LOGGER.info(f"Unused device {device}") else: _LOGGER.info( f"Skipped device {device}, because of 'valid' property") for device_type, devices in discovery_info.items(): discovery.load_platform(hass, device_type, DOMAIN, devices, config) _LOGGER.info(f"Found {len(devices)} {device_type} devices") # Return boolean to indicate that initialization was successful. return True
def api() -> TionApi: email, password = os.environ.get("TION_AUTH").split(',') return TionApi(email, password)
def magicair(api: TionApi) -> MagicAir: return api.get_devices(name_part="magic")[0]
def breezer(api: TionApi) -> Breezer: return api.get_devices(name_part="breezer 3s")[0]
def zone(api: TionApi) -> Breezer: return api.get_zones(name_part="гостиная")[0]
def api_bad_auth_fname() -> TionApi: email, password = os.environ.get("TION_AUTH").split(',') return TionApi(email, password, auth_fname="a:\\tion_auth")
def api_no_saved_auth() -> TionApi: email, password = os.environ.get("TION_AUTH").split(',') return TionApi(email, password, auth_fname=None)
def api_no_saved_auth() -> TionApi: email, password = os.environ.get("TION_AUTH").split(',') return TionApi(email, password, save_auth=False)
def test_tion_api_wait_for_task_returns_false_on_bad_task_id(api: TionApi): assert api.wait_for_task( "asdf") is False, "Must return False on lack of bad task_id!" sleep(TESTS_DELAY) # let the server "rest"
def test_tion_api_wait_for_task_returns_false_on_timeout_0_6(api: TionApi): assert api.wait_for_task( "asdf", max_time=0.6) is False, "Must return False on timeout!" sleep(TESTS_DELAY) # let the server "rest"
def test_tion_api_need_new_auth(api: TionApi): api.authorization = "" assert api.get_data(force=True) is True, "New auth should've received!" sleep(TESTS_DELAY) # let the server "rest"
def test_tion_api_bad_auth_fname(api_bad_auth_fname: TionApi): assert api_bad_auth_fname.get_data( force=True) is True, "Should've get data!" sleep(TESTS_DELAY) # let the server "rest"