Fix switch/light/lock command payloads and state reading to match API spe#3
Open
geofffranks wants to merge 4 commits intoLF2b2w:mainfrom
Open
Fix switch/light/lock command payloads and state reading to match API spe#3geofffranks wants to merge 4 commits intoLF2b2w:mainfrom
geofffranks wants to merge 4 commits intoLF2b2w:mainfrom
Conversation
… spec
Switch and light on/off commands were sending the wrong payload format —
the API expects name="on"/"off" with no arguments (per st.switch spec),
but the code was sending name="switch" with arguments={"value": 1} using
SwitchState.ON/OFF which was an IntEnum. Fixed SwitchState to a str enum
with values "on"/"off" to also correctly match state values returned by
the API in queries.
Brightness commands were targeting the wrong capability. The API returns
and accepts brightness via st.switchLevel/setLevel with a "level" argument,
but the code was sending to st.brightness/level with a "value" argument.
Added SWITCH_LEVEL = "st.switchLevel" capability and updated both the
brightness read (light.brightness property) and write (set_brightness) to
use it with the correct command name and argument key.
DoorState changed from IntEnum (1/2/3) to str enum ("Closed"/"Open"/"Unknown")
to match the string values returned by the st.doorSenr API. Fixed the
attribute name from "SensorState" to "sensorState" (lowercase s) in lock.py.
Fixed is_door_open to compare against DoorState.OPEN rather than the
incorrect raw string "Closed" (which also had inverted logic).
LockMode corrected from invented values (0=Unsure, 1=Locked, 2=Unlocked,
3=Jammed, 4=Unknown) to the actual API spec values (0=Normal, 1=Passage,
2=Locked). Updated lock_mode property mapping accordingly.
Added SWITCH_LEVEL capability to HANDLE_TYPE_CAPABILITIES for dimmer and
RGBAW light handle types. Removed COMMAND_MAP which was unused after the
command format fix. Removed SwitchState from COMMAND_MAP references.
Generated with the help of Claude Sonnet 4.6
…nding the command. This was wasteful (2 API calls per user action) and returned stale state anyway since the deadbolt hasn't moved yet. State refresh is now handled by the coordinator's periodic bulk poll. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Verified via API testing that setLevel (and by extension set_color_temp and set_rgb_color) implicitly turns the device on. Sending a separate st.switch "on" command beforehand is therefore unnecessary, reducing turn_on() with any attribute from 2 API calls to 1. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes some bugs found when trying to manage lights in the UHome-HA HACS module.
Details:
Switch and light on/off commands were sending the wrong payload format — the API expects name="on"/"off" with no arguments (per st.switch spec), but the code was sending name="switch" with arguments={"value": 1} using SwitchState.ON/OFF which was an IntEnum. Fixed SwitchState to a str enum with values "on"/"off" to also correctly match state values returned by the API in queries.
Brightness commands were targeting the wrong capability. The API returns and accepts brightness via st.switchLevel/setLevel with a "level" argument, but the code was sending to st.brightness/level with a "value" argument. Added SWITCH_LEVEL = "st.switchLevel" capability and updated both the brightness read (light.brightness property) and write (set_brightness) to use it with the correct command name and argument key.
DoorState changed from IntEnum (1/2/3) to str enum ("Closed"/"Open"/"Unknown") to match the string values returned by the st.doorSenr API. Fixed the attribute name from "SensorState" to "sensorState" (lowercase s) in lock.py. Fixed is_door_open to compare against DoorState.OPEN rather than the incorrect raw string "Closed" (which also had inverted logic).
LockMode corrected from invented values (0=Unsure, 1=Locked, 2=Unlocked, 3=Jammed, 4=Unknown) to the actual API spec values (0=Normal, 1=Passage, 2=Locked). Updated lock_mode property mapping accordingly.
Added SWITCH_LEVEL capability to HANDLE_TYPE_CAPABILITIES for dimmer and RGBAW light handle types. Removed COMMAND_MAP which was unused after the command format fix. Removed SwitchState from COMMAND_MAP references.
Generated with the help of Claude Sonnet 4.6