Skip to content

Commit

Permalink
Fix for #355 (#356)
Browse files Browse the repository at this point in the history
* Fix target_position

* fix isort
  • Loading branch information
pawlizio authored Dec 3, 2023
1 parent 0a28367 commit 8abf076
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 31 deletions.
26 changes: 13 additions & 13 deletions pyvlx/opening_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from .api.get_limitation import GetLimitation
from .exception import PyVLXException
from .node import Node
from .parameter import (
CurrentPosition, IgnorePosition, Parameter, Position, TargetPosition)
from .parameter import CurrentPosition, IgnorePosition, Parameter, Position

if TYPE_CHECKING:
from pyvlx import PyVLX
Expand Down Expand Up @@ -145,7 +144,7 @@ def __str__(self) -> str:
)

async def get_limitation(self) -> GetLimitation:
"""Return limitaation."""
"""Return limitation."""
get_limitation = GetLimitation(pyvlx=self.pyvlx, node_id=self.node_id)
await get_limitation.do_api_call()
if not get_limitation.success:
Expand Down Expand Up @@ -176,29 +175,30 @@ def __init__(
position_parameter=position_parameter,
)
self.orientation = Position(position_percent=0)
self.target_orientation = TargetPosition()
self.target_position = TargetPosition()
self.target_orientation = Position()
self.target_position = Position()
self.open_orientation_target: int = 50
self.close_orientation_target: int = 100

async def set_position_and_orientation(self,
position: Position,
wait_for_completion: bool = True,
orientation: Optional[Position] = None) -> None:
async def set_position_and_orientation(
self,
position: Position,
wait_for_completion: bool = True,
orientation: Optional[Position] = None) -> None:
"""Set window to desired position.
Parameters:
* position: Position object containing the current position.
* target_position: Position object holding the target position
which allows to ajust the position while the blind is in movement
which allows to adjust the position while the blind is in movement
without stopping the blind (if orientation position has been changed.)
* wait_for_completion: If set, function will return
after device has reached target position.
* orientation: If set, the orientation of the device will be set in the same request.
Note, that, if the position is set to 0, the orientation will be set to 0 too.
"""
self.target_position = TargetPosition.from_position(position)
self.target_position = position
self.position = position

fp3: Position
Expand Down Expand Up @@ -227,7 +227,7 @@ async def set_position(self, position: Position, wait_for_completion: bool = Tru
Parameters:
* position: Position object containing the current position.
* target_position: Position object holding the target position
which allows to ajust the position while the blind is in movement
which allows to adjust the position while the blind is in movement
without stopping the blind (if orientation position has been changed.)
* wait_for_completion: If set, function will return
after device has reached target position.
Expand Down Expand Up @@ -276,7 +276,7 @@ async def set_orientation(self, orientation: Position, wait_for_completion: bool
after device has reached target position.
"""
self.target_orientation = TargetPosition.from_position(orientation)
self.target_orientation = orientation
self.orientation = orientation

fp3 = Position(position_percent=0)\
Expand Down
22 changes: 4 additions & 18 deletions pyvlx/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def from_parameter(self, parameter: "Parameter") -> None:

@staticmethod
def from_int(value: int) -> bytes:
"""Create raw out of position vlaue."""
"""Create raw out of position value."""
if not isinstance(value, int):
raise PyVLXException("value_has_to_be_int")
if not Parameter.is_valid_int(value):
Expand Down Expand Up @@ -201,7 +201,7 @@ def from_percent(position_percent: int) -> bytes:
@staticmethod
def to_percent(raw: bytes) -> int:
"""Create percent position value out of raw."""
# The first byte has the vlue from 0 to 200. Ignoring the second one.
# The first byte has the value from 0 to 200. Ignoring the second one.
# Adding 0.5 allows a slight tolerance for devices (e.g. Velux SML) that
# do not return exactly 51200 as final position when closed.
return int(raw[0] / 2 + 0.5)
Expand Down Expand Up @@ -230,26 +230,12 @@ def __init__(self) -> None:


class TargetPosition(Position):
"""Class for using a target position, if another parameter is set.
It is implemented by taking the target parameter value and loads it into the execution
parameter buffer. When the target value is read, it holds for a given parameter always the
latest stored target value about a command execution.
"""
"""Class for using a target position."""

def __init__(self) -> None:
"""Initialize TargetPosition class."""
super().__init__(position=Position.TARGET)

@staticmethod
def from_position(from_position: Position) -> "TargetPosition":
"""Create TargetPosition from an existing position."""
target = TargetPosition()
target.position = from_position.position
target.position_percent = from_position.position_percent
return target


class IgnorePosition(Position):
"""The Ignore is used where a parameter in the frame is to be ignored."""
Expand Down Expand Up @@ -304,7 +290,7 @@ def intensity(self, intensity: int) -> None:
@property
def intensity_percent(self) -> int:
"""Intensity percent property."""
# inclear why it returns a <property object> here
# unclear why it returns a <property object> here
return int(self.to_percent(self.raw))

@intensity_percent.setter
Expand Down

0 comments on commit 8abf076

Please sign in to comment.