Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/icommitdesnet/pyvlx
Browse files Browse the repository at this point in the history
  • Loading branch information
pawlizio committed Dec 20, 2020
2 parents 234f97d + 804ccfa commit 7c26df1
Show file tree
Hide file tree
Showing 133 changed files with 1,990 additions and 503 deletions.
1 change: 1 addition & 0 deletions pyvlx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
from .pyvlx import PyVLX
from .scene import Scene
from .scenes import Scenes
from .klf200gateway import Klf200Gateway
21 changes: 21 additions & 0 deletions pyvlx/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Module for all KLF 200 API frames."""
# flake8: noqa

from .house_status_monitor import (house_status_monitor_enable)
from .command_send import (CommandSend)
from .get_local_time import (FrameGetLocalTimeRequest, FrameGetLocalTimeConfirmation)
from .get_state import (GetState)
from .get_network_setup import (GetNetworkSetup)
from .get_protocol_version import (GetProtocolVersion)
from .get_version import (GetVersion)
from .get_local_time import (GetLocalTime)
from .leave_learn_state import (LeaveLearnState)
from .factory_default import (FactoryDefault)
from .password_enter import (PasswordEnter)
from .set_utc import (SetUTC)
from .reboot import (Reboot)
from .activate_scene import (ActivateScene)
from .set_node_name import (SetNodeName)
from .get_all_nodes_information import (GetAllNodesInformation)
from .get_node_information import (GetNodeInformation)
from .get_scene_list import (GetSceneList)
18 changes: 9 additions & 9 deletions pyvlx/activate_scene.py → pyvlx/api/activate_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ActivateScene(ApiEvent):
"""Class for activating scene via API."""

def __init__(
self, pyvlx, scene_id, wait_for_completion=True, timeout_in_seconds=60
self, pyvlx, scene_id, wait_for_completion=True, timeout_in_seconds=60
):
"""Initialize SceneList class."""
super().__init__(pyvlx=pyvlx, timeout_in_seconds=timeout_in_seconds)
Expand All @@ -23,28 +23,28 @@ def __init__(
async def handle_frame(self, frame):
"""Handle incoming API frame, return True if this was the expected frame."""
if (
isinstance(frame, FrameActivateSceneConfirmation)
and frame.session_id == self.session_id
isinstance(frame, FrameActivateSceneConfirmation)
and frame.session_id == self.session_id
):
if frame.status == ActivateSceneConfirmationStatus.ACCEPTED:
self.success = True
return not self.wait_for_completion
if (
isinstance(frame, FrameCommandRemainingTimeNotification)
and frame.session_id == self.session_id
isinstance(frame, FrameCommandRemainingTimeNotification)
and frame.session_id == self.session_id
):
# Ignoring FrameCommandRemainingTimeNotification
return False
if (
isinstance(frame, FrameCommandRunStatusNotification)
and frame.session_id == self.session_id
isinstance(frame, FrameCommandRunStatusNotification)
and frame.session_id == self.session_id
):
# At the moment I don't reall understand what the FrameCommandRunStatusNotification is good for.
# Ignoring these packets for now
return False
if (
isinstance(frame, FrameSessionFinishedNotification)
and frame.session_id == self.session_id
isinstance(frame, FrameSessionFinishedNotification)
and frame.session_id == self.session_id
):
return True
return False
Expand Down
File renamed without changes.
38 changes: 19 additions & 19 deletions pyvlx/command_send.py → pyvlx/api/command_send.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
"""Module for retrieving scene list from API."""
from pyvlx.api_event import ApiEvent
from pyvlx.frames import (
from .api_event import ApiEvent
from .frames import (
CommandSendConfirmationStatus, FrameCommandRemainingTimeNotification,
FrameCommandRunStatusNotification, FrameCommandSendConfirmation,
FrameCommandSendRequest, FrameSessionFinishedNotification)
from pyvlx.session_id import get_new_session_id
from .session_id import get_new_session_id


class CommandSend(ApiEvent):
"""Class for sending command to API."""

def __init__(
self,
pyvlx,
node_id,
parameter,
active_parameter=0,
wait_for_completion=True,
timeout_in_seconds=60,
**functional_parameter
self,
pyvlx,
node_id,
parameter,
active_parameter=0,
wait_for_completion=True,
timeout_in_seconds=60,
**functional_parameter
):
"""Initialize SceneList class."""
super().__init__(pyvlx=pyvlx, timeout_in_seconds=timeout_in_seconds)
Expand All @@ -33,28 +33,28 @@ def __init__(
async def handle_frame(self, frame):
"""Handle incoming API frame, return True if this was the expected frame."""
if (
isinstance(frame, FrameCommandSendConfirmation)
and frame.session_id == self.session_id
isinstance(frame, FrameCommandSendConfirmation)
and frame.session_id == self.session_id
):
if frame.status == CommandSendConfirmationStatus.ACCEPTED:
self.success = True
return not self.wait_for_completion
if (
isinstance(frame, FrameCommandRemainingTimeNotification)
and frame.session_id == self.session_id
isinstance(frame, FrameCommandRemainingTimeNotification)
and frame.session_id == self.session_id
):
# Ignoring FrameCommandRemainingTimeNotification
return False
if (
isinstance(frame, FrameCommandRunStatusNotification)
and frame.session_id == self.session_id
isinstance(frame, FrameCommandRunStatusNotification)
and frame.session_id == self.session_id
):
# At the moment I don't reall understand what the FrameCommandRunStatusNotification is good for.
# Ignoring these packets for now
return False
if (
isinstance(frame, FrameSessionFinishedNotification)
and frame.session_id == self.session_id
isinstance(frame, FrameSessionFinishedNotification)
and frame.session_id == self.session_id
):
return True
return False
Expand Down
26 changes: 26 additions & 0 deletions pyvlx/api/factory_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Module for handling the FactoryDefault to API."""
from pyvlx.log import PYVLXLOG
from .api_event import ApiEvent
from .frames import FrameGatewayFactoryDefaultConfirmation, FrameGatewayFactoryDefaultRequest


class FactoryDefault(ApiEvent):
"""Class for handling Factory reset API."""

def __init__(self, pyvlx):
"""Initialize facotry default class."""
super().__init__(pyvlx=pyvlx)
self.pyvlx = pyvlx
self.success = False

async def handle_frame(self, frame):
"""Handle incoming API frame, return True if this was the expected frame."""
if isinstance(frame, FrameGatewayFactoryDefaultConfirmation):
PYVLXLOG.warning("KLF200 is factory resetting")
self.success = True
return True
return False

def request_frame(self):
"""Construct initiating frame."""
return FrameGatewayFactoryDefaultRequest()
47 changes: 39 additions & 8 deletions pyvlx/frame_creation.py → pyvlx/api/frame_creation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Helper module for creating a frame out of raw data."""
from pyvlx.frames import (
from pyvlx.log import PYVLXLOG
from pyvlx.const import Command
from .frames import (
FrameActivateSceneConfirmation, FrameActivateSceneRequest,
FrameActivationLogUpdatedNotification,
FrameCommandRemainingTimeNotification, FrameCommandRunStatusNotification,
Expand All @@ -21,13 +23,16 @@
FrameHouseStatusMonitorEnableConfirmation,
FrameHouseStatusMonitorEnableRequest,
FrameNodeInformationChangedNotification,
FrameNodeStatePositionChangedNotification, FramePasswordEnterConfirmation,
FramePasswordEnterRequest, FrameSessionFinishedNotification,
FrameNodeStatePositionChangedNotification,
FramePasswordEnterConfirmation, FramePasswordEnterRequest,
FramePasswordChangeRequest, FramePasswordChangeConfirmation, FramePasswordChangeNotification,
FrameSessionFinishedNotification,
FrameSetNodeNameConfirmation, FrameSetNodeNameRequest,
FrameSetUTCConfirmation, FrameSetUTCRequest, extract_from_frame)

from .const import Command
from .log import PYVLXLOG
FrameGetNetworkSetupConfirmation, FrameGetNetworkSetupRequest,
FrameSetUTCConfirmation, FrameSetUTCRequest, extract_from_frame,
FrameLeaveLearnStateConfirmation, FrameLeaveLearnStateRequest,
FrameGetLocalTimeConfirmation, FrameGetLocalTimeRequest,
FrameGatewayFactoryDefaultConfirmation, FrameGatewayFactoryDefaultRequest)


def frame_from_raw(raw):
Expand All @@ -48,7 +53,7 @@ def frame_from_raw(raw):

def create_frame(command):
"""Create and return empty Frame from Command."""
# pylint: disable=too-many-branches,too-many-return-statements
# pylint: disable=too-many-branches,too-many-return-statements,too-many-statements
if command == Command.GW_ERROR_NTF:
return FrameErrorNotification()
if command == Command.GW_COMMAND_SEND_REQ:
Expand All @@ -67,11 +72,28 @@ def create_frame(command):
if command == Command.GW_PASSWORD_ENTER_CFM:
return FramePasswordEnterConfirmation()

if command == Command.GW_PASSWORD_CHANGE_REQ:
return FramePasswordChangeRequest()
if command == Command.GW_PASSWORD_CHANGE_CFM:
return FramePasswordChangeConfirmation()
if command == Command.GW_PASSWORD_CHANGE_NTF:
return FramePasswordChangeNotification()

if command == Command.GW_REBOOT_REQ:
return FrameGatewayRebootRequest()
if command == Command.GW_REBOOT_CFM:
return FrameGatewayRebootConfirmation()

if command == Command.GW_SET_FACTORY_DEFAULT_REQ:
return FrameGatewayFactoryDefaultRequest()
if command == Command.GW_SET_FACTORY_DEFAULT_CFM:
return FrameGatewayFactoryDefaultConfirmation()

if command == Command.GW_GET_LOCAL_TIME_REQ:
return FrameGetLocalTimeRequest()
if command == Command.GW_GET_LOCAL_TIME_CFM:
return FrameGetLocalTimeConfirmation()

if command == Command.GW_CS_DISCOVER_NODES_REQ:
return FrameDiscoverNodesRequest()
if command == Command.GW_CS_DISCOVER_NODES_CFM:
Expand Down Expand Up @@ -129,6 +151,11 @@ def create_frame(command):
if command == Command.GW_GET_STATE_CFM:
return FrameGetStateConfirmation()

if command == Command.GW_GET_NETWORK_SETUP_REQ:
return FrameGetNetworkSetupRequest()
if command == Command.GW_GET_NETWORK_SETUP_CFM:
return FrameGetNetworkSetupConfirmation()

if command == Command.GW_SET_UTC_REQ:
return FrameSetUTCRequest()
if command == Command.GW_SET_UTC_CFM:
Expand All @@ -148,5 +175,9 @@ def create_frame(command):

if command == Command.GW_NODE_STATE_POSITION_CHANGED_NTF:
return FrameNodeStatePositionChangedNotification()
if command == Command.GW_LEAVE_LEARN_STATE_CFM:
return FrameLeaveLearnStateConfirmation()
if command == command.GW_LEAVE_LEARN_STATE_REQ:
return FrameLeaveLearnStateRequest()

return None
16 changes: 14 additions & 2 deletions pyvlx/frames/__init__.py → pyvlx/api/frames/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# flake8: noqa
from .frame import FrameBase
from .alias_array import AliasArray
from .frame_activate_scene import (
ActivateSceneConfirmationStatus, FrameActivateSceneConfirmation,
FrameActivateSceneRequest)
Expand Down Expand Up @@ -30,6 +31,8 @@
from .frame_get_state import (
FrameGetStateConfirmation, FrameGetStateRequest, GatewayState,
GatewaySubState)
from .frame_get_network_setup import (
FrameGetNetworkSetupConfirmation, FrameGetNetworkSetupRequest, DHCPParameter)
from .frame_get_version import (
FrameGetVersionConfirmation, FrameGetVersionRequest)
from .frame_helper import calc_crc, extract_from_frame
Expand All @@ -53,5 +56,14 @@
from .frame_set_node_name import (
FrameSetNodeNameConfirmation, FrameSetNodeNameRequest,
SetNodeNameConfirmationStatus)
from .frame_set_utc_cfm import FrameSetUTCConfirmation
from .frame_set_utc_req import FrameSetUTCRequest
from .frame_set_utc import (FrameSetUTCConfirmation, FrameSetUTCRequest)
from .frame_leave_learn_state import (
FrameLeaveLearnStateRequest, FrameLeaveLearnStateConfirmation,
LeaveLearnStateConfirmationStatus)
from .frame_get_local_time import (
FrameGetLocalTimeRequest, FrameGetLocalTimeConfirmation)
from .frame_facory_default import (
FrameGatewayFactoryDefaultRequest, FrameGatewayFactoryDefaultConfirmation)
from .frame_password_change import (
FramePasswordChangeRequest, FramePasswordChangeConfirmation,
FramePasswordChangeNotification, PasswordChangeConfirmationStatus)
2 changes: 1 addition & 1 deletion pyvlx/alias_array.py → pyvlx/api/frames/alias_array.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Module for storing alias array."""
from .exception import PyVLXException
from pyvlx.exception import PyVLXException


class AliasArray:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class FrameActivateSceneRequest(FrameBase):
PAYLOAD_LEN = 6

def __init__(
self,
scene_id=None,
session_id=None,
originator=Originator.USER,
velocity=Velocity.DEFAULT,
self,
scene_id=None,
session_id=None,
originator=Originator.USER,
velocity=Velocity.DEFAULT,
):
"""Init Frame."""
super().__init__(Command.GW_ACTIVATE_SCENE_REQ)
Expand Down Expand Up @@ -45,8 +45,8 @@ def from_payload(self, payload):

def __str__(self):
"""Return human readable string."""
return "<FrameActivateSceneRequest scene_id={} session_id={} originator={} velocity={}/>".format(
self.scene_id, self.session_id, self.originator, self.velocity
return '<{} scene_id="{}" session_id="{}" originator="{}" velocity="{}"/>'.format(
type(self).__name__, self.scene_id, self.session_id, self.originator, self.velocity
)


Expand Down Expand Up @@ -82,6 +82,6 @@ def from_payload(self, payload):

def __str__(self):
"""Return human readable string."""
return "<FrameActivateSceneConfirmation session_id={} status={}/>".format(
self.session_id, self.status
return '<{} session_id="{}" status="{}"/>'.format(
type(self).__name__, self.session_id, self.status
)
Loading

0 comments on commit 7c26df1

Please sign in to comment.