2 files changed
+46
No files matched your search
@@ -0,0 +1,22 @@
|
||||
name: Unittests
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
# Allows you to run this workflow manually from the Actions tab
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v3
|
||||
with:
|
||||
python-version: '3.x'
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
- name: Run unittests
|
||||
run: python3 -m unittest discover -s tests -p "*_test.py"
|
||||
@@ -0,0 +1,24 @@
|
||||
"""Unittest for device struct."""
|
||||
|
||||
import unittest
|
||||
|
||||
from custom_components.bluetti_bt.bluetti_bt_lib.utils.commands import ReadHoldingRegisters
|
||||
from custom_components.bluetti_bt.bluetti_bt_lib.utils.struct import DeviceStruct
|
||||
|
||||
class TestDeviceStruct(unittest.TestCase):
|
||||
def test_get_read_holding_registers(self):
|
||||
struct = DeviceStruct()
|
||||
|
||||
struct.add_swap_string_field("device_type", 110, 6)
|
||||
struct.add_sn_field("serial_number", 116)
|
||||
struct.add_decimal_field(
|
||||
"power_generation", 154, 1
|
||||
)
|
||||
struct.add_uint_field("total_battery_percent", 102)
|
||||
|
||||
registers = struct.get_read_holding_registers()
|
||||
|
||||
self.assertGreater(len(registers), 0)
|
||||
|
||||
for reg in registers:
|
||||
self.assertIsInstance(reg, ReadHoldingRegisters)
|
||||
Reference in new issue
Block a user