Coverage for mobius_adapter/config.py: 85%

32 statements  

« prev     ^ index     » next       coverage.py v7.0.0, created at 2022-12-20 14:31 +0000

1import json 

2import os 

3from typing import TypedDict 

4 

5 

6class ConversionEntry(TypedDict): 

7 sensorId: str 

8 sensorPath: str 

9 

10 

11class MobiusConfig: 

12 config = {} 

13 host: str 

14 port: int 

15 # Converts nodeID to sensorId and sensorPath 

16 conversion: dict[str, ConversionEntry] 

17 

18 def __init__(self): 

19 script_path = os.path.abspath(__file__) 

20 path_list = script_path.split(os.sep) 

21 relpath = "/config.json" 

22 

23 path = "/".join(path_list[:-1]) + relpath 

24 with open(path) as f: 

25 self.config = json.load(f) 

26 

27 @property 

28 def host(self) -> str: 

29 return self.config["host"] 

30 

31 @property 

32 def port(self) -> int: 

33 return self.config["port"] 

34 

35 @property 

36 def originator(self) -> str: 

37 return self.config["originator"] 

38 

39 def nodeID_to_sensorId(self, nodeID: int) -> str: 

40 return self.config["conversion"][str(nodeID)]["sensorId"] 

41 

42 def nodeID_to_sensorPath(self, nodeID: int) -> str: 

43 return self.config["conversion"][str(nodeID)]["sensorPath"] 

44 

45 

46config = MobiusConfig()