stinger-ipc 0.0.1__py3-none-any.whl
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.
- stinger_ipc-0.0.1.dist-info/METADATA +170 -0
- stinger_ipc-0.0.1.dist-info/RECORD +13 -0
- stinger_ipc-0.0.1.dist-info/WHEEL +5 -0
- stinger_ipc-0.0.1.dist-info/licenses/LICENSE +504 -0
- stinger_ipc-0.0.1.dist-info/top_level.txt +1 -0
- stingeripc/__init__.py +4 -0
- stingeripc/args.py +116 -0
- stingeripc/asyncapi.py +501 -0
- stingeripc/components.py +964 -0
- stingeripc/connection.py +7 -0
- stingeripc/exceptions.py +3 -0
- stingeripc/interface.py +38 -0
- stingeripc/topic.py +67 -0
stingeripc/connection.py
ADDED
stingeripc/exceptions.py
ADDED
stingeripc/interface.py
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
from typing import Optional, Any, Dict, IO, Union
|
2
|
+
import yaml
|
3
|
+
import yamlloader
|
4
|
+
|
5
|
+
from .components import StingerSpec, InvalidStingerStructure
|
6
|
+
from .topic import InterfaceTopicCreator
|
7
|
+
|
8
|
+
VERSION_SUPPORTED = "0.0.6"
|
9
|
+
|
10
|
+
|
11
|
+
class StingerInterface(StingerSpec):
|
12
|
+
|
13
|
+
def __init__(self, stinger: Dict[str, Any], topic_prefix: Optional[str] = None):
|
14
|
+
itc = self._create_topic_creator(stinger)
|
15
|
+
super().__init__(itc, stinger['interface'])
|
16
|
+
|
17
|
+
@staticmethod
|
18
|
+
def _create_topic_creator(stinger_spec: Dict[str, Any], topic_prefix: Optional[str] = None) -> InterfaceTopicCreator:
|
19
|
+
if (
|
20
|
+
"stingeripc" not in stinger_spec
|
21
|
+
or "version" not in stinger_spec["stingeripc"]
|
22
|
+
or stinger_spec["stingeripc"]["version"] not in [VERSION_SUPPORTED]
|
23
|
+
):
|
24
|
+
raise InvalidStingerStructure(
|
25
|
+
f"Provided Stinger Spec does not claim to be version {VERSION_SUPPORTED}"
|
26
|
+
)
|
27
|
+
if "interface" not in stinger_spec or "name" not in stinger_spec["interface"]:
|
28
|
+
raise InvalidStingerStructure(
|
29
|
+
"Could not find interface name in Stinger Spec"
|
30
|
+
)
|
31
|
+
itc = InterfaceTopicCreator(stinger_spec["interface"]["name"], root=topic_prefix)
|
32
|
+
return itc
|
33
|
+
|
34
|
+
@classmethod
|
35
|
+
def from_yaml(cls, yaml_input: Union[str, IO]) -> StingerSpec:
|
36
|
+
yaml_obj = yaml.load(yaml_input, Loader=yamlloader.ordereddict.Loader)
|
37
|
+
itc = cls._create_topic_creator(yaml_obj)
|
38
|
+
return cls.new_spec_from_stinger(itc, yaml_obj)
|
stingeripc/topic.py
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
from typing import Optional
|
2
|
+
|
3
|
+
|
4
|
+
class TopicCreatorBase:
|
5
|
+
def __init__(self, root: Optional[str] = None):
|
6
|
+
if root is None:
|
7
|
+
self._base_topic = None
|
8
|
+
else:
|
9
|
+
self._base_topic = root.strip("/")
|
10
|
+
|
11
|
+
def slash(self, *args) -> str:
|
12
|
+
if self._base_topic is None:
|
13
|
+
return "/".join(args)
|
14
|
+
else:
|
15
|
+
return f"{self._base_topic}/{'/'.join(args)}"
|
16
|
+
|
17
|
+
|
18
|
+
class SignalTopicCreator(TopicCreatorBase):
|
19
|
+
def __init__(self, root: str):
|
20
|
+
super().__init__(root)
|
21
|
+
|
22
|
+
def signal_topic(self, signal_name: str) -> str:
|
23
|
+
return self.slash("signal", signal_name)
|
24
|
+
|
25
|
+
class MethodTopicCreator(TopicCreatorBase):
|
26
|
+
def __init__(self, root: str):
|
27
|
+
super().__init__(root)
|
28
|
+
|
29
|
+
def method_topic(self, method_name: str) -> str:
|
30
|
+
return self.slash("method", method_name)
|
31
|
+
|
32
|
+
def method_response_topic(self, method_name: str, client_id: str) -> str:
|
33
|
+
method_topic = self.method_topic(method_name)
|
34
|
+
return f"client/{client_id}/{method_topic}/response"
|
35
|
+
|
36
|
+
class PropertyTopicCreator(TopicCreatorBase):
|
37
|
+
def __init__(self, root: str):
|
38
|
+
super().__init__(root)
|
39
|
+
|
40
|
+
def property_value_topic(self, property_name: str) -> str:
|
41
|
+
return self.slash("property", property_name)
|
42
|
+
|
43
|
+
def property_update_topic(self, property_name: str) -> str:
|
44
|
+
return self.slash("property", property_name, "set_value");
|
45
|
+
|
46
|
+
class InterfaceTopicCreator(TopicCreatorBase):
|
47
|
+
"""Helper class for creating MQTT topics for various stinger elements."""
|
48
|
+
|
49
|
+
def __init__(self, interface_name: str, root: Optional[str] = None):
|
50
|
+
super().__init__(root)
|
51
|
+
self._interface_name = interface_name
|
52
|
+
|
53
|
+
@property
|
54
|
+
def _topic_prefix(self) -> str:
|
55
|
+
return self.slash(self._interface_name)
|
56
|
+
|
57
|
+
def interface_info_topic(self) -> str:
|
58
|
+
return f"{self._topic_prefix}/interface"
|
59
|
+
|
60
|
+
def signal_topic_creator(self) -> SignalTopicCreator:
|
61
|
+
return SignalTopicCreator(self._topic_prefix)
|
62
|
+
|
63
|
+
def method_topic_creator(self) -> MethodTopicCreator:
|
64
|
+
return MethodTopicCreator(self._topic_prefix)
|
65
|
+
|
66
|
+
def property_topic_creator(self) -> PropertyTopicCreator:
|
67
|
+
return PropertyTopicCreator(self._topic_prefix)
|