custom-components / pyscript

Pyscript adds rich Python scripting to HASS
Apache License 2.0
874 stars 46 forks source link

problems with number sliders #437

Open SiriosDev opened 1 year ago

SiriosDev commented 1 year ago

versions: prev: ? don't know 1.3.3: ❌Not working 1.4.0: ❌Not working

number selector slider declared in triple quotes for services made with pyscript have this problem:

https://user-images.githubusercontent.com/26876994/220390388-c78a501a-4194-4fd7-8b26-9b8a92fabfe0.mp4

here the part of yaml about the problem:

position:
    name: Position
    description: Select a Mode (0%-100%) (required for "setPosition" command)
    example: 50
    default: 50
    required: false
    selector:
      number:
        min: 0
        max: 100
        step: 1
        unit_of_measurement: "%"
        mode: slider
SiriosDev commented 1 year ago

no news ???

craigbarratt commented 1 year ago

You haven't provided any code or details that might allow someone to recreate or understand the issue.

I'm not familiar with position sliders and how to correctly create them from pyscript.

SiriosDev commented 1 year ago

I think the inserted yaml is enough, considering that the "visual" part is generated from the yaml-docstrings, but I can insert more in a few seconds.

SiriosDev commented 1 year ago

here's more code:

@service
def switchbot_curtain(device=None, command=None, index=None, mode=None, position=None):
    """yaml
name: SwitchBot Curtain Control
description: "Control Switchbot Curtain™ connected to your SwitchBot account. (API call consumed: 1*execution)"
fields:
  device:
    name: Device
    description: Target device
    example: cover.switchbot_remote_bedroom_curtains
    default:
    required: true
    selector:
      entity:
        domain: cover

  command:
    name: Command
    description: Select a Command
    example: turnOff
    default: 
    required: true
    selector:
      select:
        options:
          - turnOn
          - turnOff
          - setPosition
        mode: list

  index:
    name: Index
    description: Index ("0" by Default)
    example: 0
    default: 0
    required: false
    selector:
      number:
        min: 0
        max: 1
        step: 1
        mode: box

  mode:
    name: Mode
    description: Select a Mode (required for "setPosition" command) ("Default" by Default)
    example: Performance
    default: Default
    required: false
    selector:
      select:
        options:
          - Performance
          - Silent
          - Default 
        mode: list

  position:
    name: Position
    description: Select a Mode (0%-100%) (required for "setPosition" command)
    example: 50
    default: 50
    required: false
    selector:
      number:
        min: 0
        max: 100
        step: 1
        unit_of_measurement: "%"
        mode: slider
    """

    deviceId = extract_device_id(device)
    headers_dict = auth(pyscript.app_config)
    modes={"Performance": "0", "Silent": "1", "Default": "ff"}
    if position == None:
      position = "50"
    if index == None:
      index = "0"
    if command == "turnOn" or command == "turnOff":
      command_execute(headers_dict, deviceId, command, parameter=None)
    else:
      command_execute(headers_dict, deviceId, command, parameter=f"{index},{modes[mode]},{position}")
SiriosDev commented 1 year ago

so nothing 🤔, im little sad 😔