Skip to content

Fix switch/light/lock command payloads and state reading to match API spe#3

Open
geofffranks wants to merge 4 commits intoLF2b2w:mainfrom
geofffranks:main
Open

Fix switch/light/lock command payloads and state reading to match API spe#3
geofffranks wants to merge 4 commits intoLF2b2w:mainfrom
geofffranks:main

Conversation

@geofffranks
Copy link
Copy Markdown

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

… 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
geofffranks and others added 3 commits March 18, 2026 08:12
…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>
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.

1 participant