kmaehashi / homebridge-nature-remo-cloud-aircon

Homebridge Plug-in for Air Conditioner Managed by Nature Remo
36 stars 19 forks source link

シーンでのON/OFFの切り替え #18

Closed hirosan18 closed 5 years ago

hirosan18 commented 5 years ago

このプラグインを使用してHomeアプリに設定したエアコンに対して、 シーンを用いてON/OFFの切り替えを行えるように対応します

現状、シーンを使用してエアコンを操作すると、 モードの変更温度の変更 が別命令としてHomeBridgeに連携されるようで、 以下のログのような動きになってしまいます。 (ここのログを変更してパラメータをわかりやすくしています)

エアコンがONの状態で、OFF(26℃)にするシーンを動作させた場合

[エアコン] making request for update {"button":"power-off"}
[エアコン] making request for update {"temperature":"26","button":""}
[エアコン] got reponse for update
[エアコン] notifying values: {"temp":"26","mode":"warm","vol":"3","dir":"","button":"power-off","updated_at":"2019-02-02T18:23:46Z"}
[エアコン] got reponse for update
[エアコン] notifying values: {"temp":"26","mode":"warm","vol":"3","dir":"","button":"","updated_at":"2019-02-02T18:23:46Z"}

エアコンがOFFの状態で、ON(26℃)にするシーンを動作させた場合

[エアコン] making request for update {"button":"","operation_mode":"warm"}
[エアコン] making request for update {"temperature":"26","button":"power-off"}
[エアコン] got reponse for update
[エアコン] notifying values: {"temp":"26","mode":"warm","vol":"3","dir":"","button":"","updated_at":"2019-02-02T18:26:06Z"}
[エアコン] got reponse for update
[エアコン] notifying values: {"temp":"26","mode":"warm","vol":"3","dir":"","button":"power-off","updated_at":"2019-02-02T18:26:06Z"}

温度の変更を処理する際に、 ここ'button': this.record.settings.button, としているのは、エアコンをオフにした状態で温度変更してもエアコンをオンにしないため(buttonを設定せずにサーバにリクエストすると"button":"" として扱われ勝手にエアコンがオンになるから?)だと思いますが、 モードの変更温度の変更 とHomeアプリが命令した場合に 温度の変更以前のbuttonの状態(モードの変更する前の状態)を見てしまっているため、 状態の不整合が起こってしまっています(モードの変更時に変更したbuttonがその時点ではthis.record.settingsに保存されていないため)

対応の方針としては

と考えました。

あと、homebridge起動時にAPIエラーで温度が取得できなかった場合にgetTargetTemperatureでクラッシュする場合があるので、確認する処理も入れています。

ご確認お願いします🙇‍♂️


以下の環境で問題を確認していますが、環境次第で問題が起きない可能性もあります。 端末 iPhone7 バージョン 12.1.2 (16C104) モデル NNCV2J/A

{
  "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "device": {
    "name": "リビングのRemo",
    "id": "xxxxxxxxxxxxxxx",
    "created_at": "2018-12-04T06:05:54Z",
    "updated_at": "2019-02-02T18:21:46Z",
    "mac_address": "xxxxxxxxxxxxxxxx",
    "serial_number": "xxxxxxxxxxxxxxxxxxxxxxx",
    "firmware_version": "Remo/1.0.62-gabbf5bd",
    "temperature_offset": 0,
    "humidity_offset": 0
  },
  "model": {
    "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "manufacturer": "daikin",
    "remote_name": "xxxxxxxxx",
    "series": "Daikin AC",
    "name": "Daikin AC 003",
    "image": "ico_ac_1"
  },
  "type": "AC",
  "nickname": "エアコン",
  "image": "ico_ac_1",
  "settings": {
    "temp": "26",
    "mode": "warm",
    "vol": "3",
    "dir": "",
    "button": "",
    "updated_at": "2019-02-02T18:21:46Z"
  },
  "aircon": {
    "range": {
      "modes": {
        "auto": {
          "temp": ["-5", "-4", "-3", "-2", "-1", "0", "1", "2", "3", "4", "5"],
          "dir": [""],
          "vol": ["1", "2", "3", "4", "5", "6", "auto"]
        },
        "cool": {
          "temp": ["18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32"],
          "dir": [""],
          "vol": ["1", "2", "3", "4", "5", "6", "auto"]
        },
        "dry": {
          "temp": ["-3", "-2", "-1", "0", "1"],
          "dir": [""],
          "vol": [""]
        },
        "warm": {
          "temp": ["14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30"],
          "dir": [""],
          "vol": ["1", "2", "3", "4", "5", "6", "auto"]
        }
      },
      "fixedButtons": ["airdir-swing", "power-off"]
    },
    "tempUnit": "c"
  },
  "signals": []
}
gaojie429 commented 5 years ago

失礼します。 私もシーン操作とHueボタンによる操作で同様の問題を抱えていたため、このコードの該当部分をindex.jsにて書き換えたところ、シーンやボタンでの操作では期待通りの修正が行われていましたが、Homeアプリ上でエアコンが「応答なし」と表示され操作できなくなってしまいました(スクリーンショット添付)。 (ただ、SIriからの操作、シーンやボタンによる操作はどの端末からも問題なく動いています。) img_4369

hirosan18 commented 5 years ago

@gaojie429

Homeアプリ上でエアコンが「応答なし」と表示され操作できなくなってしまいました

  • これはHomeアプリ再起動(一旦タスクKillした後再度アプリ起動)しても起こりますか?
  • 「応答なし」と表示されるのはアクセサリを操作(タップしてON/OFF切り替え)しようとしたときですか?それとも何も操作しなくても起こりますか?
  • 状況が再現できるなら(再起動しても起こるなら)、その時のhomebridgeのログを共有いただくことは可能ですか?
gaojie429 commented 5 years ago

コードの書き換え部分が一行間違っていたようで、それが原因でこの問題が発生してしまったようです。こちらの確認不足でした、すみません。

また、@hirosan18 さんはスレッド冒頭で

ここで'button': this.record.settings.button, としているのは、エアコンをオフにした状態で温度変更してもエアコンをオンにしないため(buttonを設定せずにサーバにリクエストすると"button":"" として扱われ勝手にエアコンがオンになるから?)だと思いますが

とおっしゃっていますが、このパッチを適用した後、エアコンの電源がオフの状態で温度調節を行うと、エアコンの電源が入って前回の運転モードで運転を開始してしまいます。

以下その時のログとなっています、 「前回起動時の運転モード:暖房、温度スライダ:22度」

[2019-2-3 14:54:26] [エアコン] making request for update: {"temperature":"22"}
[2019-2-3 14:54:26] [エアコン] request to server: {"temperature":"22"}
[2019-2-3 14:54:27] [エアコン] got reponse for update
[2019-2-3 14:54:27] [エアコン] notifying values: {"temp":"22","mode":"warm","vol":"","dir":"","button":"","updated_at":"2019-02-03T05:54:27Z"}
hirosan18 commented 5 years ago

@gaojie429 検証ありがとうございます。 バグってたので修正しました😇

gaojie429 commented 5 years ago

早速の修正ありがとうございます! オフ状態で温度スライダを変更してもエアコンがオンにならないようになりました!

kmaehashi commented 5 years ago

遅くなってしまいすみません、ありがとうございます 🙏 後ほど動作確認してマージしたいと思います!

kmaehashi commented 5 years ago

@hirosan18 @gaojie429 遅くなりましたがマージしました!ありがとうございました 🙇