spacemanspiff2007 / HABApp

Easy home automation with MQTT and/or openHAB
Apache License 2.0
54 stars 23 forks source link

openHAB PlayerItem doesn't receive prev/next commands #445

Closed kimifish closed 2 months ago

kimifish commented 2 months ago

Test code like this

import HABApp
from HABApp.openhab.items import PlayerItem
from HABApp.core.events import ValueUpdateEvent, ValueUpdateEventFilter

class Player(HABApp.Rule):
    def __init__(self, player):
        super().__init__()
        self.player = PlayerItem.get_item(player)
        self.listen_event(self.player, self.command_received, ValueUpdateEventFilter())

    def command_received(self, event: ValueUpdateEvent):
        log.warning(f'Command received: {event.value}')

player = Player('ScYt_Player')

after pressing default player widget buttons "Previous", "Play/Pause", "Next" in mainUI outputs only this:

04/15 18:17:14 HABApp.ScYt:43 │WARNING│ Command received: PLAY 04/15 18:17:16 HABApp.ScYt:43 │WARNING│ Command received: PAUSE

No Prev and Next events. =( Maybe I'm missing something?

events.log output does have those events:

2024-04-15 18:19:35.311 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'ScYt_Player' received command PREVIOUS

spacemanspiff2007 commented 2 months ago

I'm not sure I understand the issue. Can you describe which behavior you would have expected and what the current behavior is?

Also this should probably

self.listen_event(self.player, self.command_received, ValueUpdateEventFilter())

be this:

self.listen_event(self.player, self.command_received, ItemCommandEventFilter())
kimifish commented 2 months ago

When I press widget's Play and Pause, I see events in openhab's events.log and corresponding lines in habapp log as above. But when I press "Previous" and "Next" buttons, I see events in events.log, but callback method from my HABApp rule isn't called and no habapp logs printed out. Yes, event filter must be more specific, I've changed it just in case i was missing another event type.

kimifish commented 2 months ago

Sorry, my fault. Changed event type to ItemCommandEvent, and everything works now. It turned out, that play and pause events are of type "ItemStateChangedEvent", and Prev/Next are of "ItemCommandEvent", and the last is not in inheritance with ValueUpdateEvent. So consistent, but so unobvious...