From 5891717d952ea14ecc6b0c0ba756ddf9ddde1ae4 Mon Sep 17 00:00:00 2001 From: denpamusic Date: Sat, 14 Oct 2023 02:36:20 +0300 Subject: [PATCH] Improve more annotations. --- pyplumio/devices/__init__.py | 2 +- pyplumio/devices/ecomax.py | 12 +++--- pyplumio/frames/__init__.py | 18 ++++---- pyplumio/helpers/data_types.py | 68 +++++++++++++++---------------- pyplumio/helpers/event_manager.py | 4 +- pyplumio/helpers/parameter.py | 8 ++-- pyplumio/helpers/uid.py | 4 +- 7 files changed, 58 insertions(+), 58 deletions(-) diff --git a/pyplumio/devices/__init__.py b/pyplumio/devices/__init__.py index e7f92d6d..f737a59f 100644 --- a/pyplumio/devices/__init__.py +++ b/pyplumio/devices/__init__.py @@ -28,7 +28,7 @@ def _handler_class_path(device_type_name: str) -> str: # Dictionary of device handler classes indexed by device types. # -# example: "69: ecomax.EcoMAX" +# Example: "69: ecomax.EcoMAX" DEVICE_TYPES: dict[int, str] = { device_type.value: _handler_class_path(device_type.name) for device_type in DeviceType diff --git a/pyplumio/devices/ecomax.py b/pyplumio/devices/ecomax.py index 62c06373..5f38dd91 100644 --- a/pyplumio/devices/ecomax.py +++ b/pyplumio/devices/ecomax.py @@ -199,8 +199,8 @@ def _thermostats(self, indexes: Iterable[int]) -> Generator[Thermostat, None, No async def _handle_ecomax_sensors(self, sensors: EventDataType) -> bool: """Handle ecoMAX sensors. - For each sensor dispatch an event with the - sensor's name and value. + For each sensor dispatch an event with the sensor's name and + value. """ for name, value in sensors.items(): await self.dispatch(name, value) @@ -212,8 +212,8 @@ async def _handle_ecomax_parameters( ) -> bool: """Handle ecoMAX parameters. - For each parameter dispatch an event with the - parameter's name and value. + For each parameter dispatch an event with the parameter's name + and value. """ product = await self.get(ATTR_PRODUCT) for index, value in parameters: @@ -412,7 +412,7 @@ async def turn_on(self) -> bool: try: return await self.data[ATTR_ECOMAX_CONTROL].turn_on() except KeyError: - _LOGGER.error("ecoMAX control is not available, please try later") + _LOGGER.error("ecoMAX control isn't available, please try later") return False async def turn_off(self) -> bool: @@ -420,7 +420,7 @@ async def turn_off(self) -> bool: try: return await self.data[ATTR_ECOMAX_CONTROL].turn_off() except KeyError: - _LOGGER.error("ecoMAX control is not available, please try later") + _LOGGER.error("ecoMAX control isn't available, please try later") return False def turn_on_nowait(self) -> None: diff --git a/pyplumio/frames/__init__.py b/pyplumio/frames/__init__.py index 50eae91d..c3c97aaa 100644 --- a/pyplumio/frames/__init__.py +++ b/pyplumio/frames/__init__.py @@ -22,8 +22,8 @@ def _handler_class_path(frame_type_name: str) -> str: - """Return handler class path from module name and - frame type name. + """Return handler class path from module name and frame type + name. """ module, type_name = frame_type_name.split("_", 1) type_name = util.to_camelcase(type_name, overrides={"uid": "UID"}) @@ -32,7 +32,7 @@ def _handler_class_path(frame_type_name: str) -> str: # Dictionary of frame handler classes indexed by frame types. # -# example: "24: requests.StopMasterRequest" +# Example: "24: requests.StopMasterRequest" FRAME_TYPES: dict[int, str] = { frame_type.value: _handler_class_path(frame_type.name) for frame_type in FrameType } @@ -66,7 +66,7 @@ class DataFrameDescription: @dataclass class FrameDataClass: - """Data class mixin for the frame.""" + """Represents a frame data class mixin.""" recipient: int = DeviceType.ALL sender: int = DeviceType.ECONET @@ -104,20 +104,20 @@ def __init__(self, *args, **kwargs): self.data = self.decode_message(self.message) def __len__(self) -> int: - """Return frame length.""" + """Return a frame length.""" return self.length def hex(self, *args, **kwargs) -> str: - """Return frame message represented as hex string.""" + """Return a frame message represented as hex string.""" return self.bytes.hex(*args, **kwargs) @abstractmethod def create_message(self, data: EventDataType) -> bytearray: - """Create frame message.""" + """Create a frame message.""" @abstractmethod def decode_message(self, message: bytearray) -> EventDataType: - """Decode frame message.""" + """Decode a frame message.""" @property def length(self) -> int: @@ -132,7 +132,7 @@ def length(self) -> int: @property def header(self) -> bytearray: - """Frame header.""" + """A frame header.""" buffer = bytearray(HEADER_SIZE) util.pack_header( buffer, diff --git a/pyplumio/helpers/data_types.py b/pyplumio/helpers/data_types.py index 5a8d756e..c41e1506 100644 --- a/pyplumio/helpers/data_types.py +++ b/pyplumio/helpers/data_types.py @@ -35,12 +35,12 @@ def unpack(self, data: bytes): @property @abstractmethod def value(self): - """Data value.""" + """A data value.""" @property @abstractmethod def size(self) -> int: - """Data length.""" + """A data length.""" class Undefined0(DataType): @@ -48,12 +48,12 @@ class Undefined0(DataType): @property def value(self) -> None: - """Data value.""" + """A data value.""" return None @property def size(self) -> int: - """Data length.""" + """A data length.""" return 0 @@ -62,12 +62,12 @@ class SignedChar(DataType): @property def value(self) -> int: - """Data value.""" + """A data value.""" return util.unpack_char(self._data)[0] @property def size(self) -> int: - """Data length.""" + """A data length.""" return 1 @@ -76,12 +76,12 @@ class Short(DataType): @property def value(self) -> int: - """Data value.""" + """A data value.""" return util.unpack_short(self._data)[0] @property def size(self) -> int: - """Data length.""" + """A data length.""" return 2 @@ -90,12 +90,12 @@ class Int(DataType): @property def value(self) -> int: - """Data value.""" + """A data value.""" return util.unpack_int(self._data)[0] @property def size(self) -> int: - """Data length.""" + """A data length.""" return 4 @@ -104,12 +104,12 @@ class Byte(DataType): @property def value(self) -> int: - """Data value.""" + """A data value.""" return ord(self._data) @property def size(self) -> int: - """Data length.""" + """A data length.""" return 1 @@ -118,12 +118,12 @@ class UnsignedShort(DataType): @property def value(self) -> int: - """Data value.""" + """A data value.""" return util.unpack_ushort(self._data) @property def size(self) -> int: - """Data length.""" + """A data length.""" return 2 @@ -132,12 +132,12 @@ class UnsignedInt(DataType): @property def value(self) -> int: - """Data value.""" + """A data value.""" return util.unpack_uint(self._data)[0] @property def size(self) -> int: - """Data length.""" + """A data length.""" return 4 @@ -146,12 +146,12 @@ class Float(DataType): @property def value(self) -> float: - """Data value.""" + """A data value.""" return util.unpack_float(self._data)[0] @property def size(self) -> int: - """Data length.""" + """A data length.""" return 4 @@ -160,12 +160,12 @@ class Undefined8(DataType): @property def value(self) -> None: - """Data value.""" + """A data value.""" return None @property def size(self) -> int: - """Data length.""" + """A data length.""" return 0 @@ -174,12 +174,12 @@ class Double(DataType): @property def value(self) -> float: - """Data value.""" + """A data value.""" return util.unpack_double(self._data)[0] @property def size(self) -> int: - """Data length.""" + """A data length.""" return 8 @@ -204,12 +204,12 @@ def unpack(self, data: bytes) -> None: @property def value(self) -> bool: - """Data value.""" + """A data value.""" return bool(ord(self._data) & (1 << self._index)) @property def size(self) -> int: - """Data length.""" + """A data length.""" return 1 if self._index == 7 else 0 @@ -218,12 +218,12 @@ class Int64(DataType): @property def value(self) -> int: - """Data value.""" + """A data value.""" return util.unpack_int64(self._data)[0] @property def size(self) -> int: - """Data length.""" + """A data length.""" return 8 @@ -232,12 +232,12 @@ class UInt64(DataType): @property def value(self) -> int: - """Data value.""" + """A data value.""" return util.unpack_uint64(self._data)[0] @property def size(self) -> int: - """Data length.""" + """A data length.""" return 8 @@ -246,12 +246,12 @@ class IPv4(DataType): @property def value(self) -> str: - """Data value.""" + """A data value.""" return util.ip4_from_bytes(self._data) @property def size(self) -> int: - """Data length.""" + """A data length.""" return 4 @@ -260,12 +260,12 @@ class IPv6(DataType): @property def value(self) -> str: - """Data value.""" + """A data value.""" return util.ip6_from_bytes(self._data) @property def size(self) -> int: - """Data length.""" + """A data length.""" return 16 @@ -283,7 +283,7 @@ def unpack(self, data: bytes): @property def value(self) -> str: - """Data value.""" + """A data value.""" value = "" offset = 0 if offset in self._data: @@ -295,7 +295,7 @@ def value(self) -> str: @property def size(self) -> int: - """Data length.""" + """A data length.""" return len(self.value) + 1 diff --git a/pyplumio/helpers/event_manager.py b/pyplumio/helpers/event_manager.py index 63706697..ad719817 100644 --- a/pyplumio/helpers/event_manager.py +++ b/pyplumio/helpers/event_manager.py @@ -15,7 +15,7 @@ class EventManager(TaskManager): _callbacks: dict[str | int, list[EventCallbackType]] def __init__(self): - """Initialize new event manager.""" + """Initialize a new event manager.""" super().__init__() self.data = {} self._events = {} @@ -85,7 +85,7 @@ def dispatch_nowait(self, name: str | int, value) -> None: self.create_task(self.dispatch(name, value)) def load(self, data: EventDataType) -> None: - """Load event data.""" + """Load an event data.""" async def _dispatch_events(data: EventDataType) -> None: """Dispatch events for a loaded data.""" diff --git a/pyplumio/helpers/parameter.py b/pyplumio/helpers/parameter.py index e407f482..0b9a8b5f 100644 --- a/pyplumio/helpers/parameter.py +++ b/pyplumio/helpers/parameter.py @@ -20,7 +20,7 @@ def _normalize_parameter_value(value: ParameterValueType) -> int: - """Normalizes parameter value to an integer.""" + """Normalize a parameter value to an integer.""" if isinstance(value, str): return 1 if value == STATE_ON else 0 @@ -69,7 +69,7 @@ def __init__( self._index = index def __repr__(self) -> str: - """Return serializable string representation.""" + """Return a serializable string representation.""" return ( self.__class__.__name__ + f"(device={self.device.__class__.__name__}, " @@ -78,12 +78,12 @@ def __repr__(self) -> str: ) def _call_relational_method(self, method_to_call, other): - """Call specified relational method.""" + """Call a specified relational method.""" func = getattr(self._value, method_to_call) return func(_normalize_parameter_value(other)) def __int__(self) -> int: - """Return integer representation of parameter's value.""" + """Return an integer representation of parameter's value.""" return self._value def __add__(self, other) -> int: diff --git a/pyplumio/helpers/uid.py b/pyplumio/helpers/uid.py index 72939495..b47a4234 100644 --- a/pyplumio/helpers/uid.py +++ b/pyplumio/helpers/uid.py @@ -3,7 +3,7 @@ def unpack_uid(message: bytearray, offset: int = 0) -> str: - """Decode and return complete UID string.""" + """Decode and return a complete UID string.""" uid_length = message[offset] offset += 1 uid = message[offset : uid_length + offset] @@ -12,7 +12,7 @@ def unpack_uid(message: bytearray, offset: int = 0) -> str: def _encode_base5(data: bytes) -> str: - """Encode bytes to base5 encoded string.""" + """Encode bytes to a base5 encoded string.""" key_string = "0123456789ABCDEFGHIJKLMNZPQRSTUV" number = int.from_bytes(data, "little") output: str = ""