klaasnicolaas/python-omnikinverter

View on GitHub
src/omnikinverter/tcp.py

Summary

Maintainability
B
5 hrs
Test Coverage

File tcp.py has 258 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""Data model and conversions for tcp-based communication with the Omnik Inverter."""

from __future__ import annotations

from ctypes import BigEndianStructure, c_char, c_ubyte, c_uint, c_ushort, sizeof
Severity: Minor
Found in src/omnikinverter/tcp.py - About 2 hrs to fix

    Function parse has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

        def parse(cls, data: bytes, offset: int = 0) -> dict[str, Any]:
            """Parse `data` into all fields described by this C structure."""
            tcp_data = cls.from_buffer_copy(data, offset)
    
            if tcp_data.unknown0 not in [0, UINT16_MAX]:  # pragma: no cover
    Severity: Minor
    Found in src/omnikinverter/tcp.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _unpack_messages has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def _unpack_messages(
        data: bytearray,
    ) -> Generator[tuple[int, int, bytearray], None, None]:
        while len(data):
            message_start = data.pop(0)
    Severity: Minor
    Found in src/omnikinverter/tcp.py - About 55 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    There are no issues that match your filters.

    Category
    Status