pyscript icon indicating copy to clipboard operation
pyscript copied to clipboard

State_trigger float/int conversion of entity_ids that start with a number_number

Open ALERTua opened this issue 2 years ago • 1 comments

Glances integration adds generated entity_ids based on the host, provided as a Glances Server. For example, adding a Glances integration using my Unraid server hostname image generates entity_ids like sensor.server_hostname_package_id_0_temperature. But if I add the Glances server by the IP address image Such entity becomes sensor.192_168_1_3_package_id_0_temperature, and Pyscript cannot parse state_trigger condition float conversions based on this entity_id with SyntaxError: invalid decimal literal

This can be proven by creating a Number Helper input_number.123_465_number image that will fail any state_trigger that tries to convert its value to float or int

2023-12-01 14:05:41.156 ERROR (MainThread) [custom_components.pyscript.file.tryouts.tryouts] Exception in <file.tryouts.tryouts @state_trigger()> line 1:
    float(input_number.123_465_number)
                              ^
SyntaxError: invalid decimal literal (file.tryouts.tryouts @state_trigger(), line 1)

ALERTua avatar Dec 01 '23 12:12 ALERTua

In Python, identifiers starting with a digit are prohibited. You should use state.get("sensor.192_168_1_3_package_id_0_temperature")

dmamelin avatar Dec 05 '23 21:12 dmamelin