Skip to content

Feature Request: methods on entity_ids #64

Closed
@dlashua

Description

@dlashua

It would be a nice language feature if entity id's could have service calls made against them as though they were real python objects. When this syntax is invoked, it would result in a service_call with the entity_id kwarg set to the entity_id it was called on.

Example Script that works today:

@state_trigger('input_boolean.test_1 == "on"')
def do_it():
  input_boolean.turn_on(entity_id="input_boolean.test_2")

Proposed Possible Syntax:

@state_trigger('input_boolean.test_1 == "on"')
def do_it():
  input_boolean.test_2.turn_on()

This should be enabled for all entity_ids in any domain:

climate.set_preset_mode(entity_id="climate.hvac", preset_mode="home")
climate.hvac.set_preset_mode(preset_mode="home")

input_number.set_value(entity_id="input_number.test", value="13")
input_number.test.set_value(value="13")

input_select.select_option(entity_id="input_select.dishwasher_status", option="clean")
input_select.dishwasher_status.select_option(option="clean")

This makes the code look cleaner and more readable. It also prevents the need to type "input_number" (for instance) twice, and prevents the need to type "entity_id" at all.

An even better extension of this proposal would require a hardcoded list to be kept and maintained in pyscript since I don't believe this information is provided by HASS (though it might be detectable by the parameter information given when HASS enumerates available service calls). Service calls that only require two kwargs -- entity_id and one other thing -- could have the kwarg for that other thing hard coded (or somehow detected). For instance, for input_number.set_value, the other kwarg is value. If pyscript knew this then this syntax would be possible:

input_number.set_value(entity_id="input_number.test", value="13")
input_number.test.set_value(value="13")
input_number.test.set_value("13")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions