def test_blnet_web_log_out(self): """ Test setting digital values """ blnet = BLNETWeb(self.url, password=PASSWORD, timeout=10) self.assertFalse(blnet.logged_in()) with blnet as blnet: self.assertTrue(blnet.logged_in()) self.assertFalse(blnet.logged_in())
def test_blnet_login(self): """ Test logging in """ self.assertTrue( BLNETWeb(self.url, password=PASSWORD, timeout=10).log_in()) # test without http self.assertTrue( BLNETWeb("{}:{}".format(ADDRESS, self.port), password=PASSWORD, timeout=10).log_in())
def test_blnet_web_log_in(self): """ Test logging in via different urls and that log out after a with clause happens correctly """ with BLNETWeb(self.url, password=PASSWORD, timeout=10) as blnet: self.assertTrue(blnet.logged_in()) # test without http blnet = BLNETWeb("{}:{}".format(ADDRESS, self.port), password=PASSWORD, timeout=10) with blnet as blnet: self.assertTrue(blnet.logged_in())
def test_blnet_web_set_digital(self): """ Test setting digital values """ with BLNETWeb(self.url, password=PASSWORD, timeout=10) as blnet: blnet.set_digital_value(10, '2') self.assertEqual(self.server.get_node('A'), '2') blnet.set_digital_value(9, 'EIN') self.assertEqual(self.server.get_node('9'), '2') blnet.set_digital_value(8, 'auto') self.assertEqual(self.server.get_node('8'), '3') blnet.set_digital_value(1, 'on') self.assertEqual(self.server.get_node('1'), '2') blnet.set_digital_value(1, 'AUS') self.assertEqual(self.server.get_node('1'), '1') blnet.set_digital_value(5, 3) self.assertEqual(self.server.get_node('5'), '3') blnet.set_digital_value(4, True) self.assertEqual(self.server.get_node('4'), '2') blnet.set_digital_value(6, False) self.assertEqual(self.server.get_node('6'), '1') try: blnet.set_digital_value(0, 'EIN') self.fail("Didn't catch wrong id 0") except ValueError: pass try: blnet.set_digital_value(16, 'EIN') self.fail("Didn't catch wrong id 16") except ValueError: pass
def test_blnet_web(self): try: blnet = BLNETWeb(self.url) self.fail("Didn't throw an exception for offline blnetweb") except ValueError: pass
def test_blnet_web_digital(self): """ Test reading digital values""" self.assertEqual( BLNETWeb(self.url, password=PASSWORD, timeout=10).read_digital_values(), STATE_DIGITAL)
def test_blnet_web_analog(self): """ Test reading analog values """ self.assertEqual( BLNETWeb(self.url, password=PASSWORD, timeout=10).read_analog_values(), STATE_ANALOG)
""" from pyblnet import BLNETWeb, test_blnet, BLNETDirect, BLNET if __name__ == '__main__': ip = '192.168.178.10' # Check if there is a blnet at given address print(test_blnet(ip)) # Easy to use high level interface blnet = BLNET(ip, timeout=5) print(blnet.turn_on(10)) print(blnet.fetch()) # Fetch the latest data via web interface blnet = BLNETWeb(ip, timeout=5) print(blnet.read_analog_values()) print(blnet.read_digital_values()) # For publishing values #print(blnet.set_digital_value("10", 'AUS')) #print(blnet.read_digital_values()) blnet = BLNETDirect(ip) # Fetching the latest data from the backend print(blnet.get_latest()) # Still inofficial because unexplicably failing often print(blnet._get_data(1))