diff --git a/README.md b/README.md index 440c2f5..ed2577a 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,21 @@ Automated use cases: The Hub contains a Protocol, and can utilise modules A device contains a protocol, and can utilise modules +Decisions to be made: + +1. Proposed change of device and module layout: + A Device contains a bunch of modules, a module contains a bunch of components + - Device (RPI, Arduino) + - Module (AM2302) + - Glue to connect modules to the device! + - Cons: + - Configuration complexity + - Pros: + - Reusable modules 2 modules for one data record - Temp and Humidity + - Modules are small and can contain their own tests + - Naming of the glue? That is currently modules, could make a new dir for components that are self + contained! + ## TODO: 1. Fix: Bug: The script startup gets an incorrect time (Hasn't yet got the internet time) diff --git a/standalone_modules/_template_module/README.md b/standalone_modules/_template_module/README.md new file mode 100644 index 0000000..a35103f --- /dev/null +++ b/standalone_modules/_template_module/README.md @@ -0,0 +1 @@ +# Template Module diff --git a/standalone_modules/_template_module/__init__.py b/standalone_modules/_template_module/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/standalone_modules/_template_module/device_protocol.py b/standalone_modules/_template_module/device_protocol.py new file mode 100644 index 0000000..58e2471 --- /dev/null +++ b/standalone_modules/_template_module/device_protocol.py @@ -0,0 +1,32 @@ +from standalone_modules.shed_pi_module_utils.base_protocol import BaseProtocol +from standalone_modules.shed_pi_module_utils.data_submission import ( + ReadingSubmissionService, +) +from standalone_modules.shed_pi_module_utils.utils import logger + + +class DeviceProtocol(BaseProtocol): + def __init__(self, submission_service: ReadingSubmissionService): + ... + + def stop(self): + logger.info("Stopping device protocol") + + def start(self): + logger.info("Starting device protocol") + + +def main(): + # The Submission service is used to record any module data + submission_service = ReadingSubmissionService() + device = DeviceProtocol(submission_service=submission_service) + + try: + device.startup() + device.start() + finally: + device.shutdown() + + +if __name__ == "__main__": + main() diff --git a/standalone_modules/_template_module/tests/__init__.py b/standalone_modules/_template_module/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/standalone_modules/_template_module/tests/integration/__init__.py b/standalone_modules/_template_module/tests/integration/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/standalone_modules/_template_module/tests/unit/__init__.py b/standalone_modules/_template_module/tests/unit/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/standalone_modules/shed_pi_module_utils/base_protocol.py b/standalone_modules/shed_pi_module_utils/base_protocol.py index 1611ed6..fab8a05 100644 --- a/standalone_modules/shed_pi_module_utils/base_protocol.py +++ b/standalone_modules/shed_pi_module_utils/base_protocol.py @@ -1,3 +1,5 @@ +from warnings import deprecated + from standalone_modules.shed_pi_module_utils.data_submission import ( ReadingSubmissionService, ) @@ -7,14 +9,30 @@ class BaseProtocol: def __init__(self, submission_service: ReadingSubmissionService): self.submission_service = submission_service - def stop(self): + def start(self) -> None: + """ + Start any services or logic on demand + """ ... - def startup(self): + def stop(self) -> None: + """ + Stop any services or logic on demand + """ ... - def run(self): - raise NotImplementedError + def startup(self) -> None: + """ + Run at startup + """ + ... - def shutdown(self): + def shutdown(self) -> None: + """ + Run at destruction + """ ... + + @deprecated("Deprecated run method is replaced by start") + def run(self) -> None: + raise NotImplementedError