Skip to content

Commit a379704

Browse files
Temperature and humidity attributes now added for actuator battery status (#202)
* Temperature and humidity fields now added for battery status * Replaced flake8 with Ruff in pre-commit hooks * Fixed logging format * Handle absence of temperature and humidity from battery monitor * Moved from conda to venv to fix setuptools dependency issue
1 parent f4a1c25 commit a379704

File tree

9 files changed

+54
-28
lines changed

9 files changed

+54
-28
lines changed

.github/workflows/test.yaml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,28 @@ on:
1111
jobs:
1212
build:
1313
runs-on: ubuntu-latest
14-
defaults:
15-
run:
16-
shell: bash -el {0}
1714
steps:
1815
- uses: actions/checkout@v3
1916
- name: Set up Python 3.10
2017
uses: actions/setup-python@v3
2118
with:
2219
python-version: "3.10"
23-
- name: Install conda
24-
uses: conda-incubator/setup-miniconda@v3
25-
with:
26-
activate-environment: WADAS
27-
environment-file: wadas/conda_env_setup.yml
28-
auto-activate-base: false
29-
- run: |
30-
conda info
31-
conda list
20+
- name: Install system dependencies
21+
run: sudo apt-get install -y libmariadb-dev
22+
- name: Create venv and install dependencies
23+
run: |
24+
python -m venv .venv
25+
source .venv/bin/activate
26+
pip install --upgrade pip
27+
pip install -r requirements.txt
3228
- name: Login to Hugging Face
3329
run: |
34-
hf auth login --token ${{ secrets.WADAS_OFFICIAL_HUGGINGF_AUTH }} --add-to-git-credential
30+
source .venv/bin/activate
31+
pip install huggingface_hub[cli]
32+
huggingface-cli login --token ${{ secrets.WADAS_OFFICIAL_HUGGINGF_AUTH }}
3533
- name: Run tests
3634
run: |
35+
source .venv/bin/activate
3736
python -m pytest test -sv --cov=. --cov-report=html
3837
# To enforce minimum coverage, uncomment the following line:
3938
# python -m pytest test -sv --cov=. --cov-report=html --cov-fail-under=80

.pre-commit-config.yaml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,12 @@ repos:
2323
rev: v1.0.0
2424
hooks:
2525
- id: check-json5
26-
- repo: https://github.com/PyCQA/flake8
27-
rev: 7.1.1
28-
hooks:
29-
- id: flake8
30-
additional_dependencies: [
31-
'flake8-blind-except',
32-
'flake8-bugbear',
33-
'flake8-comprehensions',
34-
'flake8-implicit-str-concat',
35-
'flake8-logging-format',
36-
'pydocstyle>=5.0.0',
37-
]
38-
exclude: ^wadas/ui/.*|demo/.*
26+
- repo: https://github.com/astral-sh/ruff-pre-commit
27+
rev: v0.3.5
28+
hooks:
29+
- id: ruff
30+
args: [--no-fix]
31+
exclude: ^wadas/ui/.*|demo/.*
3932
- repo: https://github.com/pycqa/isort
4033
rev: 5.13.2
4134
hooks:

requirements.txt

32 Bytes
Binary file not shown.

wadas/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
# Date: 2024-08-14
1818
# Description: module to keep track of WADAS version
1919

20-
__version__ = "v1.0.0.a5"
20+
__version__ = "v1.0.0.a6"
2121
__dbversion__ = __version__

wadas/conda_env_setup.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ dependencies:
2929
- openssl=3.4.0
3030
- cryptography=42.0.8
3131
- pyopenssl=24.2.1
32+
- setuptools>=65
3233
- pip:
3334
- cv2-enumerate-cameras==1.1.15
3435
- intel-npu-acceleration-library==1.4.0
@@ -42,3 +43,4 @@ dependencies:
4243
- wadas-runtime==0.2.6
4344
- opencv-python==4.10.0.84
4445
- shapely==2.0.7
46+
- setuptools>=65

wadas/domain/actuator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ def from_json(cls, s: str) -> "Command":
7676
class ActuatorBatteryStatus:
7777
actuator_id: str
7878
voltage: float
79+
temperature: float
80+
humidity: float
7981
time_stamp: datetime.datetime = field(default_factory=datetime.datetime.now)
8082

8183
def to_json(self) -> str:
@@ -84,6 +86,8 @@ def to_json(self) -> str:
8486
"actuator_id": self.actuator_id,
8587
"voltage": self.voltage,
8688
"time_stamp": self.time_stamp.isoformat(),
89+
"temperature": self.temperature,
90+
"humidity": self.humidity,
8791
}
8892
)
8993

wadas/domain/actuator_server_app.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ async def receive_battery_status(actuator_id: str, payload: dict = Body(...)):
193193
if voltage is None:
194194
raise HTTPException(status_code=400, detail="Missing 'volt' in payload")
195195

196+
# We accept the possibility that temperature or humidity are null if sensor is not plugged
197+
temperature = payload.get("payload", {}).get("temperature")
198+
humidity = payload.get("payload", {}).get("humidity")
199+
196200
# Timestamp set by server
197201
ts = datetime.datetime.now()
198202

@@ -201,9 +205,21 @@ async def receive_battery_status(actuator_id: str, payload: dict = Body(...)):
201205
actuator_id=actuator_id,
202206
voltage=voltage,
203207
time_stamp=ts,
208+
temperature=temperature,
209+
humidity=humidity,
204210
)
205211
actuator.battery_status = battery_status
206-
logger.info("Received actuator %s battery status: %s", actuator_id, voltage)
212+
213+
if temperature and humidity:
214+
logger.info(
215+
"Received actuator %s battery status: %s V, temperature: %s °, humidity: %s %%",
216+
actuator_id,
217+
voltage,
218+
temperature,
219+
humidity,
220+
)
221+
else:
222+
logger.info("Received actuator %s battery status: %s V.", actuator_id, voltage)
207223

208224
# Persist in DB
209225
if db := DataBase.get_enabled_db():

wadas/domain/database.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,14 @@ def update_db_version(self):
499499
"""
500500
)
501501
)
502+
elif cur_db_version <= "v1.0.0.a5":
503+
DataBase.run_query(
504+
text("ALTER TABLE actuator_battery_status ADD COLUMN temperature FLOAT NULL;")
505+
)
506+
DataBase.run_query(
507+
text("ALTER TABLE actuator_battery_status ADD COLUMN humidity FLOAT NULL;")
508+
)
509+
502510
DataBase.run_query(text(f"UPDATE db_metadata SET version='{__dbversion__}';"))
503511
logger.info("Database updated from %s to %s", cur_db_version, __dbversion__)
504512
except Exception:
@@ -950,6 +958,8 @@ def domain_to_orm(domain_object, foreign_key=None):
950958
actuator_id=foreign_key[0],
951959
time_stamp=domain_object.time_stamp,
952960
voltage=domain_object.voltage,
961+
temperature=domain_object.temperature,
962+
humidity=domain_object.humidity,
953963
)
954964
elif isinstance(domain_object, ActuatorTemperatureStatus):
955965
return ORMActuatorTemperature(

wadas/domain/db_model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ class ActuatorBatteryStatus(Base):
208208
actuator_id = Column(Integer, ForeignKey("actuators.id"), primary_key=True, nullable=False)
209209
time_stamp = Column(MySQLDATETIME6(timezone=True), primary_key=True, nullable=False)
210210
voltage = Column(Float)
211+
temperature = Column(Float, nullable=True)
212+
humidity = Column(Float, nullable=True)
211213

212214

213215
class ActuatorTemperatureStatus(Base):

0 commit comments

Comments
 (0)