jfarmer08 / homebridge-wyze-smart-home

Wyze Smart Home plugin for Homebridge.
MIT License
93 stars 14 forks source link

Wyze Bulb Color not changing colors as part of a scene #247

Closed Hochen97 closed 1 month ago

Hochen97 commented 1 month ago

Describe the Bug: Wyze Color bulbs won't change color when part of a scene. All other properties propagate successfully. The specific issue only occurs when altering hue and other values simultaneously. Only altering hue does not cause this issue.

Below is continued from issue #234

So I found in the debug logs an issue where when changing multiple properties of lights as part of a scene (as @escharhon above mentioned) the P1507 (WYZE_API_COLOR_PROPERTY) value returns undefined. See below

[5/4/2024, 2:01:21 AM] [Wyze] run_action_list Data Body: {"action_list":[{"instance_id":"7C78B2214B0B","action_params":{"list":[{"mac":"7C78B2214B0B","plist":[{"pid":"P1507","pvalue":"undefined"},{"pid":"P3","pvalue":"1"}]}]},"provider_key":"WLPA19C","action_key":"set_mesh_property"}]}
[5/4/2024, 2:01:21 AM] [Wyze] run_action_list Data Body: {"action_list":[{"instance_id":"7C78B2214B0B","action_params":{"list":[{"mac":"7C78B2214B0B","plist":[{"pid":"P3","pvalue":"1"}]}]},"provider_key":"WLPA19C","action_key":"set_mesh_property"}]}

Now, interestingly, when setting ONLY the color value, as described above, for some reason the value is NOT undefined, but indeed contains a value.

[5/4/2024, 2:23:48 AM] [Wyze] run_action_list Data Body: {"action_list":[{"instance_id":"7C78B2214B0B","action_params":{"list":[{"mac":"7C78B2214B0B","plist":[{"pid":"P1507","pvalue":"ff6100"},{"pid":"P3","pvalue":"1"}]}]},"provider_key":"WLPA19C","action_key":"set_mesh_property"}]}

I'm not sure that this issue originates specifically from how HomeKit handles scenes, but instead how this plugin is handling that input.

And after investigating further (finding the plugin log setting) I was able to rip a log of exactly that happening.

[5/4/2024, 2:35:19 AM] [Wyze] [MeshLight] Setting brightness for "Office Light Center (7C78B2214B0B) to 1"
[5/4/2024, 2:35:19 AM] [Wyze] run_action_list Data Body: {"action_list":[{"instance_id":"7C78B2214B0B","action_params":{"list":[{"mac":"7C78B2214B0B","plist":[{"pid":"P1501","pvalue":"1"},{"pid":"P3","pvalue":"1"}]}]},"provider_key":"WLPA19C","action_key":"set_mesh_property"}]}
[5/4/2024, 2:35:19 AM] [Wyze] [MeshLight] Setting saturation (color) for "Office Light Center (7C78B2214B0B) to 100"
[5/4/2024, 2:35:19 AM] [Wyze] [MeshLight] H(S) Values: 100, 100
[5/4/2024, 2:35:19 AM] [Wyze] [MeshLight] Setting hue (color) for "Office Light Center (7C78B2214B0B) to 23 : (H)S Values: 23, 100"
[5/4/2024, 2:35:19 AM] [Wyze] ff6100
[5/4/2024, 2:35:19 AM] [Wyze] run_action_list Data Body: {"action_list":[{"instance_id":"7C78B2214B0B","action_params":{"list":[{"mac":"7C78B2214B0B","plist":[{"pid":"P1507","pvalue":"undefined"},{"pid":"P3","pvalue":"1"}]}]},"provider_key":"WLPA19C","action_key":"set_mesh_property"}]}
[5/4/2024, 2:35:19 AM] [Wyze] [MeshLight] Setting power for "Office Light Center (7C78B2214B0B)" to true"
[5/4/2024, 2:35:19 AM] [Wyze] run_action_list Data Body: {"action_list":[{"instance_id":"7C78B2214B0B","action_params":{"list":[{"mac":"7C78B2214B0B","plist":[{"pid":"P3","pvalue":"1"}]}]},"provider_key":"WLPA19C","action_key":"set_mesh_property"}]}

Here's the plugin log equivalent of the hue changes working:

[5/4/2024, 2:43:52 AM] [Wyze] [MeshLight] Setting hue (color) for "Office Light Center (7C78B2214B0B) to 23 : (H)S Values: 23, 100"
[5/4/2024, 2:43:52 AM] [Wyze] [MeshLight] Setting saturation (color) for "Office Light Center (7C78B2214B0B) to 100"
[5/4/2024, 2:43:52 AM] [Wyze] [MeshLight] H(S) Values: 100, 100
[5/4/2024, 2:43:52 AM] [Wyze] run_action_list Data Body: {"action_list":[{"instance_id":"7C78B2214B0B","action_params":{"list":[{"mac":"7C78B2214B0B","plist":[{"pid":"P1507","pvalue":"ff6100"},{"pid":"P3","pvalue":"1"}]}]},"provider_key":"WLPA19C","action_key":"set_mesh_property"}]}

Interestingly the hexValue is NOT logged in this scenario, which leads me to believe this is using a different function.

I'm not intimately familiar with the codebase, so I don't quite know where to go from here. I've traced the issue to—I think—the code in setHue() on line 209 in /accessories/WyzeMeshLight.js. It's obvious in the above logs that the application successfully produces a hexadecimal hue value (ff6100) for the API to consume, however it doesn't seem to make it there.

Originally posted by @Hochen97 in https://github.com/jfarmer08/homebridge-wyze-smart-home/issues/234#issuecomment-2094055933

github-actions[bot] commented 1 month ago

Message that will be displayed on users' first issue

Hochen97 commented 1 month ago

I fixed it.

line 230 in /accessories/WyzeMeshLight.js

replace this.hexValue with hexValue.

Here's the new function:

async setHue(value, callback) {
    if (value != null) {
      if (this.plugin.config.pluginLoggingEnabled)
        this.plugin.log(
          `[MeshLight] Setting hue (color) for "${this.display_name} (${this.mac}) to ${value} : (H)S Values: ${value}, ${this.cache.saturation}"`
        );

      try {
        this.cache.hue = value;
        if (this.cacheUpdated) {
          let hexValue = colorsys.hsv2Hex(
            this.cache.hue,
            this.cache.saturation,
            100
          );
          hexValue = hexValue.replace("#", "");
          if (this.plugin.config.pluginLoggingEnabled)
            this.plugin.log(hexValue);
          await this.plugin.client.setMeshHue(
            this.mac,
            this.product_model,
            hexValue
          );
          this.cacheUpdated = false;
        } else {
          this.cacheUpdated = true;
        }
        callback();
      } catch (e) {
        callback(e);
      }
    }
  }
carTloyal123 commented 1 month ago

Hi Jacob, if you are familiar with git could you create a pr and add your change please? That is probably the fastest way to get this fixed

Hochen97 commented 1 month ago

Yes of course!

I tried to push a feature branch but my authentication was failing, I’m assuming because I’m not authorized on this repo. I’ll see if I can’t open a PR another way. If you have instructions (this is my first time committing to a truly open source repo that I don’t own) I’d also greatly appreciate it :)

Hochen97 commented 1 month ago

Nevermind I figured it out :)