-
Notifications
You must be signed in to change notification settings - Fork 40
[WIP] Events, LED #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
add python-mpv dependency to .venv
|
Completely outsider that just landed on the project... I think the bus idea is great and can be used for a lot of things! I see there is another pr with thinking sound, etc that too can go through the bus... It would be awesome if this bus can be accessed externally... kind of the way rhasspy does it... but maybe not, meaning exposing a server to where several clients can connect and read events from the bus... so that we can have a 2mics led client, a 4mics led client but also a thinking_sound client... etc... but this channel can also be bidirectional, so a push_button client can also be implemented to trigger the listening... Don't know... my two cents... for now I'm focussed on build the bare project onto my buildroot image :) |
| def subscribe(func: Callable) -> Callable: | ||
| """Decorator to mark a method for event bus subscription.""" | ||
| func._event_bus_subscribe = True | ||
| return func |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion] Configurable handler metadata:
| def subscribe(func: Callable) -> Callable: | |
| """Decorator to mark a method for event bus subscription.""" | |
| func._event_bus_subscribe = True | |
| return func | |
| @dataclass | |
| class EventBusMetaData: | |
| priority: int = 0 | |
| # Any other info related to the handler | |
| def subscribe(priority: int=0, **kwargs): | |
| """Decorator to mark a method for event bus subscription.""" | |
| def wrapper(func: Callable) -> Callable: | |
| """Function wrapper.""" | |
| func._event_bus_subscribe = True | |
| func._event_bus_meta = EventBusMetaData( | |
| priority=priority, | |
| ... | |
| ) | |
| return func | |
| return wrapper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Nitpick] An event bus is based off events - not topics, it would scale far more easily to have event handlers react to VoiceAssistantEvents
| def publish(self, topic: str, data: [dict, None]) -> None: | ||
| """ | ||
| Publishes an event to all subscribed listeners. | ||
| """ | ||
|
|
||
| # _LOGGER.debug(f'EventBus publish {topic}') | ||
|
|
||
| data['__topic'] = topic | ||
|
|
||
| listeners = self.topics.get(topic, []) | ||
| for listener in listeners: | ||
| listener(data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion] Based on below suggestion:
| def publish(self, topic: str, data: [dict, None]) -> None: | |
| """ | |
| Publishes an event to all subscribed listeners. | |
| """ | |
| # _LOGGER.debug(f'EventBus publish {topic}') | |
| data['__topic'] = topic | |
| listeners = self.topics.get(topic, []) | |
| for listener in listeners: | |
| listener(data) | |
| async def publish(self, topic: str, data: [dict, None]) -> None: | |
| """ | |
| Publishes an event to all subscribed listeners. | |
| """ | |
| # _LOGGER.debug(f'EventBus publish {topic}') | |
| data['__topic'] = topic | |
| listeners = self.topics.get(topic, []) | |
| for listener in sorted(listeners, key=lambda l: l._event_bus_priority): | |
| if inspect.iscoroutine(listener): | |
| await listener(data) | |
| else: | |
| listener(data) |
When publishing events, use asyncio.create_task to publish the event.
|
Can you specify if this is for the v1 or the v2 of the 2MicHat? |
|
We have discussions now. It would be great, if you can add one for the LED part and hope you give some input from what you already did, maybe future ideas etc. |
This is a work in progress to add features for LED and button(s) on the 2mic pi hat. This PR will also include some other house keeping and general quality of life concerns
Completed
Todo
events_led.pycode so it will also work with the 4mic. The code can be abstracted to work with any LED/light via pub/sub.I would love comments on this PR, and also some guidance/links to working with the ESPhome package and API.