Skip to content

Commit

Permalink
fix pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
pawlizio committed Nov 24, 2023
1 parent 5757ef9 commit 92e9e70
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 144 deletions.
6 changes: 4 additions & 2 deletions pyvlx/heartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
class Heartbeat:
"""Class for sending heartbeats to API."""

def __init__(self, pyvlx: "PyVLX", interval: int = 30, load_all_states: bool = True):
def __init__(
self, pyvlx: "PyVLX", interval: int = 30, load_all_states: bool = True
):
"""Initialize Heartbeat object."""
PYVLXLOG.debug("Heartbeat __init__")
self.pyvlx = pyvlx
Expand Down Expand Up @@ -70,7 +72,7 @@ async def pulse(self) -> None:
# If nodes contain Blind or DualRollerShutter device, refresh orientation or upper/lower curtain positions because House Monitoring
# delivers wrong values for FP1, FP2 and FP3 parameter
for node in self.pyvlx.nodes:
if isinstance(node, Blind) or isinstance(node, DualRollerShutter) or self.load_all_states:
if isinstance(node, (Blind, DualRollerShutter)) or self.load_all_states:
status_request = StatusRequest(self.pyvlx, node.node_id)
await status_request.do_api_call()
# give user requests a chance
Expand Down
24 changes: 18 additions & 6 deletions pyvlx/node_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,34 @@

from .api.frames import (
FrameGetAllNodesInformationNotification,
FrameGetNodeInformationNotification)
FrameGetNodeInformationNotification,
)
from .const import NodeTypeWithSubtype
from .lightening_device import Light
from .log import PYVLXLOG
from .node import Node
from .on_off_switch import OnOffSwitch
from .opening_device import (
Awning, Blade, Blind, DualRollerShutter, GarageDoor, Gate, RollerShutter,
Window)
Awning,
Blade,
Blind,
DualRollerShutter,
GarageDoor,
Gate,
RollerShutter,
Window,
)

if TYPE_CHECKING:
from pyvlx import PyVLX


def convert_frame_to_node(pyvlx: "PyVLX",
frame: Union[FrameGetNodeInformationNotification, FrameGetAllNodesInformationNotification]) -> Optional[Node]:
def convert_frame_to_node(
pyvlx: "PyVLX",
frame: Union[
FrameGetNodeInformationNotification, FrameGetAllNodesInformationNotification
],
) -> Optional[Node]:
"""Convert FrameGet[All]Node[s]InformationNotification into Node object."""
# pylint: disable=too-many-return-statements

Expand Down Expand Up @@ -55,7 +67,7 @@ def convert_frame_to_node(pyvlx: "PyVLX",

if frame.node_type in [
NodeTypeWithSubtype.ROLLER_SHUTTER,
NodeTypeWithSubtype.SWINGING_SHUTTERS
NodeTypeWithSubtype.SWINGING_SHUTTERS,
]:
return RollerShutter(
pyvlx=pyvlx,
Expand Down
71 changes: 47 additions & 24 deletions pyvlx/node_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
from typing import TYPE_CHECKING, Any

from .api.frames import (
FrameBase, FrameGetAllNodesInformationNotification,
FrameNodeStatePositionChangedNotification, FrameStatusRequestNotification)
FrameBase,
FrameGetAllNodesInformationNotification,
FrameNodeStatePositionChangedNotification,
FrameStatusRequestNotification,
)
from .const import NodeParameter, OperatingState
from .lightening_device import LighteningDevice
from .log import PYVLXLOG
Expand All @@ -23,16 +26,18 @@ def __init__(self, pyvlx: "PyVLX"):
"""Initialize NodeUpdater object."""
self.pyvlx = pyvlx

async def process_frame_status_request_notification(self, frame: FrameStatusRequestNotification) -> None:
async def process_frame_status_request_notification(
self, frame: FrameStatusRequestNotification
) -> None:
"""Process FrameStatusRequestNotification."""
PYVLXLOG.debug("NodeUpdater process frame: %s", frame)
if frame.node_id not in self.pyvlx.nodes:
return
node = self.pyvlx.nodes[frame.node_id]
if isinstance(node, Blind):
if NodeParameter(0) not in frame.parameter_data: # MP missing in frame
if NodeParameter(0) not in frame.parameter_data: # MP missing in frame
return
if NodeParameter(3) not in frame.parameter_data: # FP3 missing in frame
if NodeParameter(3) not in frame.parameter_data: # FP3 missing in frame
return
position = Position(frame.parameter_data[NodeParameter(0)])
orientation = Position(frame.parameter_data[NodeParameter(3)])
Expand All @@ -41,17 +46,15 @@ async def process_frame_status_request_notification(self, frame: FrameStatusRequ
PYVLXLOG.debug("%s position changed to: %s", node.name, position)
if orientation.position <= Parameter.MAX:
node.orientation = orientation
PYVLXLOG.debug(
"%s orientation changed to: %s", node.name, orientation
)
PYVLXLOG.debug("%s orientation changed to: %s", node.name, orientation)
await node.after_update()

if isinstance(node, DualRollerShutter):
if NodeParameter(0) not in frame.parameter_data: # MP missing in frame
if NodeParameter(0) not in frame.parameter_data: # MP missing in frame
return
if NodeParameter(1) not in frame.parameter_data: # FP1 missing in frame
if NodeParameter(1) not in frame.parameter_data: # FP1 missing in frame
return
if NodeParameter(2) not in frame.parameter_data: # FP2 missing in frame
if NodeParameter(2) not in frame.parameter_data: # FP2 missing in frame
return
position = Position(frame.parameter_data[NodeParameter(0)])
position_upper_curtain = Position(frame.parameter_data[NodeParameter(1)])
Expand All @@ -62,23 +65,27 @@ async def process_frame_status_request_notification(self, frame: FrameStatusRequ
if position_upper_curtain.position <= Parameter.MAX:
node.position_upper_curtain = position_upper_curtain
PYVLXLOG.debug(
"%s position upper curtain changed to: %s", node.name, position_upper_curtain
"%s position upper curtain changed to: %s",
node.name,
position_upper_curtain,
)
if position_lower_curtain.position <= Parameter.MAX:
node.position_lower_curtain = position_lower_curtain
PYVLXLOG.debug(
"%s position lower curtain changed to: %s", node.name, position_lower_curtain
"%s position lower curtain changed to: %s",
node.name,
position_lower_curtain,
)
await node.after_update()

async def process_frame(self, frame: FrameBase) -> None:
"""Update nodes via frame, usually received by house monitor."""
if isinstance(
frame,
(
FrameGetAllNodesInformationNotification,
FrameNodeStatePositionChangedNotification,
),
frame,
(
FrameGetAllNodesInformationNotification,
FrameNodeStatePositionChangedNotification,
),
):
PYVLXLOG.debug("NodeUpdater process frame: %s", frame)
if frame.node_id not in self.pyvlx.nodes:
Expand All @@ -92,18 +99,34 @@ async def process_frame(self, frame: FrameBase) -> None:

# Set opening device status
if isinstance(node, OpeningDevice):
if (position.position > target.position <= Parameter.MAX) and ((frame.state == OperatingState.EXECUTING) or frame.remaining_time > 0):
if (position.position > target.position <= Parameter.MAX) and (
(frame.state == OperatingState.EXECUTING)
or frame.remaining_time > 0
):
node.is_opening = True
PYVLXLOG.debug("%s is opening", node.name)
node.state_received_at = datetime.datetime.now()
node.estimated_completion = node.state_received_at + datetime.timedelta(0, frame.remaining_time)
PYVLXLOG.debug("%s will be opening until", node.estimated_completion)
elif (position.position < target.position <= Parameter.MAX) and ((frame.state == OperatingState.EXECUTING) or frame.remaining_time > 0):
node.estimated_completion = (
node.state_received_at
+ datetime.timedelta(0, frame.remaining_time)
)
PYVLXLOG.debug(
"%s will be opening until", node.estimated_completion
)
elif (position.position < target.position <= Parameter.MAX) and (
(frame.state == OperatingState.EXECUTING)
or frame.remaining_time > 0
):
node.is_closing = True
PYVLXLOG.debug("%s is closing", node.name)
node.state_received_at = datetime.datetime.now()
node.estimated_completion = node.state_received_at + datetime.timedelta(0, frame.remaining_time)
PYVLXLOG.debug("%s will be closing until", node.estimated_completion)
node.estimated_completion = (
node.state_received_at
+ datetime.timedelta(0, frame.remaining_time)
)
PYVLXLOG.debug(
"%s will be closing until", node.estimated_completion
)
else:
if node.is_opening:
node.is_opening = False
Expand Down
Loading

0 comments on commit 92e9e70

Please sign in to comment.