Skip to content

Commit

Permalink
Started splitting out components and standardising modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiky30 committed Dec 5, 2024
1 parent e9f1aeb commit 5bcefbf
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 5 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions standalone_modules/_template_module/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Template Module
Empty file.
32 changes: 32 additions & 0 deletions standalone_modules/_template_module/device_protocol.py
Original file line number Diff line number Diff line change
@@ -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()
Empty file.
Empty file.
Empty file.
28 changes: 23 additions & 5 deletions standalone_modules/shed_pi_module_utils/base_protocol.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from warnings import deprecated

from standalone_modules.shed_pi_module_utils.data_submission import (
ReadingSubmissionService,
)
Expand All @@ -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

0 comments on commit 5bcefbf

Please sign in to comment.