Skip to content

Commit 15f8e49

Browse files
arhowe00ebrahimebrahim
authored andcommitted
Pack LIFUInterface status into enum (OpenwaterHealth#228)
- Part of storing statuses into the enums, this handles it for LIFUInterface statuses
1 parent 67680bc commit 15f8e49

3 files changed

Lines changed: 19 additions & 15 deletions

File tree

src/openlifu/io/LIFUInterface.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import asyncio
44
import logging
5+
from enum import Enum
56
from typing import Dict
67

78
from openlifu.io.LIFUHVController import HVController
@@ -10,16 +11,18 @@
1011
from openlifu.io.LIFUUart import LIFUUart
1112
from openlifu.plan.solution import Solution
1213

13-
STATUS_COMMS_ERROR = -1
14-
STATUS_SYS_OFF = 0
15-
STATUS_SYS_POWERUP = 1
16-
STATUS_SYS_ON = 2
17-
STATUS_PROGRAMMING = 3
18-
STATUS_READY = 4
19-
STATUS_NOT_READY = 5
20-
STATUS_RUNNING = 6
21-
STATUS_FINISHED = 7
22-
STATUS_ERROR = 8
14+
15+
class LIFUInterfaceStatus(Enum):
16+
STATUS_COMMS_ERROR = -1
17+
STATUS_SYS_OFF = 0
18+
STATUS_SYS_POWERUP = 1
19+
STATUS_SYS_ON = 2
20+
STATUS_PROGRAMMING = 3
21+
STATUS_READY = 4
22+
STATUS_NOT_READY = 5
23+
STATUS_RUNNING = 6
24+
STATUS_FINISHED = 7
25+
STATUS_ERROR = 8
2326

2427
logger = logging.getLogger(__name__)
2528

@@ -183,9 +186,9 @@ def get_status(self):
183186
int: The device status.
184187
"""
185188
if self._test_mode:
186-
return STATUS_READY
189+
return LIFUInterfaceStatus.STATUS_READY
187190

188-
status = STATUS_ERROR
191+
status = LIFUInterfaceStatus.STATUS_ERROR
189192
return status
190193

191194
def stop_sonication(self) -> bool:

src/openlifu/io/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from openlifu.io.LIFUInterface import LIFUInterface
1+
from openlifu.io.LIFUInterface import LIFUInterface, LIFUInterfaceStatus
22

33
__all__ = [
44
"LIFUInterface",
5+
"LIFUInterfaceStatus",
56
]

tests/test_sonication_control_mock.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from openlifu.bf import Pulse, Sequence
55
from openlifu.geo import Point
6-
from openlifu.io.LIFUInterface import STATUS_READY, LIFUInterface
6+
from openlifu.io.LIFUInterface import LIFUInterface, LIFUInterfaceStatus
77
from openlifu.plan.solution import Solution
88

99

@@ -36,5 +36,5 @@ def test_lifuinterface_mock(example_solution:Solution):
3636
lifu_interface.set_solution(example_solution)
3737
lifu_interface.start_sonication()
3838
status = lifu_interface.get_status()
39-
assert status == STATUS_READY
39+
assert status == LIFUInterfaceStatus.STATUS_READY
4040
lifu_interface.stop_sonication()

0 commit comments

Comments
 (0)