예제 #1
0
class TestBroadcastController(unittest.TestCase):
    """Unittests for reading data functions"""
    def setUp(self):
        logging.basicConfig(level=logging.ERROR)
        setup = SetupTestClass()
        self.adaptor = MockHeatmiserAdaptor(setup)
        #network, address, protocol, short_name, long_name, model, mode
        #self.func = ThermoStat(None, 1, HMV3_ID, 'test', 'test controller', 'prt_hw_model', PROG_MODE_DAY)
        self.settings = {
            'address': 1,
            'protocol': HMV3_ID,
            'long_name': 'test controller',
            'expected_model': 'prt_hw_model',
            'expected_prog_mode': PROG_MODE_DAY
        }
        dev1 = ThermoStatHotWaterDay(self.adaptor, self.settings)
        self.settings2 = {
            'address': 2,
            'protocol': HMV3_ID,
            'long_name': 'test controller',
            'expected_model': 'prt_hw_model',
            'expected_prog_mode': PROG_MODE_DAY
        }
        dev2 = ThermoStatHotWaterDay(self.adaptor, self.settings)
        self.func = HeatmiserBroadcastDevice(self.adaptor, 'Broadcaster',
                                             [dev1, dev2])

    def test_read_fields(self):
        responses = [[0, 0, 0, 0, 0, 0, 0, 170], [0, 1, 0, 0, 0, 0, 0, 180]]
        self.adaptor.setresponse(responses)
        self.assertEqual([[0, 17], [1, 18]],
                         self.func.read_fields(['tempholdmins', 'airtemp'], 0))
예제 #2
0
 def test_readall(self):
     setup = SetupTestClass()
     adaptor = MockHeatmiserAdaptor(setup)
     self.func = ThermoStatHotWaterDay(adaptor, self.settings)
     #basetime = (6 - 2) * 86400 + 53376.0 + YEAR2000
     #self.func.lastreadtime = basetime - get_offset(basetime)
     lta = self.func.currenttime.localtimearray()
     #, 3, 14, 49, 36,
     responses = [[
         1, 37, 0, 22, 4, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 38, 1, 9, 12, 28, 1,
         1, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 220, 0, 0, 0
     ] + lta + [
         7, 0, 19, 9, 30, 10, 17, 0, 19, 21, 30, 10, 7, 0, 19, 21, 30, 10,
         24, 0, 5, 24, 0, 5, 24, 0, 24, 0, 24, 0, 24, 0, 24, 0, 24, 0, 24,
         0, 24, 0, 8, 0, 9, 0, 18, 0, 19, 0, 24, 0, 24, 0, 24, 0, 24, 0, 7,
         0, 20, 21, 30, 12, 24, 0, 12, 24, 0, 12, 7, 0, 20, 21, 30, 12, 24,
         0, 12, 24, 0, 12, 7, 0, 19, 8, 30, 12, 16, 30, 20, 21, 0, 12, 7, 0,
         20, 12, 0, 12, 17, 0, 20, 21, 30, 12, 5, 0, 20, 21, 30, 12, 24, 0,
         12, 24, 0, 12, 7, 0, 20, 12, 0, 12, 17, 0, 20, 21, 30, 12, 7, 0,
         12, 24, 0, 12, 24, 0, 12, 24, 0, 12, 17, 30, 18, 0, 24, 0, 24, 0,
         24, 0, 24, 0, 24, 0, 24, 0, 17, 30, 18, 0, 24, 0, 24, 0, 24, 0, 24,
         0, 24, 0, 24, 0, 17, 30, 18, 0, 24, 0, 24, 0, 24, 0, 24, 0, 24, 0,
         24, 0, 17, 30, 18, 0, 24, 0, 24, 0, 24, 0, 24, 0, 24, 0, 24, 0, 17,
         30, 18, 0, 24, 0, 24, 0, 24, 0, 24, 0, 24, 0, 24, 0, 17, 30, 18, 0,
         24, 0, 24, 0, 24, 0, 24, 0, 24, 0, 24, 0, 17, 30, 18, 0, 24, 0, 24,
         0, 24, 0, 24, 0, 24, 0, 24, 0
     ]]
     adaptor.setresponse(responses)
     self.func.read_all()
     self.assertEqual([(1, 3, 0, 293, True)], adaptor.arguments)
예제 #3
0
 def test_read_field(self):
     setup = SetupTestClass()
     adaptor = MockHeatmiserAdaptor(setup)
     self.func = ThermoStatDay(adaptor, self.settings2)
     responses = [[0, 170], [0, 180]]
     adaptor.setresponse(responses)
     self.assertEqual(17, self.func.read_field('airtemp', 1))
     self.assertEqual(17, self.func.read_field('airtemp',
                                               -1))  #only check presence
     self.func.airtemp.lastreadtime = 0  #force reread
     self.assertEqual(18, self.func.read_field('airtemp', None))
예제 #4
0
    def test_get_temps_and_demand(self):
        setup = SetupTestClass()
        adaptor = MockHeatmiserAdaptor(setup)
        self.func = ThermoStatHotWaterDay(adaptor, self.settings)

        #queue some data to recieve
        responses = [[1, 1, 17, 0, 17, 0, 0, 0, 1]]
        adaptor.setresponse(responses)
        #run command
        self.func.get_temps_and_demand()
        self.assertEqual([(1, 3, 34, 9, False)], adaptor.arguments)
        self.assertEqual(25.7, self.func.remoteairtemp.value)
        self.assertEqual(1, self.func.hotwaterdemand.value)
예제 #5
0
    def test_readvariables(self):
        setup = SetupTestClass()
        adaptor = MockHeatmiserAdaptor(setup)
        self.func = ThermoStatHotWaterDay(adaptor, self.settings)

        #queue some data to recieve
        responses = [[17, 30, 1, 1, 1, 1, 0, 0],
                     [0, 0, 17, 0, 17, 0, 17, 0, 0, 0, 0]]
        adaptor.setresponse(responses)
        #run command
        self.func.get_variables()
        self.assertEqual([(1, 3, 18, 8, False), (1, 3, 32, 11, False)],
                         adaptor.arguments)
        self.assertEqual(17, self.func.setroomtemp.value)
        self.assertEqual(0, self.func.hotwaterdemand.value)
예제 #6
0
    def test_network_find(self):
        module_path = os.path.abspath(os.path.dirname(__file__))
        configfile = os.path.join(module_path, "nocontrollers.conf")

        hmn = HeatmiserNetwork(configfile)

        setup = SetupTestClass()
        adaptor = MockHeatmiserAdaptor(setup)
        hmn.adaptor = adaptor

        #queue some data to recieve
        responses = [[4, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
                     [4, 0, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1]]
        adaptor.setresponse(responses)

        hmn.find_devices(3)

        self.assertEqual(len(hmn.controllers), 2)
        self.assertIsInstance(hmn.controllers[0], HeatmiserDevice)
        self.assertIsInstance(hmn.controllers[1], HeatmiserDevice)
        self.assertEqual(hmn.controllers[1].set_address, 2)
예제 #7
0
 def setUp(self):
     logging.basicConfig(level=logging.ERROR)
     self.settings = {
         'address': 5,
         'protocol': HMV3_ID,
         'long_name': 'test controller',
         'expected_model': 'prt_e_model',
         'expected_prog_mode': PROG_MODE_DAY
     }
     setup = SetupTestClass()
     self.tester = MockHeatmiserAdaptor(setup)
     #self.tester.write_to_device = self.tester.store
     self.func = ThermoStatDay(self.tester, self.settings)
예제 #8
0
 def setUp(self):
     logging.basicConfig(level=logging.ERROR)
     setup = SetupTestClass()
     self.adaptor = MockHeatmiserAdaptor(setup)
     #network, address, protocol, short_name, long_name, model, mode
     #self.func = ThermoStat(None, 1, HMV3_ID, 'test', 'test controller', 'prt_hw_model', PROG_MODE_DAY)
     self.settings = {
         'address': 1,
         'protocol': HMV3_ID,
         'long_name': 'test controller',
         'expected_model': 'prt_hw_model',
         'expected_prog_mode': PROG_MODE_DAY
     }
     dev1 = ThermoStatHotWaterDay(self.adaptor, self.settings)
     self.settings2 = {
         'address': 2,
         'protocol': HMV3_ID,
         'long_name': 'test controller',
         'expected_model': 'prt_hw_model',
         'expected_prog_mode': PROG_MODE_DAY
     }
     dev2 = ThermoStatHotWaterDay(self.adaptor, self.settings)
     self.func = HeatmiserBroadcastDevice(self.adaptor, 'Broadcaster',
                                          [dev1, dev2])
예제 #9
0
 def test_read_fields(self):
     setup = SetupTestClass()
     adaptor = MockHeatmiserAdaptor(setup)
     self.func = ThermoStatDay(adaptor, self.settings2)
     responses = [[0, 170]]
     adaptor.setresponse(responses)
     self.assertEqual([17], self.func.read_fields(['airtemp'], 1))
     responses = [[0, 0, 0, 0, 0, 0, 0, 170]]
     adaptor.setresponse(responses)
     self.assertEqual([0, 17],
                      self.func.read_fields(['tempholdmins', 'airtemp'], 0))
     responses = [[3], [0, 100]]
     adaptor.setresponse(responses)
     self.assertEqual([3, 10], self.func.read_fields(['model', 'airtemp'],
                                                     0))
     responses = [[3], [0, 100, 0, 1]]
     adaptor.setresponse(responses)
     print self.func.read_fields(['model', 'airtemp', 'heatingdemand'], 0)
     responses = [[3], [0, 100, 0, 1]]
     adaptor.setresponse(responses)
     print self.func.read_fields(['model', 'airtemp', 'hotwaterdemand'], 0)
     responses = [[
         3, 0, 1, 0, 0, 0, 0, 4, 0, 0, 0, 0, 1, 7, 5, 20, 0, 0, 0
     ], [0, 100, 0, 1]]
     adaptor.setresponse(responses)
     print self.func.read_fields(
         ['model', 'airtemp', 'hotwaterdemand', 'keylock'], 0)
     responses = [[
         0, 3, 0, 1, 0, 0, 0, 0, 4, 0, 0, 0, 0, 1, 7, 5, 20, 0, 0, 0, 0, 0,
         0, 0
     ]]
     adaptor.setresponse(responses)
     print self.func.read_fields(['holidayhours', 'version'], 0)
     responses = [[0, 3, 0, 1, 0, 0, 0, 0, 4, 0, 0, 0],
                  [0, 3, 0, 1, 0, 0, 0, 0, 4, 0, 0, 0]]
     adaptor.setresponse(responses)
     print self.func.read_fields(['mon_heat', 'sun_heat'], 0)