Skip to content

enum methods are not working #787

@karabays

Description

@karabays

Hi,
I'm trying to use the Enum as it's introduced in the latest release but instance methods are not working as usual.

pyscript version: 1.7.0
HA version: 2025.12.2, home assistant OS

A simple class for home mode and a method to update entity state in HA.

class HomeState(Enum):
    HOME = "home"
    AWAY = "away"
    EXTENDED_AWAY = "extended_away"
    SLEEPING = "sleeping"
    JUST_ARRIVED = "just_arrived"

    def set_state(self):
        state.set("pyscript.home_state",self.value, new_attributes={"test":True})

state.persist("pyscript.home_state", default_value = HomeState.HOME.value,
                default_attributes = {"icon":"mdi:home-account"})

@time_trigger
def test():
    ha_state = HomeState.AWAY
    ha_state.set_state()

above the test function fails with the following error log:

This error originated from a custom integration.

Logger: custom_components.pyscript.file.location.test
Source: custom_components/pyscript/trigger.py:1397
integration: Pyscript Python scripting (documentation, issues)
First occurred: 14:29:57 (1 occurrence)
Last logged: 14:29:57

Exception in <file.location.test> line 36: ha_state.set_state() ^ TypeError: 'set_state' is not callable (got HomeState.set_state) Traceback (most recent call last): File "/config/custom_components/pyscript/eval.py", line 946, in aeval val = await getattr(self, name, self.ast_not_implemented)(arg) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/pyscript/eval.py", line 1967, in ast_call return await self.call_func(func, func_name, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/pyscript/eval.py", line 2019, in call_func raise TypeError(f"'{func_name}' is not callable (got {func})") TypeError: 'set_state' is not callable (got HomeState.set_state)

but this works:

def set_state_in_ha(home_state:HomeState):
    state.set("pyscript.home_state",home_state.value)

Am I doing something wrong or enum is not fully functional in pyscript.

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