Skip to content

Commit

Permalink
Reconstruct the modules into installable modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiky30 committed Dec 8, 2024
1 parent f42ef4b commit c1f3be6
Show file tree
Hide file tree
Showing 33 changed files with 143 additions and 157 deletions.
106 changes: 0 additions & 106 deletions shedpi_components/AM2302/__init__.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

import pytest
from rest_framework import status

from shedpi_components.temperature_probe import (
TempProbe,
from shed_pi_module_utils.data_submission import (
ReadingSubmissionService,
)

from shedpi_hub_dashboard.models import DeviceModuleReading
from shedpi_hub_dashboard.tests.utils.factories import (
DeviceModuleFactory,
)
from standalone_modules.shed_pi_module_utils.data_submission import (
ReadingSubmissionService,
from shedpi_module_utils.shedpi_components.ds18b20 import (
TempProbe,
)


Expand Down
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions shedpi_module_utils/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[tool.poetry]
name = "shedpi-module-utils"
version = "0.1.0"
description = ""
authors = ["Andrew Aikman <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.11"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from typing import Optional

import requests

from standalone_modules.shed_pi_module_utils.data_submission import (
from shed_pi_module_utils.data_submission import (
ReadingSubmissionService,
)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from standalone_modules.shed_pi_module_utils.data_submission import (
from shed_pi_module_utils.data_submission import (
ReadingSubmissionService,
)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import pytest
from rest_framework import status
from shed_pi_module_utils.data_submission import (
ReadingSubmissionService,
)
from shed_pi_module_utils.tests.utils import FakeModule

from shedpi_hub_dashboard.models import DeviceModuleReading
from shedpi_hub_dashboard.tests.utils.factories import (
DeviceModuleFactory,
)
from standalone_modules.shed_pi_module_utils.data_submission import (
ReadingSubmissionService,
)
from standalone_modules.shed_pi_module_utils.tests.utils import FakeModule


@pytest.mark.django_db
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import requests

from standalone_modules.shed_pi_module_utils.data_submission import (
from shed_pi_module_utils.data_submission import (
ReadingSubmissionService,
)

Expand Down
6 changes: 3 additions & 3 deletions standalone_modules/_template_module/device_protocol.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from standalone_modules.shed_pi_module_utils.base_protocol import BaseProtocol
from standalone_modules.shed_pi_module_utils.data_submission import (
from shed_pi_module_utils import BaseProtocol
from shed_pi_module_utils.data_submission import (
ReadingSubmissionService,
)
from standalone_modules.shed_pi_module_utils.utils import logger
from shed_pi_module_utils.utils import logger


class DeviceProtocol(BaseProtocol):
Expand Down
5 changes: 2 additions & 3 deletions standalone_modules/rpi/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
import os

import requests

from standalone_modules.shed_pi_module_utils.data_submission import (
from shed_pi_module_utils.data_submission import (
ReadingSubmissionService,
)
from standalone_modules.shed_pi_module_utils.utils import get_time
from shed_pi_module_utils.utils import get_time

logger = logging.getLogger(__name__)

Expand Down
9 changes: 5 additions & 4 deletions standalone_modules/rpi/device_protocol.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import time

from standalone_modules.rpi.device import RPIDevice
from standalone_modules.shed_pi_module_utils.base_protocol import BaseProtocol
from standalone_modules.shed_pi_module_utils.data_submission import (
from shed_pi_module_utils import BaseProtocol
from shed_pi_module_utils.data_submission import (
ReadingSubmissionService,
)
from standalone_modules.shed_pi_module_utils.utils import check_arch_is_arm, logger
from shed_pi_module_utils.utils import check_arch_is_arm, logger

from standalone_modules.rpi.device import RPIDevice

TIME_TO_SLEEP = 60 # time in seconds

Expand Down
6 changes: 3 additions & 3 deletions standalone_modules/rpi/tests/unit/test_device_protocol.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from unittest.mock import Mock

import pytest
from shed_pi_module_utils.data_submission import (
ReadingSubmissionService,
)

from shedpi_hub_dashboard.models import DeviceModuleReading
from shedpi_hub_dashboard.tests.utils.factories import (
Expand All @@ -9,9 +12,6 @@
from standalone_modules.rpi.device_protocol import (
DeviceProtocol,
)
from standalone_modules.shed_pi_module_utils.data_submission import (
ReadingSubmissionService,
)


@pytest.mark.django_db
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import time

from shedpi_components.temperature_probe import TempProbe
from standalone_modules.rpi.device import RPIDevice
from standalone_modules.shed_pi_module_utils.base_protocol import BaseProtocol
from standalone_modules.shed_pi_module_utils.data_submission import (
from shed_pi_module_utils import BaseProtocol
from shed_pi_module_utils.data_submission import (
ReadingSubmissionService,
)
from standalone_modules.shed_pi_module_utils.utils import check_arch_is_arm, logger
from shed_pi_module_utils.utils import check_arch_is_arm, logger

from shedpi_module_utils.shedpi_components.ds18b20 import TempProbe
from standalone_modules.rpi.device import RPIDevice

TIME_TO_SLEEP = 60 # time in seconds

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from unittest.mock import Mock, patch

import pytest
from shed_pi_module_utils.data_submission import (
ReadingSubmissionService,
)

from shedpi_hub_dashboard.models import DeviceModuleReading
from shedpi_hub_dashboard.tests.utils.factories import (
Expand All @@ -9,9 +12,6 @@
from standalone_modules.shed_pi_example_device_installation.device_protocol import (
DeviceProtocol,
)
from standalone_modules.shed_pi_module_utils.data_submission import (
ReadingSubmissionService,
)


@patch("standalone_modules.temperature_module.temperature_probe.Path")
Expand Down
19 changes: 19 additions & 0 deletions standalone_modules/shedpi_module_am2320/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# AM2320 temperature and humidity module

Read more at https://learn.adafruit.com/adafruit-am2320-temperature-humidity-i2c-sensor_

## Hardware installation

AM2320 pinout to Raspberry Pi 4B GPIO pins

AM2320 - Type - RPI pin
Pin 1 - 3.3v - Pin 1
Pin 2 - SDA - GPIO (SDA) Pin 3
Pin 3 - gnd - Pin 6
Pin 4 - SCL - GPIO (SCL) pin 5

## Software instalation

```
poetry add adafruit-circuitpython-am2320
```
14 changes: 14 additions & 0 deletions standalone_modules/shedpi_module_am2320/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[tool.poetry]
name = "shedpi-module-am2320"
version = "0.1.0"
description = ""
authors = ["Andrew Aikman <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.11"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import time

import adafruit_am2320
import board
from shed_pi_module_utils.data_submission import (
ReadingSubmissionService,
)
from shed_pi_module_utils.utils import logger

# create the I2C shared bus
i2c = board.I2C() # uses board.SCL and board.SDA
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
am = adafruit_am2320.AM2320(i2c)

while True:
print("Temperature: ", am.temperature)
print("Humidity: ", am.relative_humidity)
time.sleep(2)


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.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from shedpi_components.AM2302 import AM2320
from shedpi_module_utils.shedpi_components import AM2320


@patch("shedpi_components.AM2302.posix")
Expand All @@ -28,4 +28,4 @@ def test_probe_reading_happy_path(mocked_posix, mocked_ioctl):
# )

mocked_posix.read = Mock(return_value="0000000")
reading = probe.read_sensor()
probe.read_sensor()
Loading

0 comments on commit c1f3be6

Please sign in to comment.