custom-components / pyscript

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

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

Open ALERTua opened 10 months ago

ALERTua commented 10 months ago

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)
dmamelin commented 10 months ago

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