def testReadMultipleLines(self, socketMock):
        self.connect(socketMock)
        self.socket.recv.return_value = b"A:B\r\nC\r\n"

        self.assertEqual(
            Message("A", "B"), self.connection.recv(Deadline(TEST_TIMEOUT))
        )
        self.socket.recv.reset_mock()
        self.assertEqual(Message("C", ""), self.connection.recv(Deadline(TEST_TIMEOUT)))
Пример #2
0
    def testUpdateOpensNewNonPersistantConnectionAndClosesIt(self, ClassMock):
        messages = [Message("H"), Message("L")]
        self.init(ClassMock)
        self.commander.use_persistent_connection = False
        self.connection.recv.side_effect = messages

        self.assertEqual(messages, self.commander.update())

        self.connection.send.assert_called_once_with(Q_CMD)
        self.assertEqual(2, self.connection.recv.call_count)
        self.connection.close.assert_called_once()
    def testReadPartialLine(self, socketMock):
        self.connect(socketMock)
        self.socket.recv.side_effect = [b"A:", b"B\r\n"]

        self.assertEqual(
            Message("A", "B"), self.connection.recv(Deadline(TEST_TIMEOUT))
        )
Пример #4
0
    def testReadAMessage(self, socketMock):
        self.connect(socketMock)
        self.socket.recv.return_value = b"A:B\r\n"

        self.assertEqual(Message("A", "B"),
                         self.connection.recv(TEST_TIMEOUT.deadline()))
        self.socket.close.assert_not_called()
Пример #5
0
    def testUpdateSendsCommandAfterAfterTimeout(self, ClassMock):
        messages = [Message("H"), None]
        self.init(ClassMock)
        self.connection.recv.side_effect = messages

        self.assertEqual(messages[:1], self.commander.update())

        self.connection.send.assert_not_called()
        self.assertEqual(2, self.connection.recv.call_count)
        self.connection.close.assert_not_called()

        self.connection.recv.reset_mock()
        self.__mockCommandResponse(L_CMD_SUCCESS)

        self.assertEqual([L_CMD_SUCCESS], self.commander.update())

        self.connection.send.assert_called_once_with(Message("l"))
        self.assertEqual(2, self.connection.recv.call_count)
        self.connection.close.assert_not_called()
Пример #6
0
    def test_parse_manual_l_message(self, ClassMock):
        self.init(ClassMock, INIT_RESPONSE_1)
        self.__update(
            [
                Message.decode(
                    b"L:Cwa8U/ESGQkhALMACwa8WgkSGQAhAMAACwa8XAkSGQUhALIACwirggMSGQUhAAAA"
                )
            ]
        )

        device = self.cube.devices[0]
        self.assertEqual(MAX_DEVICE_MODE_MANUAL, device.mode)
        self.assertEqual(17.9, device.actual_temperature)
        self.assertEqual(16.5, device.target_temperature)
Пример #7
0
    def test_parse_m_message(self, ClassMock):
        self.init(ClassMock, INIT_RESPONSE_2)
        self.__update(
            [
                Message.decode(
                    b"M:00,01,VgIEAQdLaXRjaGVuBrxTAgZMaXZpbmcGvFoDCFNsZWVwaW5nCKuCBARXb3JrBrxcBAEGvF"
                    b"NLRVEwMzM2MTA4B0tpdGNoZW4BAQa8WktFUTAzMzYxMDAGTGl2aW5nAgEIq4JLRVEwMzM1NjYyCFNs"
                    b"ZWVwaW5nAwEGvFxLRVEwMzM2MTA0BFdvcmsEAQ=="
                ),
                INIT_RESPONSE_2[-1],
            ]
        )

        self.assertEqual("0E2EBA", self.cube.devices[0].rf_address)
        self.assertEqual("Thermostat", self.cube.devices[0].name)
        self.assertEqual(MAX_THERMOSTAT, self.cube.devices[0].type)
        self.assertEqual("KEQ1086437", self.cube.devices[0].serial)
        self.assertEqual(1, self.cube.devices[0].room_id)

        self.assertEqual("0A0881", self.cube.devices[1].rf_address)
        self.assertEqual("Wandthermostat", self.cube.devices[1].name)
        self.assertEqual(MAX_WALL_THERMOSTAT, self.cube.devices[1].type)
        self.assertEqual("KEQ0655743", self.cube.devices[1].serial)
        self.assertEqual(2, self.cube.devices[1].room_id)

        self.assertEqual("0CA2B2", self.cube.devices[2].rf_address)
        self.assertEqual("Fensterkontakt", self.cube.devices[2].name)
        self.assertEqual(MAX_WINDOW_SHUTTER, self.cube.devices[2].type)
        self.assertEqual("KEQ0839778", self.cube.devices[2].serial)
        self.assertEqual(1, self.cube.devices[2].room_id)

        self.assertEqual("Kitchen", self.cube.rooms[0].name)
        self.assertEqual(1, self.cube.rooms[0].id)

        self.assertEqual("Living", self.cube.rooms[1].name)
        self.assertEqual(2, self.cube.rooms[1].id)
 def testSendMessage(self, socketMock):
     self.connect(socketMock)
     self.connection.send(Message("A", "B"))
     self.socket.send.assert_called_with(b"A:B\r\n")
Пример #9
0
def to_messages(lines):
    return [Message.decode(line) for line in lines]
Пример #10
0
        b"C:015d2a,7QFdKgATAf9KRVEwMzQxMjY3AQsABEAAAAAAAAAAAP///////////////////////////wsABEAAAAAAAAAAQf///////////////"
        b"////////////2h0dHA6Ly9tYXguZXEtMy5kZTo4MC9jdWJlADAvbG9va3VwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
        b"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAENFVAAACgADAAAOEENFU1QAAwACAAAcIA==",
        b"C:0a0881,zgoIgQMCEP9LRVEwNjU1NzQzKyE9CURIVQhFIEUgRSBFIEUgRSBFIEUgRSBFIEUgREhVCEUgRSBFIEUgRSBFIEUgRSBFIEUgRSBES"
        b"FRsRMxVFEUgRSBFIEUgRSBFIEUgRSBFIERIVGxEzFUURSBFIEUgRSBFIEUgRSBFIEUgREhUbETMVRRFIEUgRSBFIEUgRSBFIEUgRSBESFRsRMx"
        b"VFEUgRSBFIEUgRSBFIEUgRSBFIERIVGxEzFUURSBFIEUgRSBFIEUgRSBFIEUgBxgw",
        b"C:0ca2b2,EQyisgQBFA9LRVEwODM5Nzc4",
        b"C:0e2eba,0g4uugEBEKBLRVExMDg2NDM3KyE9CQcYAzAM/wAgYFR4ISAhICEgISAhIEUgRSBFIEUgRSBFICBgVHghICEgISAhICEgRSBFIEUgR"
        b"SBFIEUgIEJUTiEfISAhICEgISBFIEUgRSBFIEUgRSAgQlROIR8hICEgISAhIEUgRSBFIEUgRSBFICBCVE4hHyEgISAhICEgRSBFIEUgRSBFIEU"
        b"gIEJUTiEfISAhICEgISBFIEUgRSBFIEUgRSAgQlROIR8hICEgISAhIEUgRSBFIEUgRSBFIA==",
        b"L:DAoIgewSGAQQAAAA5QYMorL3EpALDi66ChIYABAAAAA=",
    ]
)

LAST_STATE_MSG = Message.decode(
    b"L:Cwa8U/ESGAAiAAAACwa8WgkSGAAiAAAACwa8XAkSGAUiAAAACwirggMSGAUiAAAA"
)

SEND_CMD_OK_RESPONSE = "S:04,0,31"

WORKDAY_PROGRAMME_1 = [
    {"until": "05:30", "temp": 8},
    {"until": "06:30", "temp": 21},
    {"until": "23:55", "temp": 8},
    {"until": "24:00", "temp": 8},
]

WEEKEND_PROGRAME_1 = [
    {"until": "08:00", "temp": 8},
    {"until": "10:00", "temp": 21},
    {"until": "24:00", "temp": 8},
Пример #11
0
 def testDecodeValidMessage(self):
     line = b"s:AARAAAAABrxTAWo=\r\n"
     msg = Message.decode(line)
     self.assertEqual(Message("s", "AARAAAAABrxTAWo="), msg)
     self.assertEqual("S", msg.reply_cmd())
     self.assertEqual(line, msg.encode())
Пример #12
0
 def testDecodeEmptyMessage(self):
     self.assertEqual(Message(""), Message.decode(b"\r\n"))
Пример #13
0
import base64
from unittest import TestCase
from unittest.mock import MagicMock, call, patch

from maxcube.commander import Commander
from maxcube.connection import Connection
from maxcube.deadline import Deadline, Timeout
from maxcube.message import Message

L_CMD = Message("l")
L_CMD_SUCCESS = Message("L")
S_CMD_HEX = "FF00"
S_CMD = Message("s",
                base64.b64encode(bytearray.fromhex(S_CMD_HEX)).decode("utf-8"))
S_CMD_SUCCESS = Message("S", "00,0,31")
S_CMD_ERROR = Message("S", "64,1,1f")
S_CMD_THROTTLE_ERROR = Message("S", "64,1,0")
Q_CMD = Message("q")

TEST_TIMEOUT = Timeout("test", 1.0)


@patch("maxcube.commander.Connection", spec=True)
class TestCommander(TestCase):
    """ Test Max! Cube command handler """
    def init(self, ClassMock):
        self.connection = ClassMock.return_value
        self.commander = Commander("host", 1234)

    def testDisconnectIsNoopIfAlreadyDisconnected(self, ClassMock):
        self.init(ClassMock)