You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If switch doesn't support the toggle feature and only on_off, the UI may not send a toggle command.
UI version
0.36.0
Additional context
Python demo integration:
#!/usr/bin/env python3"""Switch entity integration example. Bare minimum of an integration driver."""importasyncioimportloggingfromtypingimportAnyimportucapifromucapiimportswitchloop=asyncio.get_event_loop()
api=ucapi.IntegrationAPI(loop)
asyncdefcmd_handler(
entity: ucapi.Switch, cmd_id: str, _params: dict[str, Any] |None
) ->ucapi.StatusCodes:
""" Switch command handler. Called by the integration-API if a command is sent to a configured switch-entity. :param entity: switch entity :param cmd_id: command :param _params: optional command parameters :return: status of the command """print(f"Got {entity.id} command request: {cmd_id}")
state=Noneifcmd_id==switch.Commands.ON:
state=switch.States.ONelifcmd_id==switch.Commands.OFF:
state=switch.States.OFFelifcmd_id==switch.Commands.TOGGLE:
print("Toggle command should not be sent, entity only has on_off feature!")
ifentity.attributes[switch.Attributes.STATE] ==switch.States.OFF:
state=switch.States.ONelse:
state=switch.States.OFFifstate:
api.configured_entities.update_attributes(
entity.id, {switch.Attributes.STATE: state}
)
returnucapi.StatusCodes.OK@api.listens_to(ucapi.Events.CONNECT)asyncdefon_connect() ->None:
# When the remote connects, we just set the device state. We are ready all the time!awaitapi.set_device_state(ucapi.DeviceStates.CONNECTED)
if__name__=="__main__":
logging.basicConfig()
entity=ucapi.Switch(
"switch1",
"Demo switch",
[switch.Features.ON_OFF],
{switch.Attributes.STATE: switch.States.OFF},
cmd_handler=cmd_handler,
)
api.available_entities.add(entity)
loop.run_until_complete(api.init("switch.json"))
loop.run_forever()
The text was updated successfully, but these errors were encountered:
Is there an existing issue for this?
Description
Refers to:
While testing the referred issue, I noticed that the UI sends invalid switch commands.
How to Reproduce
on_off
featureExpected behavior
If switch doesn't support the
toggle
feature and onlyon_off
, the UI may not send atoggle
command.UI version
0.36.0
Additional context
Python demo integration:
The text was updated successfully, but these errors were encountered: