[why do you] Not use the GroupItem
to get all members?
Is this what you mean:
def __init__(self):
super().__init__()
self.group = GroupItem.get_item('System_Volume')
for i in self.group.members:
i.listen_event(self.System_Volume, ItemCommandEventFilter()) # Received Command
log.info(f'RULE LOADED: {self}')
[why do you] Use OpenhabItem
in the event block instead of the proper item type (e.g. NumberItem
)
I didn’t post the full rule. The Group has more than one type of item in it, so it would fail if I used a specific type. Below the log.info
I go into several if/then’s of if isinstance(tItem, DimmerItem)
etc… What is the advantage of doing this other than I can then use the type specific helpers like tItem.on
?
[why do you] Use the item registry to get the item instead of a local dict in the __init__
block for the items that you are using?
So, the code I posted just above, using GroupItem.get_item()
works, but how do I create the ‘dict’ you speak of that I can then access the item object from my event block using event.name
? What’s the advantage? Is using a local dict faster than using the registry?
I’ve tried: item = self.group.members.get_item(event.name)
in the event block, along with a few other things, but they doesn’t work. Or, asked another way, how do I get an “get an item” from “self.group.members” based on the item’s name? Seems like there would be a built-in way to do this?
[why do you] Try getting the event type - it’s always ItemCommandEvent
Actually that gets the triggering item type, not the event type (DimmerItem, SwitchItem, etc). I previously used that to get the item’s type, but now I’m using the isinstance()
method to do the same because it seemed like that’s what people were doing, and that there wasn’t a really nice looking way of getting the item’s type like there was in jython or rules dsl like item.type
.
[why you] Don’t use a type hint for event?
What is the advantage with doing this? Does it affect the code somehow or just the IDE experience. I have never done anything type hints in my code before, and from reading it seems like something to do with PyCharm. I’m a cheap ba$%^$# and saw that it only had a 30 day trial period so I’m just sticking with VS code. Is there a way I can get type hints in VS code? Should I stop being cheap and buy PyCharm?
[why you] Don’t use newlines after if
and for
Well, because if I can get it on one line, sort of like a list comprehension, in a manageable width, that’s what I do. Other than Basic in Highschool and Ada95 (yes) in my freshman year of college, I have no code training. I’ll stop doing it if you tell me I should!
Can you create a github issue with a short snippet from the event log and the complete error message please?
YES!