Skip to content

Commit

Permalink
Proxy descriptor attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
denpamusic committed Nov 14, 2023
1 parent 41d89bb commit 4477744
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions pyplumio/helpers/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ def __repr__(self) -> str:
f"min_value={self.min_value}, max_value={self.max_value})"
)

def __getattr__(self, name: str):
"""Return attributes from the parameter description."""
return getattr(self.description, name)

def _call_relational_method(self, method_to_call, other):
"""Call a specified relational method."""
func = getattr(self._value, method_to_call)
Expand Down
14 changes: 11 additions & 3 deletions tests/helpers/test_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from pyplumio.const import BYTE_UNDEFINED, STATE_OFF, STATE_ON
from pyplumio.const import BYTE_UNDEFINED, STATE_OFF, STATE_ON, UnitOfMeasurement
from pyplumio.devices.ecomax import EcoMAX
from pyplumio.frames import Request
from pyplumio.helpers.parameter import (
Expand Down Expand Up @@ -40,7 +40,9 @@ def fixture_parameter(ecomax: EcoMAX) -> Parameter:
value=1,
min_value=0,
max_value=5,
description=ParameterDescription(name="test_parameter"),
description=ParameterDescription(
name="test_parameter", unit_of_measurement=UnitOfMeasurement.CELSIUS
),
)


Expand Down Expand Up @@ -155,10 +157,16 @@ def test_parameter_repr(parameter: Parameter) -> None:
assert repr(parameter) == (
"TestParameter(device=EcoMAX, "
"description=ParameterDescription(name='test_parameter', "
"unit_of_measurement=None), value=1, min_value=0, max_value=5)"
"unit_of_measurement=<UnitOfMeasurement.CELSIUS: '°C'>), "
"value=1, min_value=0, max_value=5)"
)


def test_parameter_getattr(parameter: Parameter):
"""Test getting attributes from the parameters description."""
assert parameter.unit_of_measurement == UnitOfMeasurement.CELSIUS


@patch("asyncio.Queue.put")
async def test_parameter_request_with_unchanged_value(
mock_put, parameter: Parameter, bypass_asyncio_sleep, caplog
Expand Down

0 comments on commit 4477744

Please sign in to comment.