Skip to content

chore: merge dev into main - #57

Merged
Illustar0 merged 1 commit into
mainfrom
dev
Jun 17, 2026
Merged

chore: merge dev into main#57
Illustar0 merged 1 commit into
mainfrom
dev

Conversation

@Illustar0

@Illustar0 Illustar0 commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Avoid relying on upstream templateList field order when reading the remaining electricity quantity.

Close #56.

Summary by CodeRabbit

发布说明

  • Bug 修复
    • 改进了电卡剩余电量的查询机制,增强了数据验证和错误处理的可靠性,确保异常情况下能提供更清晰的错误反馈。

Avoid relying on upstream templateList field order when reading the remaining electricity quantity.

Close #56.

Signed-off-by: Illustar0 <me@illustar0.com>
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: de93aeb0-8d49-4569-85d7-7bc407e78f91

📥 Commits

Reviewing files that changed from the base of the PR and between c253ba5 and 8172670.

📒 Files selected for processing (3)
  • zzupy/aio/app/ecard.py
  • zzupy/app/ecard.py
  • zzupy/model/ecard.py

📝 Walkthrough

Walkthrough

新增 zzupy/model/ecard.py,定义 ECardTemplateECardAccountDataECardAccountModel 三个 Pydantic 模型,其中 remaining_energy 通过遍历 template_listcode == "quantity" 查找而非固定索引取值。同步与异步 ECardClient.get_remaining_energy() 均改用 ECardAccountModel.model_validate() 解析响应,并将 ValidationError 纳入异常捕获范围。

Changes

ECard 剩余电量解析重构

Layer / File(s) Summary
ECard Pydantic 模型定义
zzupy/model/ecard.py
新增 ECardTemplate(camelCase 别名)、ECardAccountDataremaining_energy 遍历 template_listcode=="quantity" 查找)、ECardAccountModel(透传 result_data.remaining_energy)三个模型。
同步客户端解析逻辑替换
zzupy/app/ecard.py
新增 ValidationErrorECardAccountModel 导入;get_remaining_energy() 改用 model_validate 替代固定索引解析,remaining_energyNone 时抛 ParsingErrorexcept 加入 ValidationError
异步客户端解析逻辑替换
zzupy/aio/app/ecard.py
与同步客户端做相同修改:新增导入、替换固定索引解析逻辑、加入 ValidationError 捕获。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 小兔子盯着 templateList,
索引取值总出岔,
改用 code == "quantity" 来查,
电量再不变电价啦~
模型校验守好门,
Bug 从此无处藏! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning PR 标题'chore: merge dev into main'过于通用,未能准确反映此PR 的核心目标——修复 get_remaining_energy() 方法的关键bug。 建议更改标题为'fix: parse ecard energy by template code'或类似表述,以清晰描述此PR 修复了基于模板代码查找电量值的问题。
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed 代码变更完全符合 issue #56 的需求:通过新增 ECardAccountModel、ECardAccountData、ECardTemplate 等模型,实现了按 code='quantity' 查找而非固定下标的解析逻辑。
Out of Scope Changes check ✅ Passed 所有变更都直接对应 issue #56 中的需求,包括新增 ecard.py 模型文件、修改 get_remaining_energy() 方法和异常处理,均在范围内。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Illustar0
Illustar0 merged commit 3015afb into main Jun 17, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] get_remaining_energy 会把电价解析成剩余电量

1 participant