refactor: 配置迁移至 .env,推送直连设备 MAC
- config.py 顶部新增零依赖 _load_dotenv(),凭证/参数统一从同目录 .env 读取, 真实环境变量(cron/命令行注入)优先;移除所有明文 fallback - 新增 .env.example 模板,.env 加入 .gitignore - pusher.py 删除 get_devices(),resolve_device_id() 直接取 ZECTRIX_DEVICE_ID, 不再调 GET /devices 列表 - jm_api.py 改为设备密钥授权(client_secret,免验证码),token 进程内缓存 + 401 重试 - 同步 CLAUDE.md / main.py 文档 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
19
pusher.py
19
pusher.py
@@ -25,22 +25,11 @@ def _request(method, path, headers=None, body=None):
|
||||
raise RuntimeError(f"HTTP {e.code}: {e.read().decode('utf-8', 'ignore')}") from e
|
||||
|
||||
|
||||
def get_devices():
|
||||
"""获取设备列表。"""
|
||||
data = _request("GET", "/devices")
|
||||
if data.get("code") != 0:
|
||||
raise RuntimeError(f"获取设备失败: {data}")
|
||||
return data.get("data", [])
|
||||
|
||||
|
||||
def resolve_device_id():
|
||||
"""返回目标设备 ID:优先用 config.DEVICE_ID,否则取列表第一个。"""
|
||||
if config.DEVICE_ID:
|
||||
return config.DEVICE_ID
|
||||
devices = get_devices()
|
||||
if not devices:
|
||||
raise RuntimeError("账号下没有任何设备")
|
||||
return devices[0]["deviceId"]
|
||||
"""返回目标设备 ID:直接取 config.DEVICE_ID(硬件 MAC),未配置则报错。"""
|
||||
if not config.DEVICE_ID:
|
||||
raise RuntimeError("未配置设备 ID:请在 .env 设置 ZECTRIX_DEVICE_ID=<硬件 MAC>")
|
||||
return config.DEVICE_ID
|
||||
|
||||
|
||||
def _multipart(fields, files):
|
||||
|
||||
Reference in New Issue
Block a user