|
45 | 45 | based on their preference. |
46 | 46 | """ |
47 | 47 | # pylint: disable=missing-type-doc |
48 | | -from pymodbus.exceptions import NotImplementedException, ParameterException |
| 48 | +from abc import ABC, abstractmethod |
| 49 | +from typing import Iterable |
| 50 | + |
| 51 | +from pymodbus.exceptions import ParameterException |
49 | 52 |
|
50 | 53 |
|
51 | 54 | # ---------------------------------------------------------------------------# |
52 | 55 | # Datablock Storage |
53 | 56 | # ---------------------------------------------------------------------------# |
54 | | -class BaseModbusDataBlock: |
| 57 | +class BaseModbusDataBlock(ABC): |
55 | 58 | """Base class for a modbus datastore. |
56 | 59 |
|
57 | 60 | Derived classes must create the following fields: |
@@ -83,32 +86,32 @@ def reset(self): |
83 | 86 | self.default_value |
84 | 87 | ] * len(self.values) |
85 | 88 |
|
86 | | - def validate(self, address, count=1): |
| 89 | + @abstractmethod |
| 90 | + def validate(self, address:int, count=1) -> bool: |
87 | 91 | """Check to see if the request is in range. |
88 | 92 |
|
89 | 93 | :param address: The starting address |
90 | 94 | :param count: The number of values to test for |
91 | | - :raises NotImplementedException: |
| 95 | + :raises TypeError: |
92 | 96 | """ |
93 | | - raise NotImplementedException("Datastore Address Check") |
94 | 97 |
|
95 | | - def getValues(self, address, count=1): |
| 98 | + @abstractmethod |
| 99 | + def getValues(self, address:int, count=1) -> Iterable: |
96 | 100 | """Return the requested values from the datastore. |
97 | 101 |
|
98 | 102 | :param address: The starting address |
99 | 103 | :param count: The number of values to retrieve |
100 | | - :raises NotImplementedException: |
| 104 | + :raises TypeError: |
101 | 105 | """ |
102 | | - raise NotImplementedException("Datastore Value Retrieve") |
103 | 106 |
|
104 | | - def setValues(self, address, values): |
| 107 | + @abstractmethod |
| 108 | + def setValues(self, address:int, values) -> None: |
105 | 109 | """Return the requested values from the datastore. |
106 | 110 |
|
107 | 111 | :param address: The starting address |
108 | 112 | :param values: The values to store |
109 | | - :raises NotImplementedException: |
| 113 | + :raises TypeError: |
110 | 114 | """ |
111 | | - raise NotImplementedException("Datastore Value Retrieve") |
112 | 115 |
|
113 | 116 | def __str__(self): |
114 | 117 | """Build a representation of the datastore. |
|
0 commit comments