Skip to content

Commit

Permalink
Extracted Shedpi module utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiky30 committed Dec 8, 2024
1 parent c1f3be6 commit 67cebaa
Show file tree
Hide file tree
Showing 20 changed files with 29 additions and 253 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ tomli==2.0.1
typing_extensions==4.7.1
urllib3==2.2.1
virtualenv==20.25.0
shed-pi-module-utils==0.1.2
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from shed_pi_module_utils.data_submission import (
ReadingSubmissionService,
)
from shed_pi_module_utils.shed_pi_components.ds18b20 import (
TempProbe,
)

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


@patch("standalone_modules.temperature_module.temperature_probe.Path")
Expand All @@ -33,7 +33,7 @@ def test_temperature_module_reading_submission(mocked_path, live_server):
# Override the serviuce url
submission_service.base_url = live_server.url

probe = TempProbe(submission_service=submission_service)
probe = TempProbe()
# Override the module id
probe.device_id = device_module.id

Expand Down
Empty file removed shedpi_module_utils/README.md
Empty file.
Empty file removed shedpi_module_utils/__init__.py
Empty file.
14 changes: 0 additions & 14 deletions shedpi_module_utils/pyproject.toml

This file was deleted.

Empty file.
58 changes: 0 additions & 58 deletions shedpi_module_utils/shedpi_components/ds18b20.py

This file was deleted.

Empty file.
38 changes: 0 additions & 38 deletions shedpi_module_utils/shedpi_module_utils/base_protocol.py

This file was deleted.

36 changes: 0 additions & 36 deletions shedpi_module_utils/shedpi_module_utils/data_submission.py

This file was deleted.

26 changes: 0 additions & 26 deletions shedpi_module_utils/shedpi_module_utils/utils.py

This file was deleted.

Empty file.
Empty file.

This file was deleted.

Empty file.
31 changes: 0 additions & 31 deletions shedpi_module_utils/tests/utils.py

This file was deleted.

2 changes: 1 addition & 1 deletion standalone_modules/rpi/device_protocol.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import time

from shed_pi_module_utils import BaseProtocol
from shed_pi_module_utils.base_protocol import BaseProtocol
from shed_pi_module_utils.data_submission import (
ReadingSubmissionService,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import time

from shed_pi_module_utils import BaseProtocol
from shed_pi_module_utils.base_protocol import BaseProtocol
from shed_pi_module_utils.data_submission import (
ReadingSubmissionService,
)
from shed_pi_module_utils.shed_pi_components.ds18b20 import TempProbe
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,8 +1,7 @@
from unittest.mock import Mock, patch

import pytest

from shedpi_module_utils.shedpi_components import AM2320
from shed_pi_module_utils.shedpi_components import AM2320


@patch("shedpi_components.AM2302.posix")
Expand Down
21 changes: 20 additions & 1 deletion standalone_modules/temperature_module/device_protocol.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import time

import requests
from shed_pi_module_utils import BaseProtocol
from shed_pi_module_utils.data_submission import (
ReadingSubmissionService,
)
from shed_pi_module_utils.utils import check_arch_is_arm, logger

from shedpi_module_utils.shedpi_components.ds18b20 import TempProbe

TIME_TO_SLEEP = 60 # time in seconds
Expand All @@ -16,10 +16,29 @@ def __init__(self, submission_service: ReadingSubmissionService):
# Installed modules
self.temp_probe = TempProbe(submission_service=submission_service)
self.submission_delay = TIME_TO_SLEEP
self.submission_service = submission_service
self.device_id: int = None

def stop(self):
return False

def submit_reading(self) -> requests.Response:
"""
Submits a reading to an external endpoint
:return:
"""
probe_1_temp = self.temp_probe.read_temp()

# FIXME: Should this be a float or a string? Broke the test
data = {"temperature": str(probe_1_temp)}

response = self.submission_service.submit(
device_module_id=self.device_id, data=data
)

return response

def run(self):
while not self.stop():
self.temp_probe.submit_reading()
Expand Down

0 comments on commit 67cebaa

Please sign in to comment.