def open(self, network): " Request default page" self.tx_put('GET','') if self.remote: """ Fill in the parameters for login web form and send http POST """ params = {} params['login'] = self.remote_username params['pwd'] = self.remote_password """ to handle fibaro bug in login form """ if 'dom' in self.remote_server: params['loguj'] = 'Loguj' elif 'home' in self.remote_server: params['loguj_ra'] = 'Loguj' self.tx_put('POST','/cmh/index.php?page=login', params) #self.tx_put('/cmh/index.php') self.tx_put('GET','/cmh/index.php?page=choose_ui&hc={0}'.format(network)) self.tx_put('GET','/fibaro/index.php') #self.tx_put('/api/interface/data') #self.tx_put('/fibaro/pl/home/index.php') self.tx_put('GET','/api/loginStatus') #self.tx_put('/api/globalVariables') #self.tx_put('/api/globalVariables') self.start() res = Wait.single(self.connected_event, 10) if res == -1: """ Timeout """ return False else: self.tx_put('GET','/api/settings/info') return True
def run(self): logger.info("HC2Driver.run") attempt = 0 while True: self.wait_objects[0] = None self.wait_objects[1] = None self.wait_objects[2] = None self.wait_objects[3] = None self.all_nodes_queried = False if self.init(attempt): self.running = 1 self.attempt = 0 self.wait_objects[0] = self.exit_event self.wait_objects[1] = self.notifications_event self.wait_objects[2] = self.controller self.wait_objects[3] = self.queue_event[0] self.wait_objects[4] = self.queue_event[1] #objects_number = 5 logger.info("HC2Driver.run: Running") while self.running: logger.debug("HC2Driver.run: Waiting for event") res = Wait.multiple( self.wait_objects ) logger.debug("HC2Driver.run: Event: {0}".format( res ) ) if res == 0: logger.debug("HC2Driver.run: Exit Event") #self.Stop() return elif res == 1: logger.debug("HC2Driver.run: Notification Event") self.notify_watchers() elif res == 2: logger.debug("HC2Driver.run: Data Received") self.read_msg() elif res == -1: logger.debug("HC2Driver.run: res = -1") assert res != -1, "Wait.Multiple returned res = -1" else: logger.debug("HC2Driver.run: Message Queue Event: {0}".format(res -3)) self.write_next_msg(res - 3) else: attempt += 1 logger.debug("HC2Driver.run: Max attempts: {0}".format( max_attempts ) ) if max_attempts > 0 and ( attempt >= max_attempts): self.manager.set_driver_ready(self, False) self.notify_watchers() logger.error("HC2Driver.run: Max attempts exceeded") break if attempt < 10: logger.debug( "HC2Driver.run: Connection timeout. Waiting 5 second" ) else: logger.debug( "HC2Driver.run: Connection timeout. Waiting 30 second" ) res = Wait.single( self.exit_event, 30) if res == 0: logger.error("HC2Driver.run: Exit signaled") return