def test_setfield_3(self): """Check hotwaterdemand mapping""" settings2 = { 'address': 1, 'protocol': HMV3_ID, 'long_name': 'test controller', 'expected_model': 'prt_hw_model', 'expected_prog_mode': PROG_MODE_DAY } #self.func._update_settings(settings2, None) self.func = ThermoStatHotWaterDay(self.tester, settings2) #make sure read time is set and check value self.func.set_field('hotwaterdemand', self.func.hotwaterdemand.writevalues['OVER_OFF']) self.assertNotEqual( getattr(self.func, 'hotwaterdemand').lastreadtime, None) self.assertEqual(self.func.hotwaterdemand.get_value(), self.func.hotwaterdemand.readvalues['OFF']) self.func._adaptor.reset() #check releasing works self.func.set_field('hotwaterdemand', self.func.hotwaterdemand.writevalues['PROG']) self.assertEqual( self.tester.arguments, [(1, 3, 42, 1, [self.func.hotwaterdemand.writevalues['PROG']])]) self.assertEqual(self.func.hotwaterdemand.value, None) self.assertEqual(self.func.hotwaterdemand.lastreadtime, None)
def setUp(self): logging.basicConfig(level=logging.ERROR) self.settings = { 'address': 1, 'protocol': HMV3_ID, 'long_name': 'test controller', 'expected_model': 'prt_e_model', 'expected_prog_mode': PROG_MODE_DAY } self.func = ThermoStatHotWaterDay(None, self.settings)
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)
class TestHWfloorlimit(unittest.TestCase): """Unittests for other functions""" def setUp(self): logging.basicConfig(level=logging.ERROR) self.settings = { 'address': 1, 'protocol': HMV3_ID, 'long_name': 'test controller', 'expected_model': 'prt_e_model', 'expected_prog_mode': PROG_MODE_DAY } self.func = ThermoStatHotWaterDay(None, self.settings) def test_getfieldblocks(self): self.assertEqual(None, self.func.floorlimiting.get_value()) self.func._procfield([2], self.func.version) self.assertEqual(2, self.func.version.get_value()) self.assertEqual(0, self.func.floorlimiting.get_value()) self.func._procfield([129], self.func.version) self.assertEqual(1, self.func.version.get_value()) self.assertEqual(1, self.func.floorlimiting.get_value())
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)
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)
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_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)
def setUp(self): logging.basicConfig(level=logging.DEBUG) #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, 'autocorrectime': False } self.settings2 = { 'address': 1, 'protocol': HMV3_ID, 'long_name': 'test controller', 'expected_model': 'prt_e_model', 'expected_prog_mode': PROG_MODE_DAY } self.func = ThermoStatHotWaterDay(None, self.settings)
class TestSettingData(unittest.TestCase): """Unittests for setting data functions""" 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) def test_setfield_1(self): #checks the arguments sent to write_to_device #fieldname, payload self.func.set_field('frosttemp', 7) self.assertEqual(self.tester.arguments, [(5, 3, 17, 1, [7])]) self.assertEqual(self.func.frosttemp.value, 7) def test_setfield_2(self): self.func.autocorrectime = False #self.func.lastreadtime = 7 * 86400 + 7 *3600 + 7 * 60 - 3600 self.func.lastreadtime = time.time() loctime = self.func.currenttime.localtimearray(self.func.lastreadtime) self.func.set_field('currenttime', loctime) self.assertEqual(self.tester.arguments, [(5, 3, 43, 4, loctime)]) def test_setfield_notvalid(self): with self.assertRaises(KeyError): self.func.set_field('hotwaterdemand', 0) def test_setfield_3(self): """Check hotwaterdemand mapping""" settings2 = { 'address': 1, 'protocol': HMV3_ID, 'long_name': 'test controller', 'expected_model': 'prt_hw_model', 'expected_prog_mode': PROG_MODE_DAY } #self.func._update_settings(settings2, None) self.func = ThermoStatHotWaterDay(self.tester, settings2) #make sure read time is set and check value self.func.set_field('hotwaterdemand', self.func.hotwaterdemand.writevalues['OVER_OFF']) self.assertNotEqual( getattr(self.func, 'hotwaterdemand').lastreadtime, None) self.assertEqual(self.func.hotwaterdemand.get_value(), self.func.hotwaterdemand.readvalues['OFF']) self.func._adaptor.reset() #check releasing works self.func.set_field('hotwaterdemand', self.func.hotwaterdemand.writevalues['PROG']) self.assertEqual( self.tester.arguments, [(1, 3, 42, 1, [self.func.hotwaterdemand.writevalues['PROG']])]) self.assertEqual(self.func.hotwaterdemand.value, None) self.assertEqual(self.func.hotwaterdemand.lastreadtime, None) def test_setfield_errors(self): with self.assertRaises(ValueError): self.func.set_field('frosttemp', 3) with self.assertRaises(TypeError): self.func.set_field('frosttemp', [3, 3]) with self.assertRaises(ValueError): self.func.set_field('currenttime', [8, 7, 7, 7]) with self.assertRaises(TypeError): self.func.set_field('currenttime', 7) def test_setfields_1(self): self.func.set_fields(['frosttemp'], [7]) self.assertEqual(self.tester.arguments, [(5, 3, 17, 1, [7])]) self.assertEqual(self.func.frosttemp.value, 7) def test_setfields_2(self): setarray = [1, 0, 17, 9, 0, 20, 13, 0, 17, 20, 0, 20] self.func.set_fields(['mon_heat'], [setarray]) self.assertEqual(self.tester.arguments, [(5, 3, 103, 12, setarray)]) self.assertEqual(self.func.mon_heat.value, setarray) def test_setfields_3(self): setarray = [[1, 0, 17, 9, 0, 20, 13, 0, 17, 20, 0, 20], [1, 0, 17, 9, 0, 20, 13, 0, 17, 20, 0, 20]] self.func.set_fields(['mon_heat', 'wed_heat'], setarray) self.assertEqual(self.tester.arguments, [(5, 3, 103, 12, setarray[0]), (5, 3, 127, 12, setarray[0])]) self.assertEqual(self.func.mon_heat.value, setarray[0]) self.assertEqual(self.func.wed_heat.value, setarray[1]) def test_setfields_4(self): indata = [[1, 0, 17, 9, 0, 20, 13, 0, 17, 20, 0, 20], [1, 0, 18, 9, 0, 21, 13, 0, 18, 20, 0, 21]] flat_list = [item for sublist in indata for item in sublist] self.func.set_fields(['mon_heat', 'tues_heat'], indata) self.assertEqual(self.tester.arguments, [(5, 3, 103, 24, flat_list)]) self.assertEqual(self.func.mon_heat.value, indata[0]) self.assertEqual(self.func.tues_heat.value, indata[1]) def test_seton(self): #self.func.set_on() self.func.set_field('onoff', 'ON') self.assertEqual(self.tester.arguments, [(5, 3, 21, 1, [1])]) self.assertEqual(self.func.onoff.value, 1) def test_setoff(self): self.func.set_field('onoff', 'OFF') self.assertEqual(self.tester.arguments, [(5, 3, 21, 1, [0])]) self.assertEqual(self.func.onoff.value, 0)