Example #1
0
 def test_get_module_meter(self):
     payload = '11111111111111111111111111112222222222222222222222222222                            4444444444444444444444444444'
     with mock.patch.object(self.power_communicator,
                            'do_command',
                            return_value=[payload]) as cmd:
         meters = self.controller.get_module_meter(
             {
                 'version': P1_CONCENTRATOR,
                 'address': '11.0'
             }, type=1)
         assert meters == [
             '1111111111111111111111111111',
             '2222222222222222222222222222',
             '                            ',
             '4444444444444444444444444444',
             '',
             '',
             '',
             '',
         ]
         assert cmd.call_args_list == [
             mock.call(
                 '11.0',
                 PowerCommand('G',
                              'M1\x00',
                              '',
                              '224s',
                              module_type=bytearray(b'C')))
         ]
Example #2
0
 def test_get_module_voltage(self):
     with mock.patch.object(self.power_communicator, 'do_command') as cmd:
         self.controller.get_module_voltage({
             'version': POWER_MODULE,
             'address': '11.0'
         })
         assert cmd.call_args_list == [
             mock.call(
                 '11.0',
                 PowerCommand('G',
                              'VOL',
                              '',
                              'f',
                              module_type=bytearray(b'E')))
         ]
Example #3
0
 def test_get_module_injection_tariff(self):
     payload = '0000000001*kWh000002.300*kWh              000012.000*kWh'
     with mock.patch.object(self.power_communicator,
                            'do_command',
                            return_value=[payload]) as cmd:
         meters = self.controller.get_module_injection_tariff(
             {
                 'version': P1_CONCENTRATOR,
                 'address': '11.0'
             }, type=1)
         assert meters == [1.0, 2.3, None, 12.0, None, None, None, None]
         assert cmd.call_args_list == [
             mock.call(
                 '11.0',
                 PowerCommand('G',
                              'i1\x00',
                              '',
                              '112s',
                              module_type=bytearray(b'C')))
         ]
Example #4
0
 def test_get_module_timestamp(self):
     # TODO confirm this is correct
     payload = '000000000001S000000000002              000000000012S'
     with mock.patch.object(self.power_communicator,
                            'do_command',
                            return_value=[payload]) as cmd:
         meters = self.controller.get_module_timestamp({
             'version': P1_CONCENTRATOR,
             'address': '11.0'
         })
         assert meters == [1.0, 2.0, None, 12.0, None, None, None, None]
         assert cmd.call_args_list == [
             mock.call(
                 '11.0',
                 PowerCommand('G',
                              'TS\x00',
                              '',
                              '104s',
                              module_type=bytearray(b'C')))
         ]
Example #5
0
 def test_get_module_day_energy(self):
     payload = '000000.001    000000.002    !@#$%^&*42    000000.012    '
     with mock.patch.object(self.power_communicator,
                            'do_command',
                            return_value=[payload]) as cmd:
         received = self.controller.get_module_day_energy({
             'version': P1_CONCENTRATOR,
             'address': '11.0'
         })
         assert received == [
             0.001, 0.002, None, 0.012, None, None, None, None
         ]
         assert cmd.call_args_list == [
             mock.call(
                 '11.0',
                 PowerCommand('G',
                              'c1\x00',
                              '',
                              '112s',
                              module_type=bytearray(b'C'))),
         ]
Example #6
0
 def test_get_module_delivered_power(self):
     payload = '000001   000002   !@#$42   000012   '
     with mock.patch.object(self.power_communicator,
                            'do_command',
                            return_value=[payload]) as cmd:
         delivered = self.controller.get_module_delivered_power({
             'version':
             P1_CONCENTRATOR,
             'address':
             '11.0'
         })
         assert delivered == [1.0, 2.0, None, 12.0, None, None, None, None]
         assert cmd.call_args_list == [
             mock.call(
                 '11.0',
                 PowerCommand('G',
                              'PD\x00',
                              '',
                              '72s',
                              module_type=bytearray(b'C'))),
         ]
Example #7
0
 def test_get_module_status(self):
     payload = 0b00001011
     with mock.patch.object(self.power_communicator,
                            'do_command',
                            return_value=[payload]) as cmd:
         status = self.controller.get_module_status({
             'version': P1_CONCENTRATOR,
             'address': '11.0'
         })
         assert status == [
             True, True, False, True, False, False, False, False
         ]
         assert cmd.call_args_list == [
             mock.call(
                 '11.0',
                 PowerCommand('G',
                              'SP\x00',
                              '',
                              'B',
                              module_type=bytearray(b'C')))
         ]
Example #8
0
 def test_get_module_voltage(self):
     payload = '00001  002.3  !@#42  00012  '
     with mock.patch.object(self.power_communicator,
                            'do_command',
                            return_value=[payload]) as cmd:
         voltages = self.controller.get_module_voltage({
             'version': P1_CONCENTRATOR,
             'address': '11.0'
         })
         assert voltages == [{
             'phase1': 1.0,
             'phase2': 1.0,
             'phase3': 1.0
         }, {
             'phase1': 2.3,
             'phase2': 2.3,
             'phase3': 2.3
         }, {
             'phase1': None,
             'phase2': None,
             'phase3': None
         }, {
             'phase1': 12.0,
             'phase2': 12.0,
             'phase3': 12.0
         }, {
             'phase1': None,
             'phase2': None,
             'phase3': None
         }, {
             'phase1': None,
             'phase2': None,
             'phase3': None
         }, {
             'phase1': None,
             'phase2': None,
             'phase3': None
         }, {
             'phase1': None,
             'phase2': None,
             'phase3': None
         }]
         self.assertIn(
             mock.call(
                 '11.0',
                 PowerCommand('G',
                              'V1\x00',
                              '',
                              '56s',
                              module_type=bytearray(b'C'))),
             cmd.call_args_list)
         self.assertIn(
             mock.call(
                 '11.0',
                 PowerCommand('G',
                              'V2\x00',
                              '',
                              '56s',
                              module_type=bytearray(b'C'))),
             cmd.call_args_list)
         self.assertIn(
             mock.call(
                 '11.0',
                 PowerCommand('G',
                              'V3\x00',
                              '',
                              '56s',
                              module_type=bytearray(b'C'))),
             cmd.call_args_list)