Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

entities number as first character of id gives invalid decimal literal error #165

Closed
eavanvalkenburg opened this issue Feb 21, 2021 · 6 comments

Comments

@eavanvalkenburg
Copy link

I just started using pyscript and it is amazing! can't believe I missed it so far, but I have one bug, I have a alarm_control_panel that is called 8120_aaa_1_alarm which gives the error:
SyntaxError: invalid decimal literal (file.blind.control_blinds @state_trigger(), line 1)

For state I can work around it by using state.get("alarm_control_panel.8120_aaa_1_alarm") but in the trigger I don't think I can.

@craigbarratt
Copy link
Member

Ah, I didn't think about state names that start with numbers. Python won't parse those. As you point out, you can use state.get() instead, and you are correct in pointing out that doesn't work in @state_trigger since the auto-detection of state variable names to watch isn't able to look inside string arguments to functions like state.get().

As a workaround, the any-change trigger @state_trigger("alarm_control_panel.8120_aaa_1_alarm") should work (since it doesn't involve expression evaluation), and then you could use @state_active to condition the trigger (with state.get()):

@state_trigger("alarm_control_panel.8120_aaa_1_alarm")
@state_active("state.get('alarm_control_panel.8120_aaa_1_alarm') == 'something')
def alarm_trigger():
    ...

One fix would be to add an optional watch keyword argument to @state_trigger that could be a list of state (entity) variables to watch. That could be used to override the auto-detection. Then it would look like:

@state_trigger("state.get('alarm_control_panel.8120_aaa_1_alarm') == 'something', watch=["alarm_control_panel.8120_aaa_1_alarm"])
def alarm_trigger():
    ...

craigbarratt added a commit that referenced this issue Feb 22, 2021
@eavanvalkenburg
Copy link
Author

My triggers are all any-change, but I do have multiple setup, so it is @state.trigger("sun.sun.elevation or alarm...., don't know if that does trigger expression evaluation?

@craigbarratt
Copy link
Member

For any-change triggers on several variables you should use separate arguments (could also be one argument with a list of strings):

@state.trigger("sun.sun.elevation", "alarm_control_panel.8120_aaa_1_alarm")

That avoids evaluating any expression, so the numeric state name should be ok.

This form should work in the current version, without the new watch keyword argument that I added.

@eavanvalkenburg
Copy link
Author

Just tried it, but that gives the same error, both with multiple and just with the one.

@craigbarratt
Copy link
Member

You're right. The regex that checks for just a single variable name didn't allow leading digits. It's fixed now.

@eavanvalkenburg
Copy link
Author

Loaded master and it works now, thanks for the fix!

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

No branches or pull requests

2 participants