Skip to content

Commit

Permalink
Improve more annotations.
Browse files Browse the repository at this point in the history
  • Loading branch information
denpamusic committed Oct 13, 2023
1 parent 5b881fe commit 5891717
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion pyplumio/devices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions pyplumio/devices/ecomax.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -412,15 +412,15 @@ 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:
"""Turn off the ecoMAX controller."""
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:
Expand Down
18 changes: 9 additions & 9 deletions pyplumio/frames/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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,
Expand Down
68 changes: 34 additions & 34 deletions pyplumio/helpers/data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,25 @@ 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):
"""Represents an undefined zero-byte."""

@property
def value(self) -> None:
"""Data value."""
"""A data value."""
return None

@property
def size(self) -> int:
"""Data length."""
"""A data length."""
return 0


Expand All @@ -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


Expand All @@ -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


Expand All @@ -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


Expand All @@ -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


Expand All @@ -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


Expand All @@ -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


Expand All @@ -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


Expand All @@ -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


Expand All @@ -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


Expand All @@ -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


Expand All @@ -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


Expand All @@ -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


Expand All @@ -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


Expand All @@ -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


Expand All @@ -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:
Expand All @@ -295,7 +295,7 @@ def value(self) -> str:

@property
def size(self) -> int:
"""Data length."""
"""A data length."""
return len(self.value) + 1


Expand Down
4 changes: 2 additions & 2 deletions pyplumio/helpers/event_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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."""
Expand Down
Loading

0 comments on commit 5891717

Please sign in to comment.