跳转到主要内容

Yale Access(原名August)智能锁和门铃的Python API

项目描述

Yalexs PyPI版本 构建状态 codecov Python版本

耶鲁访问(原名August)智能锁和门铃的Python API。此API用于Home Assistant,但应该足够通用,可以在其他地方使用。

耶鲁访问(原名August)

此库是来自https://github.com/snjoetw/py-august的Joe Lu的优秀august库的分支。

认证器

认证器负责所有认证相关逻辑,包括通过发送验证码到电子邮件或手机来认证以及验证账户是否属于用户。

构造函数

参数 描述
api 参见Api类。
login_method 登录方法,可以是"phone"或"email"。
username 如果您的login_method是phone,则这是包括"+"和国家代码在内的完整电话号码;否则在此处输入您的电子邮件地址。
password 密码。
install_id* 当安装Yale Access应用时生成的ID。如果没有指定,认证器将自动生成一个。如果已提供install_id,则请提供已提供的install_id,因为您将绕过验证过程。
access_token_cache_file* 访问令牌缓存文件的路径。如果指定,访问令牌信息将缓存在该文件中。后续认证将利用文件中的信息来确定正确的认证状态。

*表示可选

方法

authenticate

使用指定的login_method、用户名和密码进行认证。

此方法的结果是认证对象。使用Authentication.state确定认证状态。只有当Authentication.state = AuthenticationState.AUTHENTICATED时,用户才已认证。

如果已认证的access_token已存储在access_token_cache_file中,则此方法将返回缓存的认证。

send_verification_code

根据login_method将6位数的验证码发送到手机或电子邮件。

validate_verification_code

验证验证码。此方法返回ValidationResult。检查值以确定验证码是否有效。

安装

pip install yalexs

用法

from yalexs.api import Api
from yalexs.authenticator import Authenticator, AuthenticationState

api = Api(timeout=20)
authenticator = Authenticator(api, "phone", "YOUR_USERNAME", "YOUR_PASSWORD",
                              access_token_cache_file="PATH_TO_ACCESS_TOKEN_CACHE_FILE")

authentication = authenticator.authenticate()

# State can be either REQUIRES_VALIDATION, BAD_PASSWORD or AUTHENTICATED
# You'll need to call different methods to finish authentication process, see below
state = authentication.state

# If AuthenticationState is BAD_PASSWORD, that means your login_method, username and password do not match

# If AuthenticationState is AUTHENTICATED, that means you're authenticated already. If you specify "access_token_cache_file", the authentication is cached in a file. Every time you try to authenticate again, it'll read from that file and if you're authenticated already, Authenticator won't call Yale Access again as you have a valid access_token


# If AuthenticationState is REQUIRES_VALIDATION, then you'll need to go through verification process
# send_verification_code() will send a code to either your phone or email depending on login_method
authenticator.send_verification_code()
# Wait for your code and pass it in to validate_verification_code()
validation_result = authenticator.validate_verification_code(123456)
# If ValidationResult is INVALID_VERIFICATION_CODE, then you'll need to either enter correct one or resend by calling send_verification_code() again
# If ValidationResult is VALIDATED, then you'll need to call authenticate() again to finish authentication process
authentication = authenticator.authenticate()

# Once you have authenticated and validated you can use the access token to make API calls
locks = api.get_locks(authentication.access_token)

项目详情


发布历史 发布通知 | RSS源

下载文件

下载您平台对应的文件。如果您不确定该选择哪个,请了解有关 安装包 的更多信息。

源分发

yalexs-8.9.0.tar.gz (39.0 kB 查看哈希值)

上传时间

构建分发

yalexs-8.9.0-py3-none-any.whl (47.7 kB 查看哈希值)

上传时间 Python 3

支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面