madsci.node_module 0.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ Metadata-Version: 2.1
2
+ Name: madsci.node_module
3
+ Version: 0.0.3
4
+ Summary: The Modular Autonomous Discovery for Science (MADSci) Node Module Helper Classes.
5
+ Author-Email: Tobias Ginsburg <tginsburg@anl.gov>, "Ryan D. Lewis" <ryan.lewis@anl.gov>, Casey Stone <cstone@anl.gov>, Doga Ozgulbas <dozgulbas@anl.gov>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/AD-SDL/MADSci
8
+ Requires-Python: >=3.9.1
9
+ Requires-Dist: madsci.common
10
+ Description-Content-Type: text/markdown
11
+
File without changes
@@ -0,0 +1,29 @@
1
+ [project]
2
+ name = "madsci.node_module"
3
+ version = "0.0.3"
4
+ description = "The Modular Autonomous Discovery for Science (MADSci) Node Module Helper Classes."
5
+ authors = [
6
+ { name = "Tobias Ginsburg", email = "tginsburg@anl.gov" },
7
+ { name = "Ryan D. Lewis", email = "ryan.lewis@anl.gov" },
8
+ { name = "Casey Stone", email = "cstone@anl.gov" },
9
+ { name = "Doga Ozgulbas", email = "dozgulbas@anl.gov" },
10
+ ]
11
+ requires-python = ">=3.9.1"
12
+ readme = "README.md"
13
+ dependencies = [
14
+ "madsci.common",
15
+ ]
16
+
17
+ [project.license]
18
+ text = "MIT"
19
+
20
+ [project.urls]
21
+ Homepage = "https://github.com/AD-SDL/MADSci"
22
+
23
+ [build-system]
24
+ requires = [
25
+ "pdm-backend",
26
+ ]
27
+ build-backend = "pdm.backend"
28
+
29
+ [tool]
@@ -0,0 +1,79 @@
1
+ """A test REST Node for validating the madsci.node_module package."""
2
+
3
+ from typing import Optional
4
+
5
+ from madsci.client.event_client import EventClient
6
+ from madsci.common.types.node_types import RestNodeConfig
7
+ from madsci.node_module.abstract_node_module import action
8
+ from madsci.node_module.rest_node_module import RestNode
9
+
10
+
11
+ class TestNodeConfig(RestNodeConfig):
12
+ """Configuration for the test node module."""
13
+
14
+ test_required_param: int
15
+ """A required parameter."""
16
+ test_optional_param: Optional[int] = None
17
+ """An optional parameter."""
18
+ test_default_param: int = 42
19
+ """A parameter with a default value."""
20
+
21
+
22
+ class TestNodeInterface:
23
+ """A fake test interface for testing."""
24
+
25
+ status_code: int = 0
26
+
27
+ def __init__(self, logger: Optional[EventClient] = None) -> "TestNodeInterface":
28
+ """Initialize the test interface."""
29
+ self.logger = logger if logger else EventClient()
30
+
31
+ def run_command(self, command: str, fail: bool = False) -> bool:
32
+ """Run a command on the test interface."""
33
+ self.logger.log(f"Running command {command}.")
34
+ if fail:
35
+ self.logger.log(f"Failed to run command {command}.")
36
+ return False
37
+ return True
38
+
39
+
40
+ class TestNode(RestNode):
41
+ """A test node module for automated testing."""
42
+
43
+ test_interface: TestNodeInterface = None
44
+ config_model = TestNodeConfig
45
+
46
+ def startup_handler(self) -> None:
47
+ """Called to (re)initialize the node. Should be used to open connections to devices or initialize any other resources."""
48
+ self.test_interface = TestNodeInterface(logger=self.logger)
49
+ self.logger.log("Test node initialized!")
50
+
51
+ def shutdown_handler(self) -> None:
52
+ """Called to shutdown the node. Should be used to close connections to devices or release any other resources."""
53
+ self.logger.log("Shutting down")
54
+ del self.test_interface
55
+
56
+ def state_handler(self) -> dict[str, int]:
57
+ """Periodically called to get the current state of the node."""
58
+ if self.test_interface is not None:
59
+ self.node_state = {
60
+ "test_status_code": self.test_interface.status_code,
61
+ }
62
+ return self.node_state
63
+
64
+ @action
65
+ def test_action(self, test_param: int) -> bool:
66
+ """A test action."""
67
+ return self.test_interface.run_command(f"Test action with param {test_param}.")
68
+
69
+ @action
70
+ def test_action_fail(self, test_param: int) -> bool:
71
+ """A test action that fails."""
72
+ return self.test_interface.run_command(
73
+ f"Test action with param {test_param}.", fail=True
74
+ )
75
+
76
+
77
+ if __name__ == "__main__":
78
+ test_node = TestNode()
79
+ test_node.start_node()
@@ -0,0 +1,21 @@
1
+ node_name: null
2
+ module_name: TestModule
3
+ node_type: device
4
+ module_description: A module for automated testing
5
+ module_version: 0.0.1
6
+ capabilities:
7
+ get_info: false
8
+ get_state: false
9
+ get_status: false
10
+ send_action: false
11
+ get_action_result: false
12
+ get_action_history: false
13
+ action_files: false
14
+ send_admin_commands: false
15
+ set_config: false
16
+ get_resources: false
17
+ get_log: false
18
+ events: false
19
+ resources: false
20
+ admin_commands: []
21
+ commands: {}