Example #1
0
    def __login_btn_clicked(self, user_name, password):
        """ Slot for the login button

         Tries to create model with the provided user_name and password

        :param str user_name: flow user name
        :param str password: flow user password
        """
        # clear any old status
        self.__display_app.login_view_show_error(None)

        LOGGER.debug("Trying to login with username = {}".format(user_name))

        try:
            # try to initialize model
            self.__model = ClimateControlModel()
            self.__model.connection_status.connect(
                self.__connection_status_result)
            try:
                self.__model.initialize(user_name, password)
            except LoginFailed:
                self.__display_app.login_view_show_error(
                    UIStrings.LOGIN_FAILED)
            except ControllerNotFound:
                self.__display_app.login_view_show_error(
                    UIStrings.CONTROLLER_DEVICE_NOT_FOUND)
            else:
                # Save username if no exception comes
                UserList().add_name(user_name)
                self.__model.setting_received.connect(
                    self.__get_setting_response)
                # define slot for receiving events from Controller
                self.__model.measurement_changed.connect(
                    self.__measurement_changed)
                self.__model.device_status_changed.connect(
                    self.__device_status_changed)
                self.__model.relay_status_changed.connect(
                    self.__relay_status_changed)
                self.__model.controller_status.connect(
                    self.__controller_status)
                self.__model.latency_changed.connect(self.__latency_changed)
                self.__model.get_settings()
        except FlowLibraryError:
            self.__display_app.login_view_show_error(
                UIStrings.FLOW_LIBRARY_ERROR)
    def __login_btn_clicked(self, user_name, password):
        """ Slot for the login button

         Tries to create model with the provided user_name and password
        :param str user_name: flow user name
        :param str password: flow user password
        """
        # clear any old status
        self.__admin_app.login_view_show_error(None)
        LOGGER.debug("Trying to login with username = {}".format(user_name))

        try:
            # try to initialize model
            self.__model = ClimateControlModel()
            self.__model.connection_status.connect(
                self.__connection_status_result)
            self.__model.initialize(user_name, password)
            self.__model.save_setting_result.connect(
                self.__save_setting_result)
            self.__model.command_sending_result.connect(
                self.__command_sending_result)
            self.__model.command_response_received.connect(
                self.__command_response_received)
            self.__model.relay_status_changed.connect(
                self.__relay_status_changed)

            # Save username if no exception comes
            UserList().add_name(user_name)
            # login pass, try to get settings
            self.__model.setting_received.connect(self.__get_setting_response)
            self.__model.get_settings()

        except LoginFailed:
            self.__admin_app.login_view_show_error(Strings.LOGIN_FAILED)
            LOGGER.exception("Login failed")
        except ControllerNotFound:
            self.__admin_app.login_view_show_error(
                Strings.CONTROLLER_DEVICE_NOT_FOUND)
            LOGGER.exception("Controller device not found")
        except FlowLibraryError as error:
            self.__admin_app.login_view_show_error(Strings.FLOW_LIBRARY_ERROR)
            LOGGER.exception(error.message)