Example #1
0
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
    """Set up Emporia Vue from a config entry."""
    entry_data = entry.data
    email = entry_data[CONF_EMAIL]
    password = entry_data[CONF_PASSWORD]
    _LOGGER.info(entry_data)
    vue = PyEmVue()
    try:
        result = vue.login(username=email, password=password)
        if not result:
            raise Exception("Could not authenticate with Emporia API")
            return False
    except Exception:
        _LOGGER.error("Could not authenticate with Emporia API")
        return False

    # Get device data from Emporia API
    #discovered_devices = vue.get_devices()

    hass.data[DOMAIN][entry.entry_id] = {
        VUE_DATA: vue,
        #VUE_DEVICES_DATA: VueDeviceData(),
        #VUE_DISCOVERED_DEVICES_DATA: discovered_devices,
    }

    for component in PLATFORMS:
        hass.async_create_task(
            hass.config_entries.async_forward_entry_setup(entry, component))

    return True
class VueHub:
    """Hub for the Emporia Vue Integration."""

    def __init__(self):
        """Initialize."""
        self.vue = PyEmVue()
        pass

    async def authenticate(self, username, password) -> bool:
        """Test if we can authenticate with the host."""
        return self.vue.login(username=username, password=password)
Example #3
0
def get_vue():
    vue = PyEmVue()

    try:
        data = json.load(json_file)
    except:
        return None

    try:
        vue.login(username=data['email'],
                  password=data['password'],
                  token_storage_file=token_file)
    except:
        try:
            vue.login(id_token=data['idToken'],
                      access_token=data['accessToken'],
                      refresh_token=data['refreshToken'],
                      token_storage_file=json_file)
        except:
            return None
    return vue