Esempio n. 1
0
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
Esempio n. 3
0
def magicair(api: TionApi) -> MagicAir:
    return api.get_devices(name_part="magic")[0]
Esempio n. 4
0
def breezer(api: TionApi) -> Breezer:
    return api.get_devices(name_part="breezer 3s")[0]