-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from pawlizio/master
Reboot function added
- Loading branch information
Showing
8 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"""Module for reboot frame classes.""" | ||
from pyvlx.const import Command | ||
|
||
from .frame import FrameBase | ||
|
||
|
||
class FrameGatewayRebootRequest(FrameBase): | ||
"""Frame for requesting version.""" | ||
|
||
PAYLOAD_LEN = 0 | ||
|
||
def __init__(self): | ||
"""Init Frame.""" | ||
super().__init__(Command.GW_REBOOT_REQ) | ||
|
||
def __str__(self): | ||
"""Return human readable string.""" | ||
return '<FrameGatewayRebootRequest/>' | ||
|
||
class FrameGatewayRebootConfirmation(FrameBase): | ||
"""Frame for response for get version requests.""" | ||
|
||
PAYLOAD_LEN = 0 | ||
|
||
def __init__(self): | ||
"""Init Frame.""" | ||
super().__init__(Command.GW_REBOOT_CFM) | ||
|
||
def __str__(self): | ||
"""Return human readable string.""" | ||
return '<FrameGatewayRebootConfirmation/>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""Module for handling the login to API.""" | ||
from .api_event import ApiEvent | ||
from .frames import FrameGatewayRebootRequest, FrameGatewayRebootConfirmation | ||
from .log import PYVLXLOG | ||
|
||
class Reboot(ApiEvent): | ||
"""Class for handling login to API.""" | ||
|
||
def __init__(self, pyvlx): | ||
"""Initialize login class.""" | ||
super().__init__(pyvlx=pyvlx) | ||
self.pyvlx = pyvlx | ||
|
||
async def handle_frame(self, frame): | ||
"""Handle incoming API frame, return True if this was the expected frame.""" | ||
if isinstance(frame, FrameGatewayRebootConfirmation): | ||
PYVLXLOG.warning("KLF200 is rebooting") | ||
self.pyvlx.connection.connected = False | ||
return True | ||
return False | ||
|
||
def request_frame(self): | ||
"""Construct initiating frame.""" | ||
return FrameGatewayRebootRequest() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Unit tests for FrameGatewayRebootConfirmation.""" | ||
import unittest | ||
|
||
from pyvlx.frame_creation import frame_from_raw | ||
from pyvlx.frames import FrameGatewayRebootConfirmation | ||
|
||
|
||
class TestFrameRebootConfirmation(unittest.TestCase): | ||
"""Test class FrameSetUTCConfirmation.""" | ||
|
||
# pylint: disable=too-many-public-methods,invalid-name | ||
|
||
EXAMPLE_FRAME = b'\x00\x03\x00\x02\x01' | ||
|
||
def test_bytes(self): | ||
"""Test FrameGatewayRebootConfirmation.""" | ||
frame = FrameGatewayRebootConfirmation() | ||
self.assertEqual(bytes(frame), self.EXAMPLE_FRAME) | ||
|
||
def test_frame_from_raw(self): | ||
"""Test parse FrameGatewayRebootConfirmation from raw.""" | ||
frame = frame_from_raw(self.EXAMPLE_FRAME) | ||
self.assertTrue(isinstance(frame, FrameGatewayRebootConfirmation)) | ||
|
||
def test_str(self): | ||
"""Test string representation of FrameGatewayRebootConfirmation.""" | ||
frame = FrameGatewayRebootConfirmation() | ||
self.assertEqual(str(frame), "<FrameGatewayRebootConfirmation/>") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Unit tests for FrameGatewayRebootRequest.""" | ||
import unittest | ||
|
||
from pyvlx.frame_creation import frame_from_raw | ||
from pyvlx.frames import FrameGatewayRebootRequest | ||
|
||
|
||
class TestFrameRebootRequest(unittest.TestCase): | ||
"""Test class FrameGatewayRebootRequest.""" | ||
|
||
# pylint: disable=too-many-public-methods,invalid-name | ||
|
||
EXAMPLE_FRAME = b'\x00\x03\x00\x01\x02' | ||
|
||
def test_bytes(self): | ||
"""Test FrameGatewayRebootRequest.""" | ||
frame = FrameGatewayRebootRequest() | ||
self.assertEqual(bytes(frame), self.EXAMPLE_FRAME) | ||
|
||
def test_frame_from_raw(self): | ||
"""Test parse FrameGatewayRebootRequest from raw.""" | ||
frame = frame_from_raw(self.EXAMPLE_FRAME) | ||
self.assertTrue(isinstance(frame, FrameGatewayRebootRequest)) | ||
|
||
def test_str(self): | ||
"""Test string representation of FrameGatewayRebootRequest.""" | ||
frame = FrameGatewayRebootRequest() | ||
self.assertEqual(str(frame), "<FrameGatewayRebootRequest/>") |