use Enum class for State

This commit is contained in:
Stefan Allius
2024-06-16 17:50:09 +02:00
parent f5e7aa4292
commit e0568291f6
5 changed files with 51 additions and 46 deletions

View File

@@ -1,6 +1,7 @@
import logging
import weakref
from typing import Callable, Generator
from enum import Enum
if __name__ == "app.src.messages":
@@ -52,11 +53,14 @@ class IterRegistry(type):
yield obj
class State(Enum):
init = 0
up = 2
closed = 3
class Message(metaclass=IterRegistry):
_registry = []
STATE_INIT = 0
STATE_UP = 2
STATE_CLOSED = 3
def __init__(self, server_side: bool, send_modbus_cb:
Callable[[bytes, int, str], None], mb_timeout: int):
@@ -78,7 +82,7 @@ class Message(metaclass=IterRegistry):
self._send_buffer = bytearray(0)
self._forward_buffer = bytearray(0)
self.new_data = {}
self.state = self.STATE_INIT
self.state = State.init
'''
Empty methods, that have to be implemented in any child class which