-
Notifications
You must be signed in to change notification settings - Fork 58
-
Logger: custom_components.pyscript.file.wall_box_start.get_new_price
Exception in <file.wall_box_start.get_new_price> line 22: daten.sort(key=sort_price) ^ TypeError: '<' not supported between instances of 'coroutine' and 'coroutine'
@service
def get_new_price():
def sort_price(x):
return x["price"]
# snipp
daten = [{'date': '2025-07-15T05:00:00.000Z', 'price': 29.36}, {'date': '2025-07-15T06:00:00.000Z', 'price': 28.58}]
daten.sort(key=sort_price)
and
def sort_price(x):
return x["price"]
@service
def get_new_price():
# snipp
daten.sort(key=sort_price)
also fails
...
so how to do sub functions ?
bonus: how to check debug of integration ist on / off ?
Beta Was this translation helpful? Give feedback.
All reactions
lambda works fine:
@service def get_new_price(trigger_type=None, var_name=None, value=None, old_value=None, context=None, **kwargs): daten = [ {'date': '2025-07-15T05:00:00.000Z', 'price': 29.36}, {'date': '2025-07-15T06:00:00.000Z', 'price': 28.58} ] result = sorted(daten, key=lambda x: x['price'], reverse=False) log.debug(f"{__name__}:\n{str_.__class__.__name__} {str_}")
Replies: 2 comments
-
lambda works fine:
@service def get_new_price(trigger_type=None, var_name=None, value=None, old_value=None, context=None, **kwargs): daten = [ {'date': '2025-07-15T05:00:00.000Z', 'price': 29.36}, {'date': '2025-07-15T06:00:00.000Z', 'price': 28.58} ] result = sorted(daten, key=lambda x: x['price'], reverse=False) log.debug(f"{__name__}:\n{str_.__class__.__name__} {str_}")
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
The issue is that all functions in pyscript are async. Python's list sort()
function requires key
to be a regular function. You can accomplish that via a lambda
(as @ALERTua did), or by adding @pyscript_compile
as a decorator on your sort_price()
function. See the 3rd bullet in this section of the docs.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 2