Skip to content

Commit

Permalink
Merge pull request #6 from JarbasHiveMind/release-0.2.0a1
Browse files Browse the repository at this point in the history
Release 0.2.0a1
  • Loading branch information
JarbasAl authored Dec 29, 2024
2 parents 8f80b29 + 3a52b3e commit 8640b3c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Changelog

## [0.1.0a1](https://github.com/JarbasHiveMind/hivemind-plugin-manager/tree/0.1.0a1) (2024-12-29)
## [0.2.0a1](https://github.com/JarbasHiveMind/hivemind-plugin-manager/tree/0.2.0a1) (2024-12-29)

[Full Changelog](https://github.com/JarbasHiveMind/hivemind-plugin-manager/compare/0.0.2...0.1.0a1)
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-plugin-manager/compare/0.1.0...0.2.0a1)

**Merged pull requests:**

- feat: add plugin factory classes [\#3](https://github.com/JarbasHiveMind/hivemind-plugin-manager/pull/3) ([JarbasAl](https://github.com/JarbasAl))
- feat: add client callbacks [\#5](https://github.com/JarbasHiveMind/hivemind-plugin-manager/pull/5) ([JarbasAl](https://github.com/JarbasAl))



Expand Down
28 changes: 26 additions & 2 deletions hivemind_plugin_manager/protocols.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import abc
import dataclasses
from dataclasses import dataclass
from typing import Dict, Any, Union, Optional
from typing import Dict, Any, Union, Optional, Callable

from ovos_bus_client import MessageBusClient
from ovos_utils.fakebus import FakeBus
Expand All @@ -10,11 +10,33 @@
from hivemind_bus_client.identity import NodeIdentity


def on_disconnect(client: 'HiveMindClientConnection'):
LOG.debug(f"callback: client disconnected: {client}")

def on_connect(client: 'HiveMindClientConnection'):
LOG.debug(f"callback: client connected: {client}")

def on_invalid_key(client: 'HiveMindClientConnection'):
LOG.debug(f"callback: invalid access key: {client}")

def on_invalid_protocol(client: 'HiveMindClientConnection'):
LOG.debug(f"callback: protocol requirements failure: {client}")


@dataclass
class ClientCallbacks:
on_connect: Callable[['HiveMindClientConnection'], None] = on_connect
on_disconnect: Callable[['HiveMindClientConnection'], None] = on_disconnect
on_invalid_key: Callable[['HiveMindClientConnection'], None] = on_invalid_key
on_invalid_protocol: Callable[['HiveMindClientConnection'], None] = on_invalid_protocol


@dataclass
class _SubProtocol:
"""base class all protocols derive from"""
config: Dict[str, Any] = dataclasses.field(default_factory=dict)
hm_protocol: Optional['HiveMindListenerProtocol'] = None
callbacks: ClientCallbacks = dataclasses.field(default_factory=ClientCallbacks)

@property
def identity(self) -> NodeIdentity:
Expand Down Expand Up @@ -42,13 +64,14 @@ class AgentProtocol(_SubProtocol):
config: Dict[str, Any] = dataclasses.field(default_factory=dict)
hm_protocol: Optional['HiveMindListenerProtocol'] = None # usually AgentProtocol is passed as kwarg to hm_protocol
# and only then assigned in hm_protocol.__post_init__

callbacks: ClientCallbacks = dataclasses.field(default_factory=ClientCallbacks)

@dataclass
class NetworkProtocol(_SubProtocol):
"""protocol to transport HiveMessage objects around"""
config: Dict[str, Any] = dataclasses.field(default_factory=dict)
hm_protocol: Optional['HiveMindListenerProtocol'] = None
callbacks: ClientCallbacks = dataclasses.field(default_factory=ClientCallbacks)

@property
def agent_protocol(self) -> Optional['AgentProtocol']:
Expand All @@ -68,6 +91,7 @@ class BinaryDataHandlerProtocol(_SubProtocol):
hm_protocol: Optional['HiveMindListenerProtocol'] = None # usually BinaryDataHandlerProtocol is passed as kwarg to hm_protocol
# and only then assigned in hm_protocol.__post_init__
agent_protocol: Optional['AgentProtocol'] = None
callbacks: ClientCallbacks = dataclasses.field(default_factory=ClientCallbacks)

def __post_init__(self):
# NOTE: the most common scenario is having self.agent_protocol but not having self.hm_protocol yet
Expand Down
4 changes: 2 additions & 2 deletions hivemind_plugin_manager/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# START_VERSION_BLOCK
VERSION_MAJOR = 0
VERSION_MINOR = 1
VERSION_MINOR = 2
VERSION_BUILD = 0
VERSION_ALPHA = 0
VERSION_ALPHA = 1
# END_VERSION_BLOCK

0 comments on commit 8640b3c

Please sign in to comment.