Skip to content

feat: aircon remote control - #187

Open
aqqkad wants to merge 3 commits into
BenderBlog:mainfrom
aqqkad:feat/aircon-remote-control
Open

aqqkad wants to merge 3 commits into
BenderBlog:mainfrom
aqqkad:feat/aircon-remote-control

Conversation

@aqqkad

@aqqkad aqqkad commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

此 Pull Request 为空调(aircon)遥控控制和设备状态管理提供了全面支持。主要改动包括对 AirconController 的大幅增强,以及将空调设备状态刷新集成到首页控制器中。

空调遥控与设备状态管理

  • AirconController 进行了大规模重构和扩展,支持设备状态获取、控制指令发送(电源、温度、模式、风速等)、乐观 UI 更新以及指令排队。同时新增了用于设备状态和控制状态的 Signal,以便 UI 能够及时响应状态变化。 [1] [2] [3] [4] [5]

  • 将空调设备状态刷新纳入首页的重新加载逻辑,确保 UI 显示最新的设备状态。 [1] [2]

设置与配置

  • 更新空调 IMEI 设置及相关状态提示信息,使其与新的空调遥控和设备状态功能保持一致。 [1] [2] [3]

这些改动为空调遥控功能提供了更加完整的设备控制和状态管理能力,并提升了整体的可靠性和响应性。

@aqqkad
aqqkad force-pushed the feat/aircon-remote-control branch from ef09585 to f1757a9 Compare September 17, 2026 05:28
@BenderBlog BenderBlog changed the title Feat/aircon remote control feat: aircon remote control Sep 17, 2026
Comment thread lib/controller/aircon_controller.dart Outdated

bool _isReloading = false;
final session = AirconSession();
final _pendingCommands =

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这玩意很怪,需要后续分析。

Comment thread lib/controller/aircon_controller.dart Outdated
if (imei.isEmpty) return;

_isReloading = true;
final requestId = ++_energyRequestId;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥要自增请求ID?原版程序这么写的吗

Comment thread lib/controller/aircon_controller.dart Outdated
AirconSession.clearEnergyHistory();
energyHistoryInfoList.clear();
_lastValidInfo.value = null;
_energyRequestId++;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

自增又来了,希望是原版程序真的要自增。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是状态管理的,原来的状态管理确实写的有点乱,已修改

Comment thread lib/model/aircon_state.dart Outdated
final DateTime? timestamp;
final String? errorCode;

factory AirconState.fromJson(Map<String, dynamic> json) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要用 AI,使用 json_serization 包处理了

@BenderBlog

Copy link
Copy Markdown
Owner

另请提供截图,主页卡片和内部样式

@BenderBlog

Copy link
Copy Markdown
Owner

另提供 Codex AI 分析的问题,尤其关注 P2,这是我分析该功能的核心:

  1. [P1] 多个空调指令并发时可能产生错误状态
    位置:aircon_controller.dart:197
    _pendingCommands 按控制项区分,因此不同指令可以同时发送。代码却使用 commandId >= _confirmedCommandId 判断哪个设备状态可信。
    例如同时修改风速和强力模式时,请求完成顺序可能与设备实际执行顺序不同,后返回的旧状态可能被忽略,最终 UI 显示与设备不一致。
    建议:
    • 所有空调写操作进入单一队列,串行执行;
    • 或命令完成后统一重新拉取一次权威状态;
    • 不要仅靠本地递增 ID 判断远端状态的新旧。

我建议上个队列,或者按下按钮时候搞个刷新状态,不让碰其他的按钮

  1. [P1] 命令成功判定不可靠
    位置:aircon_controller.dart:193
    当前逻辑是:
    1. 发送命令;
    2. 固定等待 2.5 秒;
    3. 拉取一次状态;
    4. 直接认为该状态已经确认。
      如果设备响应超过 2.5 秒,或者接口返回的是旧缓存状态,UI 会先显示成功,随后又回滚到旧状态。
      建议轮询设备状态,直到目标字段与命令一致,或者超时后明确显示“设备状态未确认”,不要直接清除 pending 状态。

轮询是要实现的,这也就要做到遥控器功能是一个单独的页面,不要搞到全局状态里面。

  1. [P2] 切换模式会静默修改用户温度
    位置:aircon_controller.dart:238-259
    切换制冷固定设置 26℃,制热固定设置 23℃,其他模式固定 25℃。这会覆盖用户当前的目标温度,并且 UI 没有提示。
    如果后端没有强制要求模式切换时重设温度,建议保留当前温度;如果确实需要默认温度,应在 UI 或文档中明确说明。

这个不用管,应该原版程序也是这样的。

  1. [P2] 状态模型对接口字段过于严格(不要管)
    位置:aircon_state.dart:75-82
    verticalSwing、strongMode、electricHeating 等能力字段缺失或格式变化时,整个状态解析失败。这样会导致设备状态卡片、远程控制页面全部进入错误状态。
    建议区分:
    • 核心字段:开关、模式、温度;
    • 可选能力字段:摆风、强力、电辅热。
      对可选字段提供默认值或 capability 标记,并增加不同设备响应格式的测试。

忽略这条

  1. [P2] IMEI 保存对所有异常都显示为“IMEI 无效”
    位置:aircon_imei_dialog.dart:102-117
    网络错误、服务端错误、状态解析错误都会被统一转换成 aircon_imei_invalid。用户输入正确 IMEI 但服务器不可用时,会得到错误提示。
    建议区分输入校验错误、网络错误和设备接口错误,分别提示并支持重试。

看情况修复

@aqqkad

aqqkad commented Sep 19, 2026

Copy link
Copy Markdown
Contributor Author

另请提供截图,主页卡片和内部样式

Screenshot_20260919-200741 Screenshot_20260919-200749

@BenderBlog

Copy link
Copy Markdown
Owner

明天晚上再看,问题应该都不大了

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.

2 participants