Iteration over group (not working)

Hello together,

Something I can’t turn off is preventing me from filter a group. Maybe I’m just blind, but I can’t figure it out. I hope a second pair of eyes help :wink:
I use Openhab 3.0.2

from core.rules import rule
from core.triggers import when
from shared.helper import getItem, getItemState


@rule("Rollladen schliessen", description="Rollladen schliessen, sobald sich die aeusseren Umstaende aendern")
@when("Item " + cDAEMMERUNG_ITEM_NAME + " changed")
@when("Item " + cTEMPERATUR_WOZ_GROUP_NAME + " changed")
def rollladen_schliessen(event):"iDH_R_Daemmerung: {}, gWOZ_Temperatur: {} ".format( getItemState(cDAEMMERUNG_ITEM_NAME),  getItemState(cTEMPERATUR_WOZ_GROUP_NAME)))
    if getItemState(cDAEMMERUNG_ITEM_NAME) >= cDAEMMERUNG_SCHWELLWERT and getItemState(cTEMPERATUR_WOZ_GROUP_NAME) >= cTEMPERATUR_SCHWELLWERT:"rollladen werden geschlossen")"{}".format(getItem(cTEMPERATUR_WOZ_GROUP_NAME).members.getClass))

Every time I try to filter a group I get the following console output:
AttributeError: ‘java.util.Collections$UnmodifiableSet’ object has no attribute ‘filter’
So of course, unmodifiableSet has no filter function…
What do I wrong?

Don’t post screen shots of logs or of code. It’s impossible to read on a phone, cannot be found in a search and in generally is less than useful. Please post the full logs as text in code fences the same as you do for rules code.

From looking at the code it looks like you are attempting to work with the members of a Group as if you were writing in Rules DSL. Rules DSL is a wholly different language and it adds a bunch of stuff to working with Collections that are simply not available in any other language, at least not in the same ways. The error is telling you that members is an UnmodifiableSet and there is no filter method, which is in fact the case. Rules DSL adds one to it but you are not writing in Rules DSL.

You are writing in Python so you need to work with the Collection in a Python way.

filter(lambda item: item.state == ON, ir.getItem("MyGroup").members)

or alternatively

[item for item in ir.getItem("MyGroup").members if item.state == ON]

Those two lines will return a list of all the members of MyGroup whose state is ON. See Design Pattern: Working with Groups in Rules

But you have a further problem. Assuming Rules DSL, filter[i | i.getItemName] is nonsense. What is it you are trying to accomplish? Are you trying to find all the members with a given name? Given that only one can possibly have a given name you should use findFirst instead. And you have to give it a boolean expression, something that evaluates to true or false. i.getItemName doesn’t evaluate to true nor false.

If you are wanting to get a list of all the member’s names, you need to use a map.

map(lambda item: item.getItemName(), ir.getItem("cTEMPERATURE_WOZ_GROUP_NAME"))

of using list comprehension

[item.getItemName() for item in ir.getItem("cTEMPERATURE_WOZ_GROUP_NAME")]