Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions plugwise_usb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from collections.abc import Callable, Coroutine
from functools import wraps
import logging
from typing import Any, TypeVar, cast
from typing import Any, TypeVar, cast, Final

from .api import NodeEvent, PlugwiseNode, StickEvent
from .connection import StickController
Expand All @@ -19,7 +19,7 @@

FuncT = TypeVar("FuncT", bound=Callable[..., Any])


NOT_INITIALIZED_STICK_ERROR: Final[StickError] = StickError("Cannot load nodes when network is not initialized")
_LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -319,9 +319,7 @@
async def load_nodes(self) -> bool:
"""Load all discovered nodes."""
if self._network is None:
raise StickError(
"Cannot load nodes when network is not initialized"
)
raise NOT_INITIALIZED_STICK_ERROR

Check warning on line 322 in plugwise_usb/__init__.py

View check run for this annotation

Codecov / codecov/patch

plugwise_usb/__init__.py#L322

Added line #L322 was not covered by tests
if not self._network.is_running:
raise StickError(
"Cannot load nodes when network is not started"
Expand All @@ -333,19 +331,15 @@
async def discover_coordinator(self, load: bool = False) -> None:
"""Discover the network coordinator."""
if self._network is None:
raise StickError(
"Cannot load nodes when network is not initialized"
)
raise NOT_INITIALIZED_STICK_ERROR

Check warning on line 334 in plugwise_usb/__init__.py

View check run for this annotation

Codecov / codecov/patch

plugwise_usb/__init__.py#L334

Added line #L334 was not covered by tests
await self._network.discover_network_coordinator(load=load)

@raise_not_connected
@raise_not_initialized
async def discover_nodes(self, load: bool = False) -> None:
"""Discover all nodes."""
if self._network is None:
raise StickError(
"Cannot load nodes when network is not initialized"
)
raise NOT_INITIALIZED_STICK_ERROR

Check warning on line 342 in plugwise_usb/__init__.py

View check run for this annotation

Codecov / codecov/patch

plugwise_usb/__init__.py#L342

Added line #L342 was not covered by tests
await self._network.discover_nodes(load=load)

@raise_not_connected
Expand Down
31 changes: 16 additions & 15 deletions plugwise_usb/messages/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import binascii
from datetime import UTC, date, datetime, time, timedelta
import struct
from typing import Any
from typing import Any, Final

from ..constants import LOGADDR_OFFSET, PLUGWISE_EPOCH, UTF8
from ..exceptions import MessageError
from ..helpers.util import int_to_uint

DESERIALIZE_ERROR: Final[MessageError] = MessageError("Unable to return value. Deserialize data first")

class BaseType:
"""Generic single instance property."""
Expand Down Expand Up @@ -72,7 +73,7 @@
def value(self) -> bytes:
"""Return bytes value."""
if self._value is None:
raise MessageError("Unable to return value. Deserialize data first")
raise DESERIALIZE_ERROR

Check warning on line 76 in plugwise_usb/messages/properties.py

View check run for this annotation

Codecov / codecov/patch

plugwise_usb/messages/properties.py#L76

Added line #L76 was not covered by tests
return self._value


Expand All @@ -92,7 +93,7 @@
def value(self) -> str:
"""Return converted int value."""
if self._value is None:
raise MessageError("Unable to return value. Deserialize data first")
raise DESERIALIZE_ERROR

Check warning on line 96 in plugwise_usb/messages/properties.py

View check run for this annotation

Codecov / codecov/patch

plugwise_usb/messages/properties.py#L96

Added line #L96 was not covered by tests
return self._value


Expand Down Expand Up @@ -121,7 +122,7 @@
def value(self) -> int:
"""Return converted int value."""
if self._value is None:
raise MessageError("Unable to return value. Deserialize data first")
raise DESERIALIZE_ERROR

Check warning on line 125 in plugwise_usb/messages/properties.py

View check run for this annotation

Codecov / codecov/patch

plugwise_usb/messages/properties.py#L125

Added line #L125 was not covered by tests
return self._value


Expand Down Expand Up @@ -155,7 +156,7 @@
def value(self) -> int:
"""Return converted datetime value."""
if self._value is None:
raise MessageError("Unable to return value. Deserialize data first")
raise DESERIALIZE_ERROR

Check warning on line 159 in plugwise_usb/messages/properties.py

View check run for this annotation

Codecov / codecov/patch

plugwise_usb/messages/properties.py#L159

Added line #L159 was not covered by tests
return self._value


Expand Down Expand Up @@ -183,7 +184,7 @@
def value(self) -> datetime:
"""Return converted datetime value."""
if self._value is None:
raise MessageError("Unable to return value. Deserialize data first")
raise DESERIALIZE_ERROR
return self._value


Expand All @@ -203,7 +204,7 @@
def value(self) -> int:
"""Return converted int value."""
if self._value is None:
raise MessageError("Unable to return value. Deserialize data first")
raise DESERIALIZE_ERROR

Check warning on line 207 in plugwise_usb/messages/properties.py

View check run for this annotation

Codecov / codecov/patch

plugwise_usb/messages/properties.py#L207

Added line #L207 was not covered by tests
return self._value


Expand Down Expand Up @@ -240,14 +241,14 @@
def value_set(self) -> bool:
"""True when datetime is converted."""
if not self._deserialized:
raise MessageError("Unable to return value. Deserialize data first")
raise DESERIALIZE_ERROR

Check warning on line 244 in plugwise_usb/messages/properties.py

View check run for this annotation

Codecov / codecov/patch

plugwise_usb/messages/properties.py#L244

Added line #L244 was not covered by tests
return self._value is not None

@property
def value(self) -> datetime:
"""Return converted datetime value."""
if self._value is None:
raise MessageError("Unable to return value. Deserialize data first")
raise DESERIALIZE_ERROR

Check warning on line 251 in plugwise_usb/messages/properties.py

View check run for this annotation

Codecov / codecov/patch

plugwise_usb/messages/properties.py#L251

Added line #L251 was not covered by tests
return self._value


Expand All @@ -272,7 +273,7 @@
def value(self) -> time:
"""Return converted time value."""
if self._value is None:
raise MessageError("Unable to return value. Deserialize data first")
raise DESERIALIZE_ERROR

Check warning on line 276 in plugwise_usb/messages/properties.py

View check run for this annotation

Codecov / codecov/patch

plugwise_usb/messages/properties.py#L276

Added line #L276 was not covered by tests
return self._value


Expand All @@ -297,7 +298,7 @@
def value(self) -> str:
"""Return converted string value."""
if self._value is None:
raise MessageError("Unable to return value. Deserialize data first")
raise DESERIALIZE_ERROR

Check warning on line 301 in plugwise_usb/messages/properties.py

View check run for this annotation

Codecov / codecov/patch

plugwise_usb/messages/properties.py#L301

Added line #L301 was not covered by tests
return self._value


Expand Down Expand Up @@ -326,7 +327,7 @@
def value(self) -> time:
"""Return converted time value."""
if self._value is None:
raise MessageError("Unable to return value. Deserialize data first")
raise DESERIALIZE_ERROR

Check warning on line 330 in plugwise_usb/messages/properties.py

View check run for this annotation

Codecov / codecov/patch

plugwise_usb/messages/properties.py#L330

Added line #L330 was not covered by tests
return self._value


Expand Down Expand Up @@ -355,7 +356,7 @@
def value(self) -> date:
"""Return converted date value."""
if self._value is None:
raise MessageError("Unable to return value. Deserialize data first")
raise DESERIALIZE_ERROR

Check warning on line 359 in plugwise_usb/messages/properties.py

View check run for this annotation

Codecov / codecov/patch

plugwise_usb/messages/properties.py#L359

Added line #L359 was not covered by tests
return self._value


Expand All @@ -376,7 +377,7 @@
def value(self) -> float:
"""Return converted float value."""
if self._value is None:
raise MessageError("Unable to return value. Deserialize data first")
raise DESERIALIZE_ERROR

Check warning on line 380 in plugwise_usb/messages/properties.py

View check run for this annotation

Codecov / codecov/patch

plugwise_usb/messages/properties.py#L380

Added line #L380 was not covered by tests
return self._value


Expand All @@ -399,5 +400,5 @@
def value(self) -> int:
"""Return converted time value."""
if self._value is None:
raise MessageError("Unable to return value. Deserialize data first")
raise DESERIALIZE_ERROR

Check warning on line 403 in plugwise_usb/messages/properties.py

View check run for this annotation

Codecov / codecov/patch

plugwise_usb/messages/properties.py#L403

Added line #L403 was not covered by tests
return self._value
Loading